From 554d6c70052bec6b7ca05cbd8c67dc7542b78779 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Sun, 15 Apr 2012 18:30:49 -0400 Subject: [PATCH] Add in code to support the bukkit fun --- .../ironchest/ContainerIronChestBase.java | 139 ++++++++++-------- .../mods/ironchest/TileEntityIronChest.java | 3 + 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java index 1a03421..db88931 100644 --- a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java +++ b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java @@ -3,84 +3,93 @@ package cpw.mods.ironchest; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; +import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; public class ContainerIronChestBase extends Container { - private IronChestType type; - public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - chest = chestInventory; - this.type=type; - chestInventory.openChest(); - layoutContainer(playerInventory, chestInventory, type, xSize, ySize); - } + private IronChestType type; + private EntityPlayer player; + private IInventory chest; - public boolean canInteractWith(EntityPlayer player) - { - return chest.isUseableByPlayer(player); - } + public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { + chest = chestInventory; + player = ((InventoryPlayer) playerInventory).player; + this.type = type; + chestInventory.openChest(); + layoutContainer(playerInventory, chestInventory, type, xSize, ySize); + } - public ItemStack transferStackInSlot(int i) + public boolean canInteractWith(EntityPlayer player) + { + return chest.isUseableByPlayer(player); + } + + public ItemStack transferStackInSlot(int i) + { + ItemStack itemstack = null; + Slot slot = (Slot) inventorySlots.get(i); + if (slot != null && slot.getHasStack()) { - ItemStack itemstack = null; - Slot slot = (Slot)inventorySlots.get(i); - if(slot != null && slot.getHasStack()) + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + if (i < type.size) + { + if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - if(i < type.size) - { - if(!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) - { - return null; - } - } else - if(!mergeItemStack(itemstack1, 0, type.size, false)) - { - return null; - } - if(itemstack1.stackSize == 0) - { - slot.putStack(null); - } else - { - slot.onSlotChanged(); - } + return null; } - return itemstack; + } else if (!mergeItemStack(itemstack1, 0, type.size, false)) + { + return null; + } + if (itemstack1.stackSize == 0) + { + slot.putStack(null); + } else + { + slot.onSlotChanged(); + } } + return itemstack; + } - public void onCraftGuiClosed(EntityPlayer entityplayer) + public void onCraftGuiClosed(EntityPlayer entityplayer) + { + super.onCraftGuiClosed(entityplayer); + chest.closeChest(); + } + + protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { + for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) { - super.onCraftGuiClosed(entityplayer); - chest.closeChest(); + for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) + { + addSlot(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); + } + } - protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - for(int chestRow = 0; chestRow < type.getRowCount(); chestRow++) - { - for(int chestCol = 0; chestCol < type.getRowLength(); chestCol++) - { - addSlot(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); - } - - } - - int leftCol=(xSize-162)/2 + 1; - for(int playerInvRow = 0; playerInvRow < 3; playerInvRow++) - { - for(int playerInvCol = 0; playerInvCol < 9; playerInvCol++) - { - addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4-playerInvRow) * 18 - 10)); - } - - } - - for(int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) - { - addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize-24)); - } - } + int leftCol = (xSize - 162) / 2 + 1; + for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) + { + for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) + { + addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10)); + } - private IInventory chest; + } + + for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) + { + addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24)); + } + } + public EntityPlayer getPlayer() { + return player; + } + + public IInventory getInventory() { + return chest; + } } diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java index f011303..f4e8d29 100644 --- a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java @@ -382,4 +382,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory { return null; } } + public void setMaxStackSize(int size) { + + } }