From 4090d01f6ddccafb2e609420139bbd53f1f48c60 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 13 Jun 2019 21:26:04 +1000 Subject: [PATCH] SPIGOT-5047: Correct slot types for 1.14 inventories --- nms-patches/ContainerStonecutter.patch | 2 +- .../craftbukkit/inventory/CraftInventory.java | 1 - .../inventory/CraftInventoryAnvil.java | 40 +--------------- .../inventory/CraftInventoryCartography.java | 12 +---- .../inventory/CraftInventoryGrindstone.java | 7 +-- .../inventory/CraftInventoryLoom.java | 7 +-- .../inventory/CraftInventoryStonecutter.java | 6 +-- .../inventory/CraftResultInventory.java | 47 +++++++++++++++++++ 8 files changed, 59 insertions(+), 63 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/inventory/CraftResultInventory.java diff --git a/nms-patches/ContainerStonecutter.patch b/nms-patches/ContainerStonecutter.patch index e44f48fb83..87f6d69924 100644 --- a/nms-patches/ContainerStonecutter.patch +++ b/nms-patches/ContainerStonecutter.patch @@ -26,7 +26,7 @@ + return bukkitEntity; + } + -+ CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.inventory); ++ CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.inventory, this.n); + bukkitEntity = new CraftInventoryView(this.player, inventory, this); + return bukkitEntity; + } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index deb9de366a..0d637e207e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -10,7 +10,6 @@ import net.minecraft.server.InventoryEnderChest; import net.minecraft.server.InventoryMerchant; import net.minecraft.server.PlayerInventory; import net.minecraft.server.TileEntityBarrel; -import net.minecraft.server.TileEntityBeacon; import net.minecraft.server.TileEntityBlastFurnace; import net.minecraft.server.TileEntityBrewingStand; import net.minecraft.server.TileEntityDispenser; diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java index 70c9605c3b..6222e8ba38 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java @@ -5,54 +5,18 @@ import net.minecraft.server.ContainerAnvil; import net.minecraft.server.IInventory; import org.bukkit.Location; import org.bukkit.inventory.AnvilInventory; -import org.bukkit.inventory.ItemStack; -public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory { +public class CraftInventoryAnvil extends CraftResultInventory implements AnvilInventory { private final Location location; - private final IInventory resultInventory; private final ContainerAnvil container; public CraftInventoryAnvil(Location location, IInventory inventory, IInventory resultInventory, ContainerAnvil container) { - super(inventory); + super(inventory, resultInventory); this.location = location; - this.resultInventory = resultInventory; this.container = container; } - public IInventory getResultInventory() { - return resultInventory; - } - - public IInventory getIngredientsInventory() { - return inventory; - } - - @Override - public ItemStack getItem(int slot) { - if (slot < getIngredientsInventory().getSize()) { - net.minecraft.server.ItemStack item = getIngredientsInventory().getItem(slot); - return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); - } else { - net.minecraft.server.ItemStack item = getResultInventory().getItem(slot - getIngredientsInventory().getSize()); - return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); - } - } - - @Override - public void setItem(int index, ItemStack item) { - if (index < getIngredientsInventory().getSize()) { - getIngredientsInventory().setItem(index, CraftItemStack.asNMSCopy(item)); - } else { - getResultInventory().setItem((index - getIngredientsInventory().getSize()), CraftItemStack.asNMSCopy(item)); - } - } - - @Override - public int getSize() { - return getResultInventory().getSize() + getIngredientsInventory().getSize(); - } - @Override public Location getLocation() { return location; diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCartography.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCartography.java index 892fc902bc..9458de90e3 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCartography.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCartography.java @@ -3,17 +3,9 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.IInventory; import org.bukkit.inventory.CartographyInventory; -public class CraftInventoryCartography extends CraftInventory implements CartographyInventory { - - private final IInventory resultInventory; +public class CraftInventoryCartography extends CraftResultInventory implements CartographyInventory { public CraftInventoryCartography(IInventory inventory, IInventory resultInventory) { - super(inventory); - this.resultInventory = resultInventory; - } - - @Override - public int getSize() { - return super.getSize() + resultInventory.getSize(); + super(inventory, resultInventory); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryGrindstone.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryGrindstone.java index 704d65041e..ce89ce764e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryGrindstone.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryGrindstone.java @@ -3,12 +3,9 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.IInventory; import org.bukkit.inventory.GrindstoneInventory; -public class CraftInventoryGrindstone extends CraftInventory implements GrindstoneInventory { - - private final IInventory resultInventory; +public class CraftInventoryGrindstone extends CraftResultInventory implements GrindstoneInventory { public CraftInventoryGrindstone(IInventory inventory, IInventory resultInventory) { - super(inventory); - this.resultInventory = resultInventory; + super(inventory, resultInventory); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryLoom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryLoom.java index 341d831a47..d3c5417996 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryLoom.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryLoom.java @@ -3,12 +3,9 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.IInventory; import org.bukkit.inventory.LoomInventory; -public class CraftInventoryLoom extends CraftInventory implements LoomInventory { - - private final IInventory resultInventory; +public class CraftInventoryLoom extends CraftResultInventory implements LoomInventory { public CraftInventoryLoom(IInventory inventory, IInventory resultInventory) { - super(inventory); - this.resultInventory = resultInventory; + super(inventory, resultInventory); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryStonecutter.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryStonecutter.java index 880df2a19f..e4135b679d 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryStonecutter.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryStonecutter.java @@ -3,9 +3,9 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.IInventory; import org.bukkit.inventory.StonecutterInventory; -public class CraftInventoryStonecutter extends CraftInventory implements StonecutterInventory { +public class CraftInventoryStonecutter extends CraftResultInventory implements StonecutterInventory { - public CraftInventoryStonecutter(IInventory inventory) { - super(inventory); + public CraftInventoryStonecutter(IInventory inventory, IInventory resultInventory) { + super(inventory, resultInventory); } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftResultInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftResultInventory.java new file mode 100644 index 0000000000..ff7f589a2a --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftResultInventory.java @@ -0,0 +1,47 @@ +package org.bukkit.craftbukkit.inventory; + +import net.minecraft.server.IInventory; +import org.bukkit.inventory.ItemStack; + +public class CraftResultInventory extends CraftInventory { + + private final IInventory resultInventory; + + public CraftResultInventory(IInventory inventory, IInventory resultInventory) { + super(inventory); + this.resultInventory = resultInventory; + } + + public IInventory getResultInventory() { + return resultInventory; + } + + public IInventory getIngredientsInventory() { + return inventory; + } + + @Override + public ItemStack getItem(int slot) { + if (slot < getIngredientsInventory().getSize()) { + net.minecraft.server.ItemStack item = getIngredientsInventory().getItem(slot); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); + } else { + net.minecraft.server.ItemStack item = getResultInventory().getItem(slot - getIngredientsInventory().getSize()); + return item.isEmpty() ? null : CraftItemStack.asCraftMirror(item); + } + } + + @Override + public void setItem(int index, ItemStack item) { + if (index < getIngredientsInventory().getSize()) { + getIngredientsInventory().setItem(index, CraftItemStack.asNMSCopy(item)); + } else { + getResultInventory().setItem((index - getIngredientsInventory().getSize()), CraftItemStack.asNMSCopy(item)); + } + } + + @Override + public int getSize() { + return getResultInventory().getSize() + getIngredientsInventory().getSize(); + } +}