Skip to content

Commit

Permalink
Fix horse inventories indices (#11139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulu13022002 authored Jul 22, 2024
1 parent aa36ae6 commit 73a863b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions patches/server/1031-fix-horse-inventories.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ index 9bcc0931510607b8fbd01233e2b3c346369b214d..467693a60786688b753cebac3b0a8889

// Paper start - Horse API
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAbstractHorse.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAbstractHorse.java
index 4946da593713f4d11d88ac1bb68a089f2f6d5ae0..bae0db99a8159bdea71182485b22cce9fc61e00a 100644
index 4946da593713f4d11d88ac1bb68a089f2f6d5ae0..abef7f23361e6c5d18243dd18439ffd13ac787ae 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAbstractHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAbstractHorse.java
@@ -6,17 +6,64 @@ import org.bukkit.inventory.ItemStack;
@@ -6,17 +6,73 @@ import org.bukkit.inventory.ItemStack;

public class CraftInventoryAbstractHorse extends CraftInventory implements AbstractHorseInventory {

Expand Down Expand Up @@ -76,20 +76,29 @@ index 4946da593713f4d11d88ac1bb68a089f2f6d5ae0..bae0db99a8159bdea71182485b22cce9
+ @Override
+ public ItemStack getItem(final int index) {
+ if (index == net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR) {
+ final net.minecraft.world.item.ItemStack item = this.getArmorInventory().getItem(index);
+ final net.minecraft.world.item.ItemStack item = this.getArmorInventory().getItem(0);
+ return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
+ } else {
+ final net.minecraft.world.item.ItemStack item = this.getMainInventory().getItem(index);
+ int shiftedIndex = index;
+ if (index > net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR) {
+ shiftedIndex--;
+ }
+
+ final net.minecraft.world.item.ItemStack item = this.getMainInventory().getItem(shiftedIndex);
+ return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item);
+ }
+ }
+
+ @Override
+ public void setItem(final int index, final ItemStack item) {
+ if (index == net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR) {
+ this.getArmorInventory().setItem(index, CraftItemStack.asNMSCopy(item));
+ this.getArmorInventory().setItem(0, CraftItemStack.asNMSCopy(item));
+ } else {
+ this.getMainInventory().setItem(index, CraftItemStack.asNMSCopy(item));
+ int shiftedIndex = index;
+ if (index > net.minecraft.world.inventory.HorseInventoryMenu.SLOT_BODY_ARMOR) {
+ shiftedIndex--;
+ }
+ this.getMainInventory().setItem(shiftedIndex, CraftItemStack.asNMSCopy(item));
+ }
+ }
+ // Paper end - combine both horse inventories
Expand Down

0 comments on commit 73a863b

Please sign in to comment.