[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) { 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() {

View file

@ -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() {

View file

@ -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) {
@ -177,7 +182,7 @@ public class EntityMinecart extends Entity implements IInventory {
itemstack.count -= k; itemstack.count -= k;
// CraftBukkit - include enchantments in the new itemstack // CraftBukkit - include enchantments in the new itemstack
EntityItem entityitem = new EntityItem(this.world, this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, new ItemStack(itemstack.id, k, itemstack.getData(), itemstack.getEnchantments())); EntityItem entityitem = new EntityItem(this.world, this.locX + (double) f, this.locY + (double) f1, this.locZ + (double) f2, new ItemStack(itemstack.id, k, itemstack.getData(), itemstack.getEnchantments()));
float f3 = 0.05F; float f3 = 0.05F;
entityitem.motX = (double) ((float) this.random.nextGaussian() * f3); entityitem.motX = (double) ((float) this.random.nextGaussian() * f3);
@ -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() {}

View file

@ -34,13 +34,17 @@ public interface IInventory {
// CraftBukkit start // CraftBukkit start
ItemStack[] getContents(); ItemStack[] getContents();
void onOpen(CraftHumanEntity who); void onOpen(CraftHumanEntity who);
void onClose(CraftHumanEntity who); void onClose(CraftHumanEntity who);
List<HumanEntity> getViewers(); List<HumanEntity> getViewers();
InventoryHolder getOwner(); InventoryHolder getOwner();
void setMaxStackSize(int size);
int MAX_STACK = 64;
//CraftBukkit end //CraftBukkit end
} }

View file

@ -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() {}

View file

@ -20,7 +20,9 @@ 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;
} }
@ -28,7 +30,7 @@ public class InventoryCrafting implements IInventory {
public void onOpen(CraftHumanEntity who) { public void onOpen(CraftHumanEntity who) {
transaction.add(who); transaction.add(who);
} }
public InventoryType getInvType() { public InventoryType getInvType() {
return items.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH; return items.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
} }
@ -36,13 +38,23 @@ public class InventoryCrafting implements IInventory {
public void onClose(CraftHumanEntity who) { public void onClose(CraftHumanEntity who) {
transaction.remove(who); transaction.remove(who);
} }
public List<HumanEntity> getViewers() { public List<HumanEntity> getViewers() {
return transaction; return transaction;
} }
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() {}

View file

@ -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() {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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() {

View file

@ -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);
}
} }

View file

@ -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());
@ -41,7 +41,7 @@ public class CraftInventoryCustom extends CraftInventory {
public MinecraftInventory(InventoryHolder owner, int size) { public MinecraftInventory(InventoryHolder owner, int size) {
this(owner, size, "Chest"); this(owner, size, "Chest");
} }
public MinecraftInventory(InventoryHolder owner, int size, String title) { public MinecraftInventory(InventoryHolder owner, int size, String title) {
this.items = new ItemStack[size]; this.items = new ItemStack[size];
this.title = title; this.title = title;
@ -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) {
@ -120,7 +127,7 @@ public class CraftInventoryCustom extends CraftInventory {
public List<HumanEntity> getViewers() { public List<HumanEntity> getViewers() {
return viewers; return viewers;
} }
public InventoryType getType() { public InventoryType getType() {
return type; return type;
} }