summaryrefslogtreecommitdiffhomepage
path: root/patches/server/0408-Add-additional-open-container-api-to-HumanEntity.patch
blob: 15f9a92e44355e24e629bc40f747808a4e9e22c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: JRoy <joshroy126@gmail.com>
Date: Wed, 26 Aug 2020 02:12:31 -0400
Subject: [PATCH] Add additional open container api to HumanEntity

== AT ==
public net/minecraft/world/level/block/state/BlockBehaviour getMenuProvider(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/MenuProvider;

diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index c17dd4205983855615289cf0a5619056d237f325..6cda13df52ee4d56dd1d3c213307bfd38175584c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -471,6 +471,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, Material.ANVIL);
+    }
+
+    @Override
+    public InventoryView openCartographyTable(Location location, boolean force) {
+        return this.openInventory(location, force, Material.CARTOGRAPHY_TABLE);
+    }
+
+    @Override
+    public InventoryView openGrindstone(Location location, boolean force) {
+        return this.openInventory(location, force, Material.GRINDSTONE);
+    }
+
+    @Override
+    public InventoryView openLoom(Location location, boolean force) {
+        return this.openInventory(location, force, Material.LOOM);
+    }
+
+    @Override
+    public InventoryView openSmithingTable(Location location, boolean force) {
+        return this.openInventory(location, force, Material.SMITHING_TABLE);
+    }
+
+    @Override
+    public InventoryView openStonecutter(Location location, boolean force) {
+        return this.openInventory(location, force, Material.STONECUTTER);
+    }
+
+    private InventoryView openInventory(Location location, boolean force, Material material) {
+        org.spigotmc.AsyncCatcher.catchOp("open" + material);
+        if (location == null) {
+            location = this.getLocation();
+        }
+        if (!force) {
+            Block block = location.getBlock();
+            if (block.getType() != material) {
+                return null;
+            }
+        }
+        net.minecraft.world.level.block.Block block;
+        if (material == Material.ANVIL) {
+            block = Blocks.ANVIL;
+        } else if (material == Material.CARTOGRAPHY_TABLE) {
+            block = Blocks.CARTOGRAPHY_TABLE;
+        } else if (material == Material.GRINDSTONE) {
+            block = Blocks.GRINDSTONE;
+        } else if (material == Material.LOOM) {
+            block = Blocks.LOOM;
+        } else if (material == Material.SMITHING_TABLE) {
+            block = Blocks.SMITHING_TABLE;
+        } else if (material == Material.STONECUTTER) {
+            block = Blocks.STONECUTTER;
+        } else {
+            throw new IllegalArgumentException("Unsupported inventory type: " + material);
+        }
+        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 - Inventory close reason