Fix up method override.
This commit is contained in:
parent
dd542c0c48
commit
9aa53eec37
|
@ -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<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;
|
||||
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (chestContents[i] != null)
|
||||
{
|
||||
if (chestContents[i].stackSize <= j)
|
||||
{
|
||||
ItemStack itemstack = chestContents[i];
|
||||
chestContents[i] = null;
|
||||
onInventoryChanged();
|
||||
return itemstack;
|
||||
}
|
||||
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
||||
if (chestContents[i].stackSize == 0)
|
||||
{
|
||||
chestContents[i] = null;
|
||||
}
|
||||
onInventoryChanged();
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (chestContents[i] != null)
|
||||
{
|
||||
if (chestContents[i].stackSize <= j)
|
||||
{
|
||||
ItemStack itemstack = chestContents[i];
|
||||
chestContents[i] = null;
|
||||
onInventoryChanged();
|
||||
return itemstack;
|
||||
}
|
||||
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
||||
if (chestContents[i].stackSize == 0)
|
||||
{
|
||||
chestContents[i] = null;
|
||||
}
|
||||
onInventoryChanged();
|
||||
return itemstack1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
chestContents[i] = itemstack;
|
||||
if (itemstack != null && itemstack.stackSize > 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<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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlotOnClosing(int par1)
|
||||
{
|
||||
if (this.chestContents[par1] != null)
|
||||
{
|
||||
ItemStack var2 = this.chestContents[par1];
|
||||
this.chestContents[par1] = null;
|
||||
return var2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlotOnClosing(int par1)
|
||||
{
|
||||
if (this.chestContents[par1] != null)
|
||||
{
|
||||
ItemStack var2 = this.chestContents[par1];
|
||||
this.chestContents[par1] = null;
|
||||
return var2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue