0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2025-02-16 15:45:59 +00:00
2025-02-05 22:54:42 +11:00

69 lines
2.5 KiB
Diff

--- a/net/minecraft/world/inventory/ContainerChest.java
+++ b/net/minecraft/world/inventory/ContainerChest.java
@@ -6,10 +6,45 @@
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import net.minecraft.world.InventoryLargeChest;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerChest extends Container {
private final IInventory container;
private final int containerRows;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory;
+ if (this.container instanceof PlayerInventory) {
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryPlayer((PlayerInventory) this.container);
+ } else if (this.container instanceof InventoryLargeChest) {
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) this.container);
+ } else {
+ inventory = new CraftInventory(this.container);
+ }
+
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+
+ @Override
+ public void startOpen() {
+ super.startOpen();
+ this.container.startOpen(this.player.player);
+ }
+ // CraftBukkit end
private ContainerChest(Containers<?> containers, int i, PlayerInventory playerinventory, int j) {
this(containers, i, playerinventory, new InventorySubcontainer(9 * j), j);
@@ -52,7 +87,10 @@
checkContainerSize(iinventory, j * 9);
this.container = iinventory;
this.containerRows = j;
- iinventory.startOpen(playerinventory.player);
+ // iinventory.startOpen(playerinventory.player); // CraftBukkit - don't startOpen until menu actually opens
+ // CraftBukkit start - Save player
+ this.player = playerinventory;
+ // CraftBukkit end
boolean flag = true;
this.addChestGrid(iinventory, 8, 18);
@@ -72,6 +110,7 @@
@Override
public boolean stillValid(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.container.stillValid(entityhuman);
}