mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-28 09:17:21 +01:00
[Bleeding] Implemented Inventory.{get,set}MaxStackSize(). Addresses BUKKIT-1076
- Custom inventories also respect this setting now.
This commit is contained in:
parent
66e067f373
commit
5c8fd4995f
14 changed files with 105 additions and 26 deletions
|
@ -7,10 +7,11 @@ public class ContainerEnchantTableInventory extends ContainerEnchantTableSubcont
|
||||||
ContainerEnchantTableInventory(ContainerEnchantTable containerenchanttable, String s, int i) {
|
ContainerEnchantTableInventory(ContainerEnchantTable containerenchanttable, String s, int i) {
|
||||||
super(s, i);
|
super(s, i);
|
||||||
this.enchantTable = containerenchanttable;
|
this.enchantTable = containerenchanttable;
|
||||||
|
super.setMaxStackSize(1); // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 1;
|
return super.getMaxStackSize(); // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
|
@ -18,6 +18,8 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
public org.bukkit.entity.Player player;
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -38,6 +40,10 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
|
||||||
public InventoryHolder getOwner() {
|
public InventoryHolder getOwner() {
|
||||||
return null; // TODO: Enchanting tables don't really have an owner? Maybe they should?
|
return null; // TODO: Enchanting tables don't really have an owner? Maybe they should?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public ContainerEnchantTableSubcontainer(String s, int i) {
|
public ContainerEnchantTableSubcontainer(String s, int i) {
|
||||||
|
@ -102,7 +108,7 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
|
@ -44,7 +44,8 @@ public class EntityMinecart extends Entity implements IInventory {
|
||||||
private double flyingY = 0.95;
|
private double flyingY = 0.95;
|
||||||
private double flyingZ = 0.95;
|
private double flyingZ = 0.95;
|
||||||
public double maxSpeed = 0.4D;
|
public double maxSpeed = 0.4D;
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>(); // CraftBukkit
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -67,6 +68,10 @@ public class EntityMinecart extends Entity implements IInventory {
|
||||||
if(cart instanceof InventoryHolder) return (InventoryHolder) cart;
|
if(cart instanceof InventoryHolder) return (InventoryHolder) cart;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public EntityMinecart(World world) {
|
public EntityMinecart(World world) {
|
||||||
|
@ -874,7 +879,7 @@ public class EntityMinecart extends Entity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {}
|
public void update() {}
|
||||||
|
|
|
@ -42,5 +42,9 @@ public interface IInventory {
|
||||||
List<HumanEntity> getViewers();
|
List<HumanEntity> getViewers();
|
||||||
|
|
||||||
InventoryHolder getOwner();
|
InventoryHolder getOwner();
|
||||||
|
|
||||||
|
void setMaxStackSize(int size);
|
||||||
|
|
||||||
|
int MAX_STACK = 64;
|
||||||
//CraftBukkit end
|
//CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class InventoryCraftResult implements IInventory {
|
||||||
private ItemStack[] items = new ItemStack[1];
|
private ItemStack[] items = new ItemStack[1];
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +29,10 @@ public class InventoryCraftResult implements IInventory {
|
||||||
public List<HumanEntity> getViewers() {
|
public List<HumanEntity> getViewers() {
|
||||||
return new ArrayList<HumanEntity>();
|
return new ArrayList<HumanEntity>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public InventoryCraftResult() {}
|
public InventoryCraftResult() {}
|
||||||
|
@ -70,7 +76,7 @@ public class InventoryCraftResult implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {}
|
public void update() {}
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class InventoryCrafting implements IInventory {
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
public CraftingRecipe currentRecipe;
|
public CraftingRecipe currentRecipe;
|
||||||
public IInventory resultInventory;
|
public IInventory resultInventory;
|
||||||
|
private EntityHuman owner;
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -42,7 +44,17 @@ public class InventoryCrafting implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryHolder getOwner() {
|
public InventoryHolder getOwner() {
|
||||||
return null; // TODO: Crafting grids don't really have an owner? Maybe they should?
|
return owner.getBukkitEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
resultInventory.setMaxStackSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryCrafting(Container container, int i, int j, EntityHuman player) {
|
||||||
|
this(container, i, j);
|
||||||
|
this.owner = player;
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
|
@ -116,7 +128,7 @@ public class InventoryCrafting implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {}
|
public void update() {}
|
||||||
|
|
|
@ -45,6 +45,11 @@ public class InventoryLargeChest implements IInventory {
|
||||||
public InventoryHolder getOwner() {
|
public InventoryHolder getOwner() {
|
||||||
return null; // This method won't be called since CraftInventoryDoubleChest doesn't defer to here
|
return null; // This method won't be called since CraftInventoryDoubleChest doesn't defer to here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
this.left.setMaxStackSize(size);
|
||||||
|
this.right.setMaxStackSize(size);
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) {
|
public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) {
|
||||||
|
@ -90,7 +95,7 @@ public class InventoryLargeChest implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return this.left.getMaxStackSize();
|
return Math.min(this.left.getMaxStackSize(), this.right.getMaxStackSize()); // CraftBukkit - check both sides
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
|
@ -20,6 +20,7 @@ public class PlayerInventory implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -44,6 +45,10 @@ public class PlayerInventory implements IInventory {
|
||||||
public InventoryHolder getOwner() {
|
public InventoryHolder getOwner() {
|
||||||
return this.player.getBukkitEntity();
|
return this.player.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public PlayerInventory(EntityHuman entityhuman) {
|
public PlayerInventory(EntityHuman entityhuman) {
|
||||||
|
@ -350,7 +355,7 @@ public class PlayerInventory implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public int a(Entity entity) {
|
public int a(Entity entity) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
private int maxStack = 1;
|
||||||
|
|
||||||
public void onOpen(CraftHumanEntity who) {
|
public void onOpen(CraftHumanEntity who) {
|
||||||
transaction.add(who);
|
transaction.add(who);
|
||||||
|
@ -39,6 +40,10 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -228,7 +233,7 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 1;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class TileEntityChest extends TileEntity implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -39,6 +40,10 @@ public class TileEntityChest extends TileEntity implements IInventory {
|
||||||
public List<HumanEntity> getViewers() {
|
public List<HumanEntity> getViewers() {
|
||||||
return transaction;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public TileEntityChest() {}
|
public TileEntityChest() {}
|
||||||
|
@ -132,7 +137,7 @@ public class TileEntityChest extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
return this.items;
|
return this.items;
|
||||||
|
@ -33,6 +34,10 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
|
||||||
public List<HumanEntity> getViewers() {
|
public List<HumanEntity> getViewers() {
|
||||||
return transaction;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public TileEntityDispenser() {}
|
public TileEntityDispenser() {}
|
||||||
|
@ -151,7 +156,7 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
private int lastTick = (int) (System.currentTimeMillis() / 50);
|
private int lastTick = (int) (System.currentTimeMillis() / 50);
|
||||||
|
private int maxStack = MAX_STACK;
|
||||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||||
|
|
||||||
public ItemStack[] getContents() {
|
public ItemStack[] getContents() {
|
||||||
|
@ -39,6 +40,10 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
|
||||||
public List<HumanEntity> getViewers() {
|
public List<HumanEntity> getViewers() {
|
||||||
return transaction;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public TileEntityFurnace() {}
|
public TileEntityFurnace() {}
|
||||||
|
@ -134,7 +139,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return 64;
|
return maxStack; // CraftBukkit
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBurning() {
|
public boolean isBurning() {
|
||||||
|
|
|
@ -412,4 +412,12 @@ public class CraftInventory implements Inventory {
|
||||||
public InventoryHolder getHolder() {
|
public InventoryHolder getHolder() {
|
||||||
return inventory.getOwner();
|
return inventory.getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return inventory.getMaxStackSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
inventory.setMaxStackSize(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,11 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||||
|
|
||||||
static class MinecraftInventory implements IInventory {
|
static class MinecraftInventory implements IInventory {
|
||||||
private ItemStack[] items;
|
private ItemStack[] items;
|
||||||
private int maxStack = 64;
|
private int maxStack = MAX_STACK;
|
||||||
private List<HumanEntity> viewers;
|
private List<HumanEntity> viewers;
|
||||||
private String title;
|
private String title;
|
||||||
private InventoryType type;
|
private InventoryType type;
|
||||||
private InventoryHolder owner; // TODO: Constructors to set this
|
private InventoryHolder owner;
|
||||||
|
|
||||||
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
|
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
|
||||||
this(owner, type.getDefaultSize(), type.getDefaultTitle());
|
this(owner, type.getDefaultSize(), type.getDefaultTitle());
|
||||||
|
@ -89,6 +89,9 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||||
|
|
||||||
public void setItem(int i, ItemStack itemstack) {
|
public void setItem(int i, ItemStack itemstack) {
|
||||||
items[i] = itemstack;
|
items[i] = itemstack;
|
||||||
|
if (itemstack != null && this.getMaxStackSize() > 0 && itemstack.count > this.getMaxStackSize()) {
|
||||||
|
itemstack.count = this.getMaxStackSize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -99,6 +102,10 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||||
return maxStack;
|
return maxStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMaxStackSize(int size) {
|
||||||
|
maxStack = size;
|
||||||
|
}
|
||||||
|
|
||||||
public void update() {}
|
public void update() {}
|
||||||
|
|
||||||
public boolean a(EntityHuman entityhuman) {
|
public boolean a(EntityHuman entityhuman) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue