--- a/net/minecraft/world/SimpleContainer.java +++ b/net/minecraft/world/SimpleContainer.java @@ -19,7 +_,84 @@ @Nullable private List listeners; + // Paper start - add fields and methods + public List transaction = new java.util.ArrayList<>(); + private int maxStack = MAX_STACK; + protected @Nullable org.bukkit.inventory.InventoryHolder bukkitOwner; // Paper - annotation + + public List getContents() { + return this.items; + } + + public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who) { + this.transaction.add(who); + } + + public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) { + this.transaction.remove(who); + } + + public List getViewers() { + return this.transaction; + } + + @Override + public int getMaxStackSize() { + return this.maxStack; + } + + public void setMaxStackSize(int i) { + this.maxStack = i; + } + + public org.bukkit.inventory.InventoryHolder getOwner() { + // Paper start - Add missing InventoryHolders + if (this.bukkitOwner == null && this.bukkitOwnerCreator != null) { + this.bukkitOwner = this.bukkitOwnerCreator.get(); + } + // Paper end - Add missing InventoryHolders + return this.bukkitOwner; + } + + @Override + public org.bukkit.Location getLocation() { + // Paper start - Fix inventories returning null Locations + // When the block inventory does not have a tile state that implements getLocation, e. g. composters + if (this.bukkitOwner instanceof org.bukkit.inventory.BlockInventoryHolder blockInventoryHolder) { + return blockInventoryHolder.getBlock().getLocation(); + } + // When the bukkit owner is a bukkit entity, but does not implement Container itself, e. g. horses + if (this.bukkitOwner instanceof org.bukkit.entity.Entity entity) { + return entity.getLocation(); + } + // Paper end - Fix inventories returning null Locations + return null; + } + + public SimpleContainer(SimpleContainer original) { + this(original.size); + for (int slot = 0; slot < original.size; slot++) { + this.items.set(slot, original.items.get(slot).copy()); + } + } + // Paper end + public SimpleContainer(int size) { + this(size, null); + } + + // Paper start - Add missing InventoryHolders + private @Nullable java.util.function.Supplier bukkitOwnerCreator; + + public SimpleContainer(java.util.function.Supplier bukkitOwnerCreator, int size) { + this(size); + this.bukkitOwnerCreator = bukkitOwnerCreator; + } + // Paper end - Add missing InventoryHolders + + public SimpleContainer(int size, org.bukkit.inventory.InventoryHolder owner) { + this.bukkitOwner = owner; + // Paper end this.size = size; this.items = NonNullList.withSize(size, ItemStack.EMPTY); }