3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/patches/server/0458-Add-additional-open-container-api-to-HumanEntity.patch

82 Zeilen
3.4 KiB
Diff

2021-06-11 14:02:28 +02:00
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
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2023-12-06 04:00:14 +01:00
index 9541ebf81c3c2c282c6d04f5e51b309e69d0802e..2609da834c014e82d0038de580d50163dd0c5687 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2023-12-06 04:00:14 +01:00
@@ -462,6 +462,70 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2021-06-11 14:02:28 +02:00
return this.getHandle().containerMenu.getBukkitView();
}
+ // Paper start - Add additional containers
+ @Override
+ public InventoryView openAnvil(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.ANVIL);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public InventoryView openCartographyTable(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.CARTOGRAPHY_TABLE);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public InventoryView openGrindstone(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.GRINDSTONE);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public InventoryView openLoom(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.LOOM);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public InventoryView openSmithingTable(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.SMITHING_TABLE);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public InventoryView openStonecutter(Location location, boolean force) {
2023-06-08 02:30:05 +02:00
+ return this.openInventory(location, force, Material.STONECUTTER);
2021-06-11 14:02:28 +02:00
+ }
+
+ private InventoryView openInventory(Location location, boolean force, Material material) {
+ org.spigotmc.AsyncCatcher.catchOp("open" + material);
+ if (location == null) {
2023-06-08 02:30:05 +02:00
+ location = this.getLocation();
2021-06-11 14:02:28 +02:00
+ }
+ 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);
+ }
2023-06-08 02:30:05 +02:00
+ 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();
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
@Override
public void closeInventory() {
2021-07-30 11:37:11 +02:00
// Paper start