PaperMC/paper-server/nms-patches/net/minecraft/world/inventory/ContainerDispenser.patch

63 lines
2 KiB
Diff
Raw Normal View History

2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/inventory/ContainerDispenser.java
+++ b/net/minecraft/world/inventory/ContainerDispenser.java
@@ -6,6 +6,11 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerDispenser extends Container {
private static final int SLOT_COUNT = 9;
@@ -14,6 +19,10 @@
private static final int USE_ROW_SLOT_START = 36;
private static final int USE_ROW_SLOT_END = 45;
public final IInventory dispenser;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerDispenser(int i, PlayerInventory playerinventory) {
this(i, playerinventory, new InventorySubcontainer(9));
@@ -21,6 +30,10 @@
public ContainerDispenser(int i, PlayerInventory playerinventory, IInventory iinventory) {
super(Containers.GENERIC_3x3, i);
+ // CraftBukkit start - Save player
+ this.player = playerinventory;
+ // CraftBukkit end
+
a(iinventory, 9);
this.dispenser = iinventory;
iinventory.startOpen(playerinventory.player);
@@ -48,6 +61,7 @@
@Override
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.dispenser.a(entityhuman);
}
@@ -89,4 +103,17 @@
super.b(entityhuman);
this.dispenser.closeContainer(entityhuman);
}
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory = new CraftInventory(this.dispenser);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}