From 9aa53eec377470b0778e320152c3077627dd2939 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 8 Mar 2012 23:59:01 -0500 Subject: [PATCH] Fix up method override. --- .../mods/ironchest/TileEntityIronChest.java | 327 +++++++++--------- .../net/minecraft/src/mod_IronChest.java | 2 +- 2 files changed, 166 insertions(+), 163 deletions(-) diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java index d86b7d9..6240dc8 100644 --- a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java @@ -27,18 +27,18 @@ public class TileEntityIronChest extends TileEntity implements IInventory { public TileEntityIronChest() { this(IronChestType.IRON); } - + protected TileEntityIronChest(IronChestType type) { super(); - this.type=type; - this.chestContents=new ItemStack[getSizeInventory()]; + this.type = type; + this.chestContents = new ItemStack[getSizeInventory()]; this.topStacks = new ItemStack[8]; } - + public ItemStack[] getContents() { return chestContents; } - + @Override public int getSizeInventory() { return type.size; @@ -47,6 +47,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory { public byte getFacing() { return this.facing; } + @Override public String getInvName() { return type.name(); @@ -55,10 +56,11 @@ public class TileEntityIronChest extends TileEntity implements IInventory { public IronChestType getType() { return type; } + @Override public ItemStack getStackInSlot(int i) { - inventoryTouched=true; - return chestContents[i]; + inventoryTouched = true; + return chestContents[i]; } @Override @@ -71,131 +73,130 @@ public class TileEntityIronChest extends TileEntity implements IInventory { if (!type.isTransparent() || mod_IronChest.proxy.isRemote()) { return; } - ItemStack[] tempCopy=new ItemStack[getSizeInventory()]; - boolean hasStuff=false; - int compressedIdx=0; - mainLoop: - for (int i=0; i() { + hadStuff = true; + Arrays.sort(tempCopy, new Comparator() { @Override public int compare(ItemStack o1, ItemStack o2) { - if (o1==null) { + if (o1 == null) { return 1; - } else if (o2==null) { + } else if (o2 == null) { return -1; } else { - return o2.stackSize-o1.stackSize; + return o2.stackSize - o1.stackSize; } } }); - int p=0; - for (int i=0; i0) { - topStacks[p++]=tempCopy[i]; - if (p==topStacks.length) { + int p = 0; + for (int i = 0; i < tempCopy.length; i++) { + if (tempCopy[i] != null && tempCopy[i].stackSize > 0) { + topStacks[p++] = tempCopy[i]; + if (p == topStacks.length) { break; } } } - for (int i=p; i getInventoryStackLimit()) - { - itemstack.stackSize = getInventoryStackLimit(); - } - onInventoryChanged(); + chestContents[i] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + } + onInventoryChanged(); } - @Override + @Override public void readFromNBT(NBTTagCompound nbttagcompound) - { - super.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) - { - NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i); - int j = nbttagcompound1.getByte("Slot") & 0xff; - if (j >= 0 && j < chestContents.length) - { - chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); - } - } - facing=nbttagcompound.getByte("facing"); - sortTopStacks(); - } + { + super.readFromNBT(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < nbttaglist.tagCount(); i++) + { + NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); + int j = nbttagcompound1.getByte("Slot") & 0xff; + if (j >= 0 && j < chestContents.length) + { + chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + facing = nbttagcompound.getByte("facing"); + sortTopStacks(); + } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) - { - super.writeToNBT(nbttagcompound); - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < chestContents.length; i++) - { - if (chestContents[i] != null) - { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte)i); - chestContents[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < chestContents.length; i++) + { + if (chestContents[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + chestContents[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } - nbttagcompound.setTag("Items", nbttaglist); - nbttagcompound.setByte("facing", facing); - } + nbttagcompound.setTag("Items", nbttaglist); + nbttagcompound.setByte("facing", facing); + } @Override public int getInventoryStackLimit() { @@ -204,7 +205,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory { @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { - if (worldObj==null) { + if (worldObj == null) { return true; } if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { @@ -218,9 +219,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory { super.updateEntity(); // Resynchronize clients with the server state if ((++ticksSinceSync % 20) * 4 == 0) { - worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ( ( numUsingPlayers<<3 ) & 0xF8 ) | (facing & 0x7)); + worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); if (inventoryTouched) { - inventoryTouched=false; + inventoryTouched = false; sortTopStacks(); } } @@ -254,49 +255,51 @@ public class TileEntityIronChest extends TileEntity implements IInventory { } @Override - public void onTileEntityPowered(int i, int j) - { - if (i == 1) - { - numUsingPlayers = j; - } else if (i == 2) { - facing = (byte)j; - } else if (i == 3) { - facing = (byte)(j & 0x7); - numUsingPlayers = (j & 0xF8 )>> 3; - } - } + public void onTileEntityPowered(int i, int j) + { + if (i == 1) + { + numUsingPlayers = j; + } else if (i == 2) { + facing = (byte) j; + } else if (i == 3) { + facing = (byte) (j & 0x7); + numUsingPlayers = (j & 0xF8) >> 3; + } + } @Override public void openChest() { - if (worldObj==null) return; - numUsingPlayers++; - worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + if (worldObj == null) + return; + numUsingPlayers++; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); } @Override public void closeChest() { - if (worldObj==null) return; - numUsingPlayers--; - worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + if (worldObj == null) + return; + numUsingPlayers--; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); } public void setFacing(byte chestFacing) { - this.facing=chestFacing; + this.facing = chestFacing; } public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) { - if (numUsingPlayers>0) { + if (numUsingPlayers > 0) { return null; } if (!itemChestChanger.getType().canUpgrade(this.getType())) { return null; } - TileEntityIronChest newEntity=IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); - int newSize=newEntity.chestContents.length; - System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize,chestContents.length)); - BlockIronChest block=mod_IronChest.ironChestBlock; - block.dropContent(newSize,this,this.worldObj); + TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); + int newSize = newEntity.chestContents.length; + System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); + BlockIronChest block = mod_IronChest.ironChestBlock; + block.dropContent(newSize, this, this.worldObj); newEntity.setFacing(facing); newEntity.sortTopStacks(); return newEntity; @@ -307,72 +310,72 @@ public class TileEntityIronChest extends TileEntity implements IInventory { } public TileEntityIronChest updateFromMetadata(int l) { - if (worldObj!=null && worldObj.isRemote) { - if (l!=type.ordinal()) { + if (worldObj != null && worldObj.isRemote) { + if (l != type.ordinal()) { worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); - return (TileEntityIronChest)worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); + return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); } } return this; } - + public Packet getDescriptionPacket() { return mod_IronChest.proxy.getDescriptionPacket(this); } public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) { - TileEntityIronChest chest=this; - if (this.type.ordinal()!=typeData) { - chest=updateFromMetadata(typeData); + TileEntityIronChest chest = this; + if (this.type.ordinal() != typeData) { + chest = updateFromMetadata(typeData); } - if (IronChestType.values()[typeData].isTransparent() && intData!=null) { - int pos=0; - if (intData.length