Fix up method override.

This commit is contained in:
Christian Weeks 2012-03-08 23:59:01 -05:00
parent dd542c0c48
commit 9aa53eec37
2 changed files with 166 additions and 163 deletions

View File

@ -30,8 +30,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
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];
}
@ -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,9 +56,10 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
public IronChestType getType() {
return type;
}
@Override
public ItemStack getStackInSlot(int i) {
inventoryTouched=true;
inventoryTouched = true;
return chestContents[i];
}
@ -71,54 +73,53 @@ 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<getSizeInventory(); i++) {
if (chestContents[i]!=null) {
for (int j=0; j<compressedIdx; j++) {
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++) {
if (chestContents[i] != null) {
for (int j = 0; j < compressedIdx; j++) {
if (tempCopy[j].isItemEqual(chestContents[i])) {
tempCopy[j].stackSize+=chestContents[i].stackSize;
tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop;
}
}
tempCopy[compressedIdx++]=chestContents[i].copy();
hasStuff=true;
tempCopy[compressedIdx++] = chestContents[i].copy();
hasStuff = true;
}
}
if (!hasStuff && hadStuff) {
hadStuff=false;
for (int i=0; i<topStacks.length; i++) {
topStacks[i]=null;
hadStuff = false;
for (int i = 0; i < topStacks.length; i++) {
topStacks[i] = null;
}
mod_IronChest.proxy.sendTileEntityUpdate(this);
return;
}
hadStuff=true;
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@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; i<tempCopy.length; i++) {
if (tempCopy[i]!=null && tempCopy[i].stackSize>0) {
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<topStacks.length; i++) {
topStacks[i]=null;
for (int i = p; i < topStacks.length; i++) {
topStacks[i] = null;
}
mod_IronChest.proxy.sendTileEntityUpdate(this);
}
@ -166,14 +167,14 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
chestContents = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(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");
facing = nbttagcompound.getByte("facing");
sortTopStacks();
}
@ -187,7 +188,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
if (chestContents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
nbttagcompound1.setByte("Slot", (byte) i);
chestContents[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
@ -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();
}
}
@ -260,43 +261,45 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
{
numUsingPlayers = j;
} else if (i == 2) {
facing = (byte)j;
facing = (byte) j;
} else if (i == 3) {
facing = (byte)(j & 0x7);
numUsingPlayers = (j & 0xF8 )>> 3;
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
}
@Override
public void openChest() {
if (worldObj==null) return;
if (worldObj == null)
return;
numUsingPlayers++;
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
}
@Override
public void closeChest() {
if (worldObj==null) return;
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,10 +310,10 @@ 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;
@ -321,40 +324,40 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
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<chest.topStacks.length*3) {
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
int pos = 0;
if (intData.length < chest.topStacks.length * 3) {
return;
}
for (int i=0; i<chest.topStacks.length; i++) {
if (intData[pos+2]!=0) {
ItemStack is=new ItemStack(intData[pos],intData[pos+2],intData[pos+1]);
chest.topStacks[i]=is;
for (int i = 0; i < chest.topStacks.length; i++) {
if (intData[pos + 2] != 0) {
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
} else {
chest.topStacks[i]=null;
chest.topStacks[i] = null;
}
pos+=3;
pos += 3;
}
}
}
public int[] buildIntDataList() {
if (type.isTransparent()) {
int[] sortList=new int[topStacks.length*3];
int pos=0;
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks) {
if (is!=null) {
sortList[pos++]=is.itemID;
sortList[pos++]=is.getItemDamage();
sortList[pos++]=is.stackSize;
if (is != null) {
sortList[pos++] = is.itemID;
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else {
sortList[pos++]=0;
sortList[pos++]=0;
sortList[pos++]=0;
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;

View File

@ -98,7 +98,7 @@ public class mod_IronChest extends BaseModMp {
proxy.showGUI(te,player);
}
public void HandleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) {
public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) {
proxy.handleTileEntityPacket(x,y,z,type,intData,floatData,stringData);
}
}