[Bleeding] Implemented Inventory.{get,set}MaxStackSize(). Addresses BUKKIT-1076

- Custom inventories also respect this setting now.
This commit is contained in:
Celtic Minstrel 2012-03-14 10:00:54 -04:00 committed by EvilSeph
parent 66e067f373
commit 5c8fd4995f
14 changed files with 105 additions and 26 deletions

View file

@ -7,10 +7,11 @@ public class ContainerEnchantTableInventory extends ContainerEnchantTableSubcont
ContainerEnchantTableInventory(ContainerEnchantTable containerenchanttable, String s, int i) {
super(s, i);
this.enchantTable = containerenchanttable;
super.setMaxStackSize(1); // CraftBukkit
}
public int getMaxStackSize() {
return 1;
return super.getMaxStackSize(); // CraftBukkit
}
public void update() {

View file

@ -18,6 +18,8 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
// CraftBukkit start
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public org.bukkit.entity.Player player;
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
@ -38,6 +40,10 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
public InventoryHolder getOwner() {
return null; // TODO: Enchanting tables don't really have an owner? Maybe they should?
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public ContainerEnchantTableSubcontainer(String s, int i) {
@ -102,7 +108,7 @@ public class ContainerEnchantTableSubcontainer implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public void update() {

View file

@ -44,7 +44,8 @@ public class EntityMinecart extends Entity implements IInventory {
private double flyingY = 0.95;
private double flyingZ = 0.95;
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() {
return this.items;
@ -67,6 +68,10 @@ public class EntityMinecart extends Entity implements IInventory {
if(cart instanceof InventoryHolder) return (InventoryHolder) cart;
return null;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public EntityMinecart(World world) {
@ -874,7 +879,7 @@ public class EntityMinecart extends Entity implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public void update() {}

View file

@ -42,5 +42,9 @@ public interface IInventory {
List<HumanEntity> getViewers();
InventoryHolder getOwner();
void setMaxStackSize(int size);
int MAX_STACK = 64;
//CraftBukkit end
}

View file

@ -14,6 +14,8 @@ public class InventoryCraftResult implements IInventory {
private ItemStack[] items = new ItemStack[1];
// CraftBukkit start
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
}
@ -27,6 +29,10 @@ public class InventoryCraftResult implements IInventory {
public List<HumanEntity> getViewers() {
return new ArrayList<HumanEntity>();
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public InventoryCraftResult() {}
@ -70,7 +76,7 @@ public class InventoryCraftResult implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public void update() {}

View file

@ -20,6 +20,8 @@ public class InventoryCrafting implements IInventory {
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public CraftingRecipe currentRecipe;
public IInventory resultInventory;
private EntityHuman owner;
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
@ -42,7 +44,17 @@ public class InventoryCrafting implements IInventory {
}
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
@ -116,7 +128,7 @@ public class InventoryCrafting implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public void update() {}

View file

@ -45,6 +45,11 @@ public class InventoryLargeChest implements IInventory {
public InventoryHolder getOwner() {
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
public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) {
@ -90,7 +95,7 @@ public class InventoryLargeChest implements IInventory {
}
public int getMaxStackSize() {
return this.left.getMaxStackSize();
return Math.min(this.left.getMaxStackSize(), this.right.getMaxStackSize()); // CraftBukkit - check both sides
}
public void update() {

View file

@ -20,6 +20,7 @@ public class PlayerInventory implements IInventory {
// CraftBukkit start
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
@ -44,6 +45,10 @@ public class PlayerInventory implements IInventory {
public InventoryHolder getOwner() {
return this.player.getBukkitEntity();
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public PlayerInventory(EntityHuman entityhuman) {
@ -350,7 +355,7 @@ public class PlayerInventory implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public int a(Entity entity) {

View file

@ -23,6 +23,7 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
// CraftBukkit start
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private int maxStack = 1;
public void onOpen(CraftHumanEntity who) {
transaction.add(who);
@ -39,6 +40,10 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
public ItemStack[] getContents() {
return this.items;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public String getName() {
@ -228,7 +233,7 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
}
public int getMaxStackSize() {
return 1;
return maxStack; // CraftBukkit
}
public boolean a(EntityHuman entityhuman) {

View file

@ -23,6 +23,7 @@ public class TileEntityChest extends TileEntity implements IInventory {
// CraftBukkit start
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
@ -39,6 +40,10 @@ public class TileEntityChest extends TileEntity implements IInventory {
public List<HumanEntity> getViewers() {
return transaction;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public TileEntityChest() {}
@ -132,7 +137,7 @@ public class TileEntityChest extends TileEntity implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public boolean a(EntityHuman entityhuman) {

View file

@ -17,6 +17,7 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
// CraftBukkit start
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private int maxStack = MAX_STACK;
public ItemStack[] getContents() {
return this.items;
@ -33,6 +34,10 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
public List<HumanEntity> getViewers() {
return transaction;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public TileEntityDispenser() {}
@ -151,7 +156,7 @@ public class TileEntityDispenser extends TileEntity implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public boolean a(EntityHuman entityhuman) {

View file

@ -22,6 +22,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
// CraftBukkit start
private int lastTick = (int) (System.currentTimeMillis() / 50);
private int maxStack = MAX_STACK;
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public ItemStack[] getContents() {
@ -39,6 +40,10 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
public List<HumanEntity> getViewers() {
return transaction;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
// CraftBukkit end
public TileEntityFurnace() {}
@ -134,7 +139,7 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
}
public int getMaxStackSize() {
return 64;
return maxStack; // CraftBukkit
}
public boolean isBurning() {

View file

@ -412,4 +412,12 @@ public class CraftInventory implements Inventory {
public InventoryHolder getHolder() {
return inventory.getOwner();
}
public int getMaxStackSize() {
return inventory.getMaxStackSize();
}
public void setMaxStackSize(int size) {
inventory.setMaxStackSize(size);
}
}

View file

@ -27,11 +27,11 @@ public class CraftInventoryCustom extends CraftInventory {
static class MinecraftInventory implements IInventory {
private ItemStack[] items;
private int maxStack = 64;
private int maxStack = MAX_STACK;
private List<HumanEntity> viewers;
private String title;
private InventoryType type;
private InventoryHolder owner; // TODO: Constructors to set this
private InventoryHolder owner;
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
this(owner, type.getDefaultSize(), type.getDefaultTitle());
@ -89,6 +89,9 @@ public class CraftInventoryCustom extends CraftInventory {
public void setItem(int i, ItemStack itemstack) {
items[i] = itemstack;
if (itemstack != null && this.getMaxStackSize() > 0 && itemstack.count > this.getMaxStackSize()) {
itemstack.count = this.getMaxStackSize();
}
}
public String getName() {
@ -99,6 +102,10 @@ public class CraftInventoryCustom extends CraftInventory {
return maxStack;
}
public void setMaxStackSize(int size) {
maxStack = size;
}
public void update() {}
public boolean a(EntityHuman entityhuman) {