Add in code to support the bukkit fun

This commit is contained in:
Christian Weeks 2012-04-15 18:30:49 -04:00
parent f12f8b1c31
commit 554d6c7005
2 changed files with 77 additions and 65 deletions

View File

@ -3,14 +3,19 @@ package cpw.mods.ironchest;
import net.minecraft.src.Container; import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory; import net.minecraft.src.IInventory;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot; import net.minecraft.src.Slot;
public class ContainerIronChestBase extends Container { public class ContainerIronChestBase extends Container {
private IronChestType type; private IronChestType type;
private EntityPlayer player;
private IInventory chest;
public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
chest = chestInventory; chest = chestInventory;
this.type=type; player = ((InventoryPlayer) playerInventory).player;
this.type = type;
chestInventory.openChest(); chestInventory.openChest();
layoutContainer(playerInventory, chestInventory, type, xSize, ySize); layoutContainer(playerInventory, chestInventory, type, xSize, ySize);
} }
@ -23,23 +28,22 @@ public class ContainerIronChestBase extends Container {
public ItemStack transferStackInSlot(int i) public ItemStack transferStackInSlot(int i)
{ {
ItemStack itemstack = null; ItemStack itemstack = null;
Slot slot = (Slot)inventorySlots.get(i); Slot slot = (Slot) inventorySlots.get(i);
if(slot != null && slot.getHasStack()) if (slot != null && slot.getHasStack())
{ {
ItemStack itemstack1 = slot.getStack(); ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy(); itemstack = itemstack1.copy();
if(i < type.size) if (i < type.size)
{ {
if(!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true))
{ {
return null; return null;
} }
} else } else if (!mergeItemStack(itemstack1, 0, type.size, false))
if(!mergeItemStack(itemstack1, 0, type.size, false))
{ {
return null; return null;
} }
if(itemstack1.stackSize == 0) if (itemstack1.stackSize == 0)
{ {
slot.putStack(null); slot.putStack(null);
} else } else
@ -57,30 +61,35 @@ public class ContainerIronChestBase extends Container {
} }
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
for(int chestRow = 0; chestRow < type.getRowCount(); chestRow++) for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{ {
for(int chestCol = 0; chestCol < type.getRowLength(); chestCol++) for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
{ {
addSlot(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); addSlot(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
} }
} }
int leftCol=(xSize-162)/2 + 1; int leftCol = (xSize - 162) / 2 + 1;
for(int playerInvRow = 0; playerInvRow < 3; playerInvRow++) for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
{ {
for(int playerInvCol = 0; playerInvCol < 9; playerInvCol++) for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{ {
addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4-playerInvRow) * 18 - 10)); addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
} }
} }
for(int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
{ {
addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize-24)); addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24));
} }
} }
public EntityPlayer getPlayer() {
return player;
}
private IInventory chest; public IInventory getInventory() {
return chest;
}
} }

View File

@ -382,4 +382,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return null; return null;
} }
} }
public void setMaxStackSize(int size) {
}
} }