From c5e09ceaaa4f814cad454cec56963e8b0f764654 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 20 May 2019 19:46:20 +1000 Subject: [PATCH] SPIGOT-4961: Cannot open various inventories --- nms-patches/TileEntityLectern.patch | 21 +++++++++++-------- .../craftbukkit/entity/CraftHumanEntity.java | 13 +++++++++--- .../craftbukkit/inventory/CraftInventory.java | 3 ++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/nms-patches/TileEntityLectern.patch b/nms-patches/TileEntityLectern.patch index 5f5c5e0aa5..f101cf4848 100644 --- a/nms-patches/TileEntityLectern.patch +++ b/nms-patches/TileEntityLectern.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/TileEntityLectern.java +++ b/net/minecraft/server/TileEntityLectern.java -@@ -1,10 +1,61 @@ +@@ -1,10 +1,63 @@ package net.minecraft.server; import javax.annotation.Nullable; @@ -18,9 +18,11 @@ -public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory { +public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory, ICommandListener { // CraftBukkit - ICommandListener - - public final IInventory inventory = new IInventory() { -+ // CraftBukkit start - add fields and methods ++ ++ // CraftBukkit start - add fields and methods ++ public final IInventory inventory = new LecternInventory(); ++ public class LecternInventory implements IInventory { ++ + public List transaction = new ArrayList<>(); + private int maxStack = 1; + @@ -59,11 +61,12 @@ + return (Lectern) CraftBlock.at(world, position).getState(); + } + // CraftBukkit end -+ + +- public final IInventory inventory = new IInventory() { @Override public int getSize() { return 1; -@@ -49,11 +100,18 @@ +@@ -49,11 +102,18 @@ } @Override @@ -84,7 +87,7 @@ } @Override -@@ -158,6 +216,32 @@ +@@ -158,6 +218,32 @@ return itemstack; } @@ -117,7 +120,7 @@ private CommandListenerWrapper a(@Nullable EntityHuman entityhuman) { String s; Object object; -@@ -172,7 +256,8 @@ +@@ -172,7 +258,8 @@ Vec3D vec3d = new Vec3D((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D); @@ -127,7 +130,7 @@ } @Override -@@ -206,7 +291,7 @@ +@@ -206,7 +293,7 @@ @Override public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index d6d04995ab..772f919b6c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -468,12 +468,19 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { case STONECUTTER: openCustomInventory(inventory, player, Containers.STONECUTTER); break; + case LOOM: + openCustomInventory(inventory, player, Containers.LOOM); + break; + case CARTOGRAPHY: + openCustomInventory(inventory, player, Containers.CARTOGRAPHY); + break; + case GRINDSTONE: + openCustomInventory(inventory, player, Containers.GRINDSTONE); + break; case CREATIVE: case CRAFTING: case MERCHANT: - case LOOM: - case CARTOGRAPHY: - case GRINDSTONE: + default: throw new IllegalArgumentException("Can't open a " + type + " inventory!"); } if (getHandle().activeContainer == formerContainer) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 4e80c07a12..deb9de366a 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -16,6 +16,7 @@ import net.minecraft.server.TileEntityBrewingStand; import net.minecraft.server.TileEntityDispenser; import net.minecraft.server.TileEntityDropper; import net.minecraft.server.TileEntityFurnace; +import net.minecraft.server.TileEntityLectern; import net.minecraft.server.TileEntityShulkerBox; import net.minecraft.server.TileEntitySmoker; import org.apache.commons.lang.Validate; @@ -479,7 +480,7 @@ public class CraftInventory implements Inventory { return InventoryType.SHULKER_BOX; } else if (inventory instanceof TileEntityBarrel) { return InventoryType.BARREL; - } else if (this instanceof CraftInventoryLectern) { + } else if (inventory instanceof TileEntityLectern.LecternInventory) { return InventoryType.LECTERN; } else if (this instanceof CraftInventoryLoom) { return InventoryType.LOOM;