Fix AbstractHorse get/setSaddle

Fixes #12412
This commit is contained in:
Nassim Jahnke
2025-04-12 18:59:52 +02:00
parent f00727c57e
commit 8eede4bb8a
7 changed files with 45 additions and 30 deletions

View File

@@ -115,7 +115,11 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac
@Override
public AbstractHorseInventory getInventory() {
return new CraftSaddledInventory(getHandle().inventory, this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY));
return new CraftSaddledInventory(
this.getHandle().inventory,
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY),
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.SADDLE)
);
}
@Override

View File

@@ -58,7 +58,10 @@ public class CraftHorse extends CraftAbstractHorse implements Horse {
@Override
public HorseInventory getInventory() {
return new CraftInventoryHorse(this.getHandle().inventory, this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY));
return new CraftInventoryHorse(this.getHandle().inventory,
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY),
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.SADDLE)
);
}
@Override

View File

@@ -34,7 +34,10 @@ public class CraftLlama extends CraftChestedHorse implements Llama, com.destroys
@Override
public LlamaInventory getInventory() {
return new CraftInventoryLlama(this.getHandle().inventory, this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY));
return new CraftInventoryLlama(this.getHandle().inventory,
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.BODY),
this.getHandle().createEquipmentSlotContainer(EquipmentSlot.SADDLE)
);
}
@Override

View File

@@ -1,18 +1,21 @@
package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.HorseInventoryMenu;
import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.inventory.AbstractHorseInventory;
import org.bukkit.inventory.ItemStack;
public class CraftInventoryAbstractHorse extends CraftInventory implements AbstractHorseInventory {
// Paper start - combine both horse inventories
private final Container bodyArmor;
public CraftInventoryAbstractHorse(Container inventory, final Container bodyArmor) {
private final Container bodyArmorInventory;
private final Container saddleInventory;
public CraftInventoryAbstractHorse(Container inventory, final Container bodyArmorInventory, final Container saddleInventory) {
super(inventory);
this.bodyArmor = bodyArmor;
// Paper end - combine both horse inventories
this.bodyArmorInventory = bodyArmorInventory;
this.saddleInventory = saddleInventory;
}
@Override
@@ -25,21 +28,24 @@ public class CraftInventoryAbstractHorse extends CraftInventory implements Abstr
this.setItem(HorseInventoryMenu.SLOT_SADDLE, stack); // Paper
}
// Paper start - combine both horse inventories
public Container getMainInventory() {
return this.inventory;
}
public Container getArmorInventory() {
return this.bodyArmor;
return this.bodyArmorInventory;
}
public Container getSaddleInventory() {
return this.saddleInventory;
}
public ItemStack getArmor() {
return this.getItem(net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR);
return this.getItem(HorseInventoryMenu.SLOT_BODY_ARMOR);
}
public void setArmor(ItemStack armor) {
this.setItem(net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR, armor);
this.setItem(HorseInventoryMenu.SLOT_BODY_ARMOR, armor);
}
@Override
@@ -60,7 +66,7 @@ public class CraftInventoryAbstractHorse extends CraftInventory implements Abstr
items[HorseInventoryMenu.SLOT_BODY_ARMOR] = this.getArmor();
for (int i = HorseInventoryMenu.SLOT_HORSE_INVENTORY_START; i < items.length; i++) {
net.minecraft.world.item.ItemStack item = this.getMainInventory().getItem(i - 1);
net.minecraft.world.item.ItemStack item = this.getMainInventory().getItem(i - HorseInventoryMenu.SLOT_HORSE_INVENTORY_START);
items[i] = item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
}
@@ -69,14 +75,14 @@ public class CraftInventoryAbstractHorse extends CraftInventory implements Abstr
@Override
public void setContents(ItemStack[] items) {
com.google.common.base.Preconditions.checkArgument(items.length <= this.getSize(), "Invalid inventory size (%s); expected %s or less", items.length, this.getSize());
Preconditions.checkArgument(items.length <= this.getSize(), "Invalid inventory size (%s); expected %s or less", items.length, this.getSize());
this.setSaddle(org.apache.commons.lang3.ArrayUtils.get(items, HorseInventoryMenu.SLOT_SADDLE));
this.setArmor(org.apache.commons.lang3.ArrayUtils.get(items, HorseInventoryMenu.SLOT_BODY_ARMOR));
this.setSaddle(ArrayUtils.get(items, HorseInventoryMenu.SLOT_SADDLE));
this.setArmor(ArrayUtils.get(items, HorseInventoryMenu.SLOT_BODY_ARMOR));
for (int i = HorseInventoryMenu.SLOT_BODY_ARMOR + 1; i < this.getSize(); i++) {
for (int i = HorseInventoryMenu.SLOT_HORSE_INVENTORY_START; i < this.getSize(); i++) {
net.minecraft.world.item.ItemStack item = i >= items.length ? net.minecraft.world.item.ItemStack.EMPTY : CraftItemStack.asNMSCopy(items[i]);
this.getMainInventory().setItem(i - 1, item);
this.getMainInventory().setItem(i - HorseInventoryMenu.SLOT_HORSE_INVENTORY_START, item);
}
}
@@ -85,6 +91,9 @@ public class CraftInventoryAbstractHorse extends CraftInventory implements Abstr
if (index == HorseInventoryMenu.SLOT_BODY_ARMOR) {
final net.minecraft.world.item.ItemStack item = this.getArmorInventory().getItem(0);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
} else if (index == HorseInventoryMenu.SLOT_SADDLE) {
final net.minecraft.world.item.ItemStack item = this.getSaddleInventory().getItem(0);
return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
} else {
int shiftedIndex = index;
if (index > HorseInventoryMenu.SLOT_BODY_ARMOR) {
@@ -100,6 +109,8 @@ public class CraftInventoryAbstractHorse extends CraftInventory implements Abstr
public void setItem(final int index, final ItemStack item) {
if (index == HorseInventoryMenu.SLOT_BODY_ARMOR) {
this.getArmorInventory().setItem(0, CraftItemStack.asNMSCopy(item));
} else if (index == HorseInventoryMenu.SLOT_SADDLE) {
this.getSaddleInventory().setItem(0, CraftItemStack.asNMSCopy(item));
} else {
int shiftedIndex = index;
if (index > HorseInventoryMenu.SLOT_BODY_ARMOR) {

View File

@@ -6,9 +6,7 @@ import org.bukkit.inventory.ItemStack;
public class CraftInventoryHorse extends CraftSaddledInventory implements HorseInventory {
// Paper start - properly combine both inventories
public CraftInventoryHorse(Container inventory, Container bodyArmorInventory) {
super(inventory, bodyArmorInventory);
public CraftInventoryHorse(Container inventory, Container bodyArmorInventory, Container saddleInventory) {
super(inventory, bodyArmorInventory, saddleInventory);
}
// Paper end - properly combine both inventories
}

View File

@@ -6,10 +6,8 @@ import org.bukkit.inventory.LlamaInventory;
public class CraftInventoryLlama extends CraftInventoryAbstractHorse implements LlamaInventory {
// Paper start - properly combine both inventories
public CraftInventoryLlama(Container inventory, Container bodyArmorInventory) {
super(inventory, bodyArmorInventory);
// Paper end - properly combine both inventories
public CraftInventoryLlama(Container inventory, Container bodyArmorInventory, Container saddleInventory) {
super(inventory, bodyArmorInventory, saddleInventory);
}
@Override

View File

@@ -5,10 +5,8 @@ import org.bukkit.inventory.SaddledHorseInventory;
public class CraftSaddledInventory extends CraftInventoryAbstractHorse implements SaddledHorseInventory {
// Paper start - combine both inventories
public CraftSaddledInventory(Container inventory, final Container bodyArmor) {
super(inventory, bodyArmor);
// Paper end - combine both inventories
public CraftSaddledInventory(Container inventory, final Container bodyArmorInventory, final Container saddleInventory) {
super(inventory, bodyArmorInventory, saddleInventory);
}
}