From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: JRoy Date: Wed, 26 Aug 2020 02:12:31 -0400 Subject: [PATCH] Add additional open container api to HumanEntity diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 90971adbe5bb15f42c1d59eb069fec40866f30b0..96016906ec745c5f806161edcfe3caad53fc8381 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -463,6 +463,70 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { return this.getHandle().containerMenu.getBukkitView(); } + // Paper start - Add additional containers + @Override + public InventoryView openAnvil(Location location, boolean force) { + return this.openInventory(location, force, BlockType.ANVIL); + } + + @Override + public InventoryView openCartographyTable(Location location, boolean force) { + return this.openInventory(location, force, BlockType.CARTOGRAPHY_TABLE); + } + + @Override + public InventoryView openGrindstone(Location location, boolean force) { + return this.openInventory(location, force, BlockType.GRINDSTONE); + } + + @Override + public InventoryView openLoom(Location location, boolean force) { + return this.openInventory(location, force, BlockType.LOOM); + } + + @Override + public InventoryView openSmithingTable(Location location, boolean force) { + return this.openInventory(location, force, BlockType.SMITHING_TABLE); + } + + @Override + public InventoryView openStonecutter(Location location, boolean force) { + return this.openInventory(location, force, BlockType.STONECUTTER); + } + + private InventoryView openInventory(Location location, boolean force, BlockType blockType) { + org.spigotmc.AsyncCatcher.catchOp("open" + blockType); + if (location == null) { + location = this.getLocation(); + } + if (!force) { + Block block = location.getBlock(); + if (block.getType() != blockType) { + return null; + } + } + net.minecraft.world.level.block.Block block; + if (blockType == BlockType.ANVIL) { + block = Blocks.ANVIL; + } else if (blockType == BlockType.CARTOGRAPHY_TABLE) { + block = Blocks.CARTOGRAPHY_TABLE; + } else if (blockType == BlockType.GRINDSTONE) { + block = Blocks.GRINDSTONE; + } else if (blockType == BlockType.LOOM) { + block = Blocks.LOOM; + } else if (blockType == BlockType.SMITHING_TABLE) { + block = Blocks.SMITHING_TABLE; + } else if (blockType == BlockType.STONECUTTER) { + block = Blocks.STONECUTTER; + } else { + throw new IllegalArgumentException("Unsupported inventory type: " + blockType); + } + this.getHandle().openMenu(block.getMenuProvider(null, this.getHandle().level(), new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()))); + this.getHandle().containerMenu.checkReachable = !force; + return this.getHandle().containerMenu.getBukkitView(); + } + // Paper end + @Override public void closeInventory() { // Paper start