diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java b/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java index 300f6d075a..191de73a92 100644 --- a/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java +++ b/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java @@ -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() { diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java b/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java index daf85bcc63..9fff6acf70 100644 --- a/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java +++ b/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java @@ -18,6 +18,8 @@ public class ContainerEnchantTableSubcontainer implements IInventory { // CraftBukkit start public List transaction = new ArrayList(); + 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() { diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java index 1e2c9eae84..7dfc587026 100644 --- a/src/main/java/net/minecraft/server/EntityMinecart.java +++ b/src/main/java/net/minecraft/server/EntityMinecart.java @@ -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 transaction = new ArrayList(); // CraftBukkit + public List transaction = new ArrayList(); + 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) { @@ -177,7 +182,7 @@ public class EntityMinecart extends Entity implements IInventory { itemstack.count -= k; // 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; entityitem.motX = (double) ((float) this.random.nextGaussian() * f3); @@ -874,7 +879,7 @@ public class EntityMinecart extends Entity implements IInventory { } public int getMaxStackSize() { - return 64; + return maxStack; // CraftBukkit } public void update() {} diff --git a/src/main/java/net/minecraft/server/IInventory.java b/src/main/java/net/minecraft/server/IInventory.java index 97a8b88de5..a8b87d8c64 100644 --- a/src/main/java/net/minecraft/server/IInventory.java +++ b/src/main/java/net/minecraft/server/IInventory.java @@ -34,13 +34,17 @@ public interface IInventory { // CraftBukkit start ItemStack[] getContents(); - + void onOpen(CraftHumanEntity who); - + void onClose(CraftHumanEntity who); - + List getViewers(); - + InventoryHolder getOwner(); + + void setMaxStackSize(int size); + + int MAX_STACK = 64; //CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/InventoryCraftResult.java b/src/main/java/net/minecraft/server/InventoryCraftResult.java index 98858d5fae..18b6791e05 100644 --- a/src/main/java/net/minecraft/server/InventoryCraftResult.java +++ b/src/main/java/net/minecraft/server/InventoryCraftResult.java @@ -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 getViewers() { return new ArrayList(); } + + 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() {} diff --git a/src/main/java/net/minecraft/server/InventoryCrafting.java b/src/main/java/net/minecraft/server/InventoryCrafting.java index ade98090f0..857ad0e79d 100644 --- a/src/main/java/net/minecraft/server/InventoryCrafting.java +++ b/src/main/java/net/minecraft/server/InventoryCrafting.java @@ -20,7 +20,9 @@ public class InventoryCrafting implements IInventory { public List transaction = new ArrayList(); public CraftingRecipe currentRecipe; public IInventory resultInventory; - + private EntityHuman owner; + private int maxStack = MAX_STACK; + public ItemStack[] getContents() { return this.items; } @@ -28,7 +30,7 @@ public class InventoryCrafting implements IInventory { public void onOpen(CraftHumanEntity who) { transaction.add(who); } - + public InventoryType getInvType() { return items.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH; } @@ -36,13 +38,23 @@ public class InventoryCrafting implements IInventory { public void onClose(CraftHumanEntity who) { transaction.remove(who); } - + public List getViewers() { return transaction; } - + 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() {} diff --git a/src/main/java/net/minecraft/server/InventoryLargeChest.java b/src/main/java/net/minecraft/server/InventoryLargeChest.java index 159740c661..0f23a2f8c6 100644 --- a/src/main/java/net/minecraft/server/InventoryLargeChest.java +++ b/src/main/java/net/minecraft/server/InventoryLargeChest.java @@ -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() { diff --git a/src/main/java/net/minecraft/server/PlayerInventory.java b/src/main/java/net/minecraft/server/PlayerInventory.java index 1881d7327e..d01be1e191 100644 --- a/src/main/java/net/minecraft/server/PlayerInventory.java +++ b/src/main/java/net/minecraft/server/PlayerInventory.java @@ -20,6 +20,7 @@ public class PlayerInventory implements IInventory { // CraftBukkit start public List transaction = new ArrayList(); + 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) { diff --git a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java index 0c50bb6ba8..abfa178bbe 100644 --- a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java +++ b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java @@ -23,6 +23,7 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory { // CraftBukkit start public List transaction = new ArrayList(); + 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) { diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java index ce2ad48989..b3a837518f 100644 --- a/src/main/java/net/minecraft/server/TileEntityChest.java +++ b/src/main/java/net/minecraft/server/TileEntityChest.java @@ -23,6 +23,7 @@ public class TileEntityChest extends TileEntity implements IInventory { // CraftBukkit start public List transaction = new ArrayList(); + private int maxStack = MAX_STACK; public ItemStack[] getContents() { return this.items; @@ -39,6 +40,10 @@ public class TileEntityChest extends TileEntity implements IInventory { public List 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) { diff --git a/src/main/java/net/minecraft/server/TileEntityDispenser.java b/src/main/java/net/minecraft/server/TileEntityDispenser.java index 553a3b2e31..c811610d2d 100644 --- a/src/main/java/net/minecraft/server/TileEntityDispenser.java +++ b/src/main/java/net/minecraft/server/TileEntityDispenser.java @@ -17,6 +17,7 @@ public class TileEntityDispenser extends TileEntity implements IInventory { // CraftBukkit start public List transaction = new ArrayList(); + private int maxStack = MAX_STACK; public ItemStack[] getContents() { return this.items; @@ -33,6 +34,10 @@ public class TileEntityDispenser extends TileEntity implements IInventory { public List 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) { diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java index 9790ea5084..48635c8202 100644 --- a/src/main/java/net/minecraft/server/TileEntityFurnace.java +++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java @@ -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 transaction = new ArrayList(); public ItemStack[] getContents() { @@ -39,6 +40,10 @@ public class TileEntityFurnace extends TileEntity implements IInventory { public List 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() { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index d64df14338..a5ea612df3 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -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); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java index eb2546e6c9..a53a5c2ddf 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java @@ -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 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()); @@ -41,7 +41,7 @@ public class CraftInventoryCustom extends CraftInventory { public MinecraftInventory(InventoryHolder owner, int size) { this(owner, size, "Chest"); } - + public MinecraftInventory(InventoryHolder owner, int size, String title) { this.items = new ItemStack[size]; this.title = title; @@ -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) { @@ -120,7 +127,7 @@ public class CraftInventoryCustom extends CraftInventory { public List getViewers() { return viewers; } - + public InventoryType getType() { return type; }