Fix up method override.
This commit is contained in:
parent
dd542c0c48
commit
9aa53eec37
|
@ -30,8 +30,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
|
|
||||||
protected TileEntityIronChest(IronChestType type) {
|
protected TileEntityIronChest(IronChestType type) {
|
||||||
super();
|
super();
|
||||||
this.type=type;
|
this.type = type;
|
||||||
this.chestContents=new ItemStack[getSizeInventory()];
|
this.chestContents = new ItemStack[getSizeInventory()];
|
||||||
this.topStacks = new ItemStack[8];
|
this.topStacks = new ItemStack[8];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
public byte getFacing() {
|
public byte getFacing() {
|
||||||
return this.facing;
|
return this.facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInvName() {
|
public String getInvName() {
|
||||||
return type.name();
|
return type.name();
|
||||||
|
@ -55,10 +56,11 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
public IronChestType getType() {
|
public IronChestType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int i) {
|
public ItemStack getStackInSlot(int i) {
|
||||||
inventoryTouched=true;
|
inventoryTouched = true;
|
||||||
return chestContents[i];
|
return chestContents[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,131 +73,130 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
if (!type.isTransparent() || mod_IronChest.proxy.isRemote()) {
|
if (!type.isTransparent() || mod_IronChest.proxy.isRemote()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack[] tempCopy=new ItemStack[getSizeInventory()];
|
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
|
||||||
boolean hasStuff=false;
|
boolean hasStuff = false;
|
||||||
int compressedIdx=0;
|
int compressedIdx = 0;
|
||||||
mainLoop:
|
mainLoop: for (int i = 0; i < getSizeInventory(); i++) {
|
||||||
for (int i=0; i<getSizeInventory(); i++) {
|
if (chestContents[i] != null) {
|
||||||
if (chestContents[i]!=null) {
|
for (int j = 0; j < compressedIdx; j++) {
|
||||||
for (int j=0; j<compressedIdx; j++) {
|
|
||||||
if (tempCopy[j].isItemEqual(chestContents[i])) {
|
if (tempCopy[j].isItemEqual(chestContents[i])) {
|
||||||
tempCopy[j].stackSize+=chestContents[i].stackSize;
|
tempCopy[j].stackSize += chestContents[i].stackSize;
|
||||||
continue mainLoop;
|
continue mainLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempCopy[compressedIdx++]=chestContents[i].copy();
|
tempCopy[compressedIdx++] = chestContents[i].copy();
|
||||||
hasStuff=true;
|
hasStuff = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasStuff && hadStuff) {
|
if (!hasStuff && hadStuff) {
|
||||||
hadStuff=false;
|
hadStuff = false;
|
||||||
for (int i=0; i<topStacks.length; i++) {
|
for (int i = 0; i < topStacks.length; i++) {
|
||||||
topStacks[i]=null;
|
topStacks[i] = null;
|
||||||
}
|
}
|
||||||
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hadStuff=true;
|
hadStuff = true;
|
||||||
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
|
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ItemStack o1, ItemStack o2) {
|
public int compare(ItemStack o1, ItemStack o2) {
|
||||||
if (o1==null) {
|
if (o1 == null) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (o2==null) {
|
} else if (o2 == null) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return o2.stackSize-o1.stackSize;
|
return o2.stackSize - o1.stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
int p=0;
|
int p = 0;
|
||||||
for (int i=0; i<tempCopy.length; i++) {
|
for (int i = 0; i < tempCopy.length; i++) {
|
||||||
if (tempCopy[i]!=null && tempCopy[i].stackSize>0) {
|
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) {
|
||||||
topStacks[p++]=tempCopy[i];
|
topStacks[p++] = tempCopy[i];
|
||||||
if (p==topStacks.length) {
|
if (p == topStacks.length) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i=p; i<topStacks.length; i++) {
|
for (int i = p; i < topStacks.length; i++) {
|
||||||
topStacks[i]=null;
|
topStacks[i] = null;
|
||||||
}
|
}
|
||||||
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
mod_IronChest.proxy.sendTileEntityUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int i, int j) {
|
public ItemStack decrStackSize(int i, int j) {
|
||||||
if (chestContents[i] != null)
|
if (chestContents[i] != null)
|
||||||
{
|
{
|
||||||
if (chestContents[i].stackSize <= j)
|
if (chestContents[i].stackSize <= j)
|
||||||
{
|
{
|
||||||
ItemStack itemstack = chestContents[i];
|
ItemStack itemstack = chestContents[i];
|
||||||
chestContents[i] = null;
|
chestContents[i] = null;
|
||||||
onInventoryChanged();
|
onInventoryChanged();
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
ItemStack itemstack1 = chestContents[i].splitStack(j);
|
||||||
if (chestContents[i].stackSize == 0)
|
if (chestContents[i].stackSize == 0)
|
||||||
{
|
{
|
||||||
chestContents[i] = null;
|
chestContents[i] = null;
|
||||||
}
|
}
|
||||||
onInventoryChanged();
|
onInventoryChanged();
|
||||||
return itemstack1;
|
return itemstack1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||||
chestContents[i] = itemstack;
|
chestContents[i] = itemstack;
|
||||||
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
|
||||||
{
|
{
|
||||||
itemstack.stackSize = getInventoryStackLimit();
|
itemstack.stackSize = getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
onInventoryChanged();
|
onInventoryChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound)
|
public void readFromNBT(NBTTagCompound nbttagcompound)
|
||||||
{
|
{
|
||||||
super.readFromNBT(nbttagcompound);
|
super.readFromNBT(nbttagcompound);
|
||||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
|
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
|
||||||
chestContents = new ItemStack[getSizeInventory()];
|
chestContents = new ItemStack[getSizeInventory()];
|
||||||
for (int i = 0; i < nbttaglist.tagCount(); i++)
|
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;
|
int j = nbttagcompound1.getByte("Slot") & 0xff;
|
||||||
if (j >= 0 && j < chestContents.length)
|
if (j >= 0 && j < chestContents.length)
|
||||||
{
|
{
|
||||||
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
facing=nbttagcompound.getByte("facing");
|
facing = nbttagcompound.getByte("facing");
|
||||||
sortTopStacks();
|
sortTopStacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound)
|
public void writeToNBT(NBTTagCompound nbttagcompound)
|
||||||
{
|
{
|
||||||
super.writeToNBT(nbttagcompound);
|
super.writeToNBT(nbttagcompound);
|
||||||
NBTTagList nbttaglist = new NBTTagList();
|
NBTTagList nbttaglist = new NBTTagList();
|
||||||
for (int i = 0; i < chestContents.length; i++)
|
for (int i = 0; i < chestContents.length; i++)
|
||||||
{
|
{
|
||||||
if (chestContents[i] != null)
|
if (chestContents[i] != null)
|
||||||
{
|
{
|
||||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||||
nbttagcompound1.setByte("Slot", (byte)i);
|
nbttagcompound1.setByte("Slot", (byte) i);
|
||||||
chestContents[i].writeToNBT(nbttagcompound1);
|
chestContents[i].writeToNBT(nbttagcompound1);
|
||||||
nbttaglist.appendTag(nbttagcompound1);
|
nbttaglist.appendTag(nbttagcompound1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nbttagcompound.setTag("Items", nbttaglist);
|
nbttagcompound.setTag("Items", nbttaglist);
|
||||||
nbttagcompound.setByte("facing", facing);
|
nbttagcompound.setByte("facing", facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit() {
|
||||||
|
@ -204,7 +205,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||||
if (worldObj==null) {
|
if (worldObj == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) {
|
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) {
|
||||||
|
@ -218,9 +219,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
// Resynchronize clients with the server state
|
// Resynchronize clients with the server state
|
||||||
if ((++ticksSinceSync % 20) * 4 == 0) {
|
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) {
|
if (inventoryTouched) {
|
||||||
inventoryTouched=false;
|
inventoryTouched = false;
|
||||||
sortTopStacks();
|
sortTopStacks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,49 +255,51 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTileEntityPowered(int i, int j)
|
public void onTileEntityPowered(int i, int j)
|
||||||
{
|
{
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
numUsingPlayers = j;
|
numUsingPlayers = j;
|
||||||
} else if (i == 2) {
|
} else if (i == 2) {
|
||||||
facing = (byte)j;
|
facing = (byte) j;
|
||||||
} else if (i == 3) {
|
} else if (i == 3) {
|
||||||
facing = (byte)(j & 0x7);
|
facing = (byte) (j & 0x7);
|
||||||
numUsingPlayers = (j & 0xF8 )>> 3;
|
numUsingPlayers = (j & 0xF8) >> 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openChest() {
|
public void openChest() {
|
||||||
if (worldObj==null) return;
|
if (worldObj == null)
|
||||||
numUsingPlayers++;
|
return;
|
||||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
numUsingPlayers++;
|
||||||
|
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeChest() {
|
public void closeChest() {
|
||||||
if (worldObj==null) return;
|
if (worldObj == null)
|
||||||
numUsingPlayers--;
|
return;
|
||||||
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
numUsingPlayers--;
|
||||||
|
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFacing(byte chestFacing) {
|
public void setFacing(byte chestFacing) {
|
||||||
this.facing=chestFacing;
|
this.facing = chestFacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
|
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
|
||||||
if (numUsingPlayers>0) {
|
if (numUsingPlayers > 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
|
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
TileEntityIronChest newEntity=IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
|
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
|
||||||
int newSize=newEntity.chestContents.length;
|
int newSize = newEntity.chestContents.length;
|
||||||
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize,chestContents.length));
|
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length));
|
||||||
BlockIronChest block=mod_IronChest.ironChestBlock;
|
BlockIronChest block = mod_IronChest.ironChestBlock;
|
||||||
block.dropContent(newSize,this,this.worldObj);
|
block.dropContent(newSize, this, this.worldObj);
|
||||||
newEntity.setFacing(facing);
|
newEntity.setFacing(facing);
|
||||||
newEntity.sortTopStacks();
|
newEntity.sortTopStacks();
|
||||||
return newEntity;
|
return newEntity;
|
||||||
|
@ -307,10 +310,10 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntityIronChest updateFromMetadata(int l) {
|
public TileEntityIronChest updateFromMetadata(int l) {
|
||||||
if (worldObj!=null && worldObj.isRemote) {
|
if (worldObj != null && worldObj.isRemote) {
|
||||||
if (l!=type.ordinal()) {
|
if (l != type.ordinal()) {
|
||||||
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
|
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
|
||||||
return (TileEntityIronChest)worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
|
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -321,40 +324,40 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) {
|
public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) {
|
||||||
TileEntityIronChest chest=this;
|
TileEntityIronChest chest = this;
|
||||||
if (this.type.ordinal()!=typeData) {
|
if (this.type.ordinal() != typeData) {
|
||||||
chest=updateFromMetadata(typeData);
|
chest = updateFromMetadata(typeData);
|
||||||
}
|
}
|
||||||
if (IronChestType.values()[typeData].isTransparent() && intData!=null) {
|
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
|
||||||
int pos=0;
|
int pos = 0;
|
||||||
if (intData.length<chest.topStacks.length*3) {
|
if (intData.length < chest.topStacks.length * 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i=0; i<chest.topStacks.length; i++) {
|
for (int i = 0; i < chest.topStacks.length; i++) {
|
||||||
if (intData[pos+2]!=0) {
|
if (intData[pos + 2] != 0) {
|
||||||
ItemStack is=new ItemStack(intData[pos],intData[pos+2],intData[pos+1]);
|
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
|
||||||
chest.topStacks[i]=is;
|
chest.topStacks[i] = is;
|
||||||
} else {
|
} else {
|
||||||
chest.topStacks[i]=null;
|
chest.topStacks[i] = null;
|
||||||
}
|
}
|
||||||
pos+=3;
|
pos += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] buildIntDataList() {
|
public int[] buildIntDataList() {
|
||||||
if (type.isTransparent()) {
|
if (type.isTransparent()) {
|
||||||
int[] sortList=new int[topStacks.length*3];
|
int[] sortList = new int[topStacks.length * 3];
|
||||||
int pos=0;
|
int pos = 0;
|
||||||
for (ItemStack is : topStacks) {
|
for (ItemStack is : topStacks) {
|
||||||
if (is!=null) {
|
if (is != null) {
|
||||||
sortList[pos++]=is.itemID;
|
sortList[pos++] = is.itemID;
|
||||||
sortList[pos++]=is.getItemDamage();
|
sortList[pos++] = is.getItemDamage();
|
||||||
sortList[pos++]=is.stackSize;
|
sortList[pos++] = is.stackSize;
|
||||||
} else {
|
} else {
|
||||||
sortList[pos++]=0;
|
sortList[pos++] = 0;
|
||||||
sortList[pos++]=0;
|
sortList[pos++] = 0;
|
||||||
sortList[pos++]=0;
|
sortList[pos++] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sortList;
|
return sortList;
|
||||||
|
@ -362,17 +365,17 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getStackInSlotOnClosing(int par1)
|
public ItemStack getStackInSlotOnClosing(int par1)
|
||||||
{
|
{
|
||||||
if (this.chestContents[par1] != null)
|
if (this.chestContents[par1] != null)
|
||||||
{
|
{
|
||||||
ItemStack var2 = this.chestContents[par1];
|
ItemStack var2 = this.chestContents[par1];
|
||||||
this.chestContents[par1] = null;
|
this.chestContents[par1] = null;
|
||||||
return var2;
|
return var2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class mod_IronChest extends BaseModMp {
|
||||||
proxy.showGUI(te,player);
|
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);
|
proxy.handleTileEntityPacket(x,y,z,type,intData,floatData,stringData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue