Fix #71, Chest orientation will now stay the same after a Chunk Unload.

This commit is contained in:
alexbegt 2016-06-08 15:59:44 -04:00
parent 6e4188fe62
commit 5d607a0d15
6 changed files with 209 additions and 125 deletions

View File

@ -51,8 +51,9 @@ public enum IronChestType implements IStringSerializable
public final Collection<String> recipes; public final Collection<String> recipes;
public final Collection<String> matList; public final Collection<String> matList;
IronChestType(int size, int rowLength, boolean tieredChest, String modelTexture, Collection<String> mats, Class<? extends TileEntityIronChest> clazz, //@formatter:off
String... recipes) IronChestType(int size, int rowLength, boolean tieredChest, String modelTexture, Collection<String> mats, Class<? extends TileEntityIronChest> clazz, String... recipes)
//@formatter:on
{ {
this.name = this.name().toLowerCase(); this.name = this.name().toLowerCase();
this.size = size; this.size = size;

View File

@ -54,8 +54,9 @@ public class ItemChestChanger extends Item
} }
else else
{ {
if (worldIn.getBlockState(pos) != IronChest.ironChestBlock //@formatter:off
.getStateFromMeta(IronChestType.valueOf(this.type.source.getName().toUpperCase()).ordinal())) if (worldIn.getBlockState(pos) != IronChest.ironChestBlock.getStateFromMeta(IronChestType.valueOf(this.type.source.getName().toUpperCase()).ordinal()))
//@formatter:on
{ {
return EnumActionResult.PASS; return EnumActionResult.PASS;
} }

View File

@ -12,7 +12,6 @@ package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest public class TileEntityGoldChest extends TileEntityIronChest
{ {
public TileEntityGoldChest() public TileEntityGoldChest()
{ {
super(IronChestType.GOLD); super(IronChestType.GOLD);

View File

@ -12,7 +12,8 @@ package cpw.mods.ironchest;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
@ -38,7 +39,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
private int ticksSinceSync = -1; private int ticksSinceSync = -1;
public float prevLidAngle; public float prevLidAngle;
public float lidAngle; public float lidAngle;
private int numUsingPlayers; private int numPlayersUsing;
public ItemStack[] chestContents; public ItemStack[] chestContents;
private ItemStack[] topStacks; private ItemStack[] topStacks;
private EnumFacing facing; private EnumFacing facing;
@ -62,6 +63,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public void setContents(ItemStack[] contents) public void setContents(ItemStack[] contents)
{ {
this.chestContents = new ItemStack[this.getType().size]; this.chestContents = new ItemStack[this.getType().size];
for (int i = 0; i < contents.length; i++) for (int i = 0; i < contents.length; i++)
{ {
if (i < this.chestContents.length) if (i < this.chestContents.length)
@ -69,6 +71,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
this.chestContents[i] = contents[i]; this.chestContents[i] = contents[i];
} }
} }
this.inventoryTouched = true; this.inventoryTouched = true;
} }
@ -86,6 +89,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
public IronChestType getType() public IronChestType getType()
{ {
IronChestType type = IronChestType.WOOD; IronChestType type = IronChestType.WOOD;
if (this.hasWorldObj()) if (this.hasWorldObj())
{ {
IBlockState state = this.worldObj.getBlockState(this.pos); IBlockState state = this.worldObj.getBlockState(this.pos);
@ -94,20 +98,23 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
type = state.getValue(BlockIronChest.VARIANT_PROP); type = state.getValue(BlockIronChest.VARIANT_PROP);
} }
} }
return type; return type;
} }
@Override @Override
public ItemStack getStackInSlot(int i) public ItemStack getStackInSlot(int index)
{ {
this.inventoryTouched = true; this.inventoryTouched = true;
return this.chestContents[i];
return this.chestContents[index];
} }
@Override @Override
public void markDirty() public void markDirty()
{ {
super.markDirty(); super.markDirty();
this.sortTopStacks(); this.sortTopStacks();
} }
@ -117,9 +124,13 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
return; return;
} }
ItemStack[] tempCopy = new ItemStack[this.getSizeInventory()]; ItemStack[] tempCopy = new ItemStack[this.getSizeInventory()];
boolean hasStuff = false; boolean hasStuff = false;
int compressedIdx = 0; int compressedIdx = 0;
mainLoop: for (int i = 0; i < this.getSizeInventory(); i++) mainLoop: for (int i = 0; i < this.getSizeInventory(); i++)
{ {
if (this.chestContents[i] != null) if (this.chestContents[i] != null)
@ -136,21 +147,27 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
hasStuff = true; hasStuff = true;
} }
} }
if (!hasStuff && this.hadStuff) if (!hasStuff && this.hadStuff)
{ {
this.hadStuff = false; this.hadStuff = false;
for (int i = 0; i < this.topStacks.length; i++) for (int i = 0; i < this.topStacks.length; i++)
{ {
this.topStacks[i] = null; this.topStacks[i] = null;
} }
if (this.worldObj != null) if (this.worldObj != null)
{ {
IBlockState iblockstate = this.worldObj.getBlockState(this.pos); IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
} }
return; return;
} }
this.hadStuff = true; this.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)
@ -169,48 +186,61 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
} }
}); });
int p = 0; int p = 0;
for (ItemStack element : tempCopy) for (ItemStack element : tempCopy)
{ {
if (element != null && element.stackSize > 0) if (element != null && element.stackSize > 0)
{ {
this.topStacks[p++] = element; this.topStacks[p++] = element;
if (p == this.topStacks.length) if (p == this.topStacks.length)
{ {
break; break;
} }
} }
} }
for (int i = p; i < this.topStacks.length; i++) for (int i = p; i < this.topStacks.length; i++)
{ {
this.topStacks[i] = null; this.topStacks[i] = null;
} }
if (this.worldObj != null) if (this.worldObj != null)
{ {
IBlockState iblockstate = this.worldObj.getBlockState(this.pos); IBlockState iblockstate = this.worldObj.getBlockState(this.pos);
this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); this.worldObj.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
} }
} }
@Override @Override
public ItemStack decrStackSize(int i, int j) public ItemStack decrStackSize(int index, int count)
{ {
if (this.chestContents[i] != null) if (this.chestContents[index] != null)
{ {
if (this.chestContents[i].stackSize <= j) if (this.chestContents[index].stackSize <= count)
{ {
ItemStack itemstack = this.chestContents[i]; ItemStack stack = this.chestContents[index];
this.chestContents[i] = null;
this.chestContents[index] = null;
this.markDirty(); this.markDirty();
return itemstack;
return stack;
} }
ItemStack itemstack1 = this.chestContents[i].splitStack(j);
if (this.chestContents[i].stackSize == 0) ItemStack stack = this.chestContents[index].splitStack(count);
if (this.chestContents[index].stackSize == 0)
{ {
this.chestContents[i] = null; this.chestContents[index] = null;
} }
this.markDirty(); this.markDirty();
return itemstack1;
return stack;
} }
else else
{ {
@ -219,13 +249,15 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack itemstack) public void setInventorySlotContents(int index, @Nullable ItemStack stack)
{ {
this.chestContents[i] = itemstack; this.chestContents[index] = stack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{ {
itemstack.stackSize = this.getInventoryStackLimit(); stack.stackSize = this.getInventoryStackLimit();
} }
this.markDirty(); this.markDirty();
} }
@ -247,56 +279,67 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbttagcompound) public void readFromNBT(NBTTagCompound compound)
{ {
super.readFromNBT(nbttagcompound); super.readFromNBT(compound);
NBTTagList tagList = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
this.chestContents = new ItemStack[this.getSizeInventory()]; this.chestContents = new ItemStack[this.getSizeInventory()];
if (nbttagcompound.hasKey("CustomName", Constants.NBT.TAG_STRING)) if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
{ {
this.customName = nbttagcompound.getString("CustomName"); this.customName = compound.getString("CustomName");
} }
for (int i = 0; i < nbttaglist.tagCount(); i++) for (int i = 0; i < tagList.tagCount(); i++)
{ {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); NBTTagCompound tag = tagList.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < this.chestContents.length) int slot = tag.getByte("Slot") & 0xff;
if (slot >= 0 && slot < this.chestContents.length)
{ {
this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); this.chestContents[slot] = ItemStack.loadItemStackFromNBT(tag);
} }
} }
this.facing = EnumFacing.VALUES[nbttagcompound.getByte("facing")];
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
this.sortTopStacks(); this.sortTopStacks();
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) public NBTTagCompound writeToNBT(NBTTagCompound compound)
{ {
super.writeToNBT(nbttagcompound); super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.chestContents.length; i++) NBTTagList tagList = new NBTTagList();
for (int slot = 0; slot < this.chestContents.length; slot++)
{ {
if (this.chestContents[i] != null) if (this.chestContents[slot] != null)
{ {
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
this.chestContents[i].writeToNBT(nbttagcompound1); tag.setByte("Slot", (byte) slot);
nbttaglist.appendTag(nbttagcompound1);
this.chestContents[slot].writeToNBT(tag);
tagList.appendTag(tag);
} }
} }
nbttagcompound.setTag("Items", nbttaglist); compound.setTag("Items", tagList);
nbttagcompound.setByte("facing", (byte) this.facing.ordinal());
compound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName()) if (this.hasCustomName())
{ {
nbttagcompound.setString("CustomName", this.customName); compound.setString("CustomName", this.customName);
} }
return nbttagcompound; return compound;
} }
@Override @Override
@ -306,86 +349,105 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) public boolean isUseableByPlayer(EntityPlayer player)
{ {
if (this.worldObj == null) if (this.worldObj == null)
{ {
return true; return true;
} }
if (this.worldObj.getTileEntity(this.pos) != this) if (this.worldObj.getTileEntity(this.pos) != this)
{ {
return false; return false;
} }
return entityplayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64D;
return player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64D;
} }
@Override @Override
public void update() public void update()
{ {
// Resynchronize clients with the server state // Resynchronizes clients with the server state
if (this.worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0
&& (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0)
{
this.numUsingPlayers = 0;
float var1 = 5.0F;
//@formatter:off
List<EntityPlayer> var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - var1, this.pos.getY() - var1, this.pos.getZ() - var1, this.pos.getX() + 1 + var1, this.pos.getY() + 1 + var1, this.pos.getZ() + 1 + var1));
//@formatter:on
for (EntityPlayer var4 : var2) //@formatter:off
if (this.worldObj != null && !this.worldObj.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0)
//@formatter:on
{ {
if (var4.openContainer instanceof ContainerIronChest) this.numPlayersUsing = 0;
float f = 5.0F;
//@formatter:off
for (EntityPlayer player : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - f, this.pos.getY() - f, this.pos.getZ() - f, this.pos.getX() + 1 + f, this.pos.getY() + 1 + f, this.pos.getZ() + 1 + f)))
//@formatter:on
{ {
++this.numUsingPlayers; if (player.openContainer instanceof ContainerIronChest)
{
++this.numPlayersUsing;
} }
} }
} }
if (this.worldObj != null && !this.worldObj.isRemote && this.ticksSinceSync < 0) if (this.worldObj != null && !this.worldObj.isRemote && this.ticksSinceSync < 0)
{ {
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 3, ((this.numUsingPlayers << 3) & 0xF8) | (this.facing.ordinal() & 0x7)); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 3, ((this.numPlayersUsing << 3) & 0xF8) | (this.facing.ordinal() & 0x7));
} }
if (!this.worldObj.isRemote && this.inventoryTouched) if (!this.worldObj.isRemote && this.inventoryTouched)
{ {
this.inventoryTouched = false; this.inventoryTouched = false;
this.sortTopStacks(); this.sortTopStacks();
} }
this.ticksSinceSync++; this.ticksSinceSync++;
this.prevLidAngle = this.lidAngle; this.prevLidAngle = this.lidAngle;
float f = 0.1F;
if (this.numUsingPlayers > 0 && this.lidAngle == 0.0F) float angle = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F)
{ {
double d = this.pos.getX() + 0.5D; double x = this.pos.getX() + 0.5D;
double d1 = this.pos.getZ() + 0.5D; double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
//@formatter:off //@formatter:off
this.worldObj.playSound(null, d, this.pos.getY() + 0.5D, d1, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); this.worldObj.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:on //@formatter:on
} }
if (this.numUsingPlayers == 0 && this.lidAngle > 0.0F || this.numUsingPlayers > 0 && this.lidAngle < 1.0F)
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
{ {
float f1 = this.lidAngle; float currentAngle = this.lidAngle;
if (this.numUsingPlayers > 0)
if (this.numPlayersUsing > 0)
{ {
this.lidAngle += f; this.lidAngle += angle;
} }
else else
{ {
this.lidAngle -= f; this.lidAngle -= angle;
} }
if (this.lidAngle > 1.0F) if (this.lidAngle > 1.0F)
{ {
this.lidAngle = 1.0F; this.lidAngle = 1.0F;
} }
float f2 = 0.5F;
if (this.lidAngle < f2 && f1 >= f2) float maxAngle = 0.5F;
if (this.lidAngle < maxAngle && currentAngle >= maxAngle)
{ {
double d2 = this.pos.getX() + 0.5D; double x = this.pos.getX() + 0.5D;
double d3 = this.pos.getZ() + 0.5D; double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
//@formatter:off //@formatter:off
this.worldObj.playSound(null, d2, this.pos.getY() + 0.5D, d3, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F); this.worldObj.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:on //@formatter:on
} }
if (this.lidAngle < 0.0F) if (this.lidAngle < 0.0F)
{ {
this.lidAngle = 0.0F; this.lidAngle = 0.0F;
@ -394,21 +456,22 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
@Override @Override
public boolean receiveClientEvent(int i, int j) public boolean receiveClientEvent(int id, int type)
{ {
if (i == 1) if (id == 1)
{ {
this.numUsingPlayers = j; this.numPlayersUsing = type;
} }
else if (i == 2) else if (id == 2)
{ {
this.facing = EnumFacing.VALUES[j]; this.facing = EnumFacing.VALUES[type];
} }
else if (i == 3) else if (id == 3)
{ {
this.facing = EnumFacing.VALUES[j & 0x7]; this.facing = EnumFacing.VALUES[type & 0x7];
this.numUsingPlayers = (j & 0xF8) >> 3; this.numPlayersUsing = (type & 0xF8) >> 3;
} }
return true; return true;
} }
@ -419,8 +482,10 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
return; return;
} }
this.numUsingPlayers++;
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers); this.numPlayersUsing++;
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numPlayersUsing);
} }
@Override @Override
@ -430,13 +495,15 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
return; return;
} }
this.numUsingPlayers--;
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numUsingPlayers); this.numPlayersUsing--;
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 1, this.numPlayersUsing);
} }
public void setFacing(EnumFacing facing2) public void setFacing(EnumFacing facing)
{ {
this.facing = facing2; this.facing = facing;
} }
public ItemStack[] getTopItemStacks() public ItemStack[] getTopItemStacks()
@ -447,27 +514,26 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public SPacketUpdateTileEntity getUpdatePacket() public SPacketUpdateTileEntity getUpdatePacket()
{ {
NBTTagCompound compound = new NBTTagCompound();
NBTTagCompound nbt = new NBTTagCompound(); compound.setByte("facing", (byte) this.facing.ordinal());
nbt.setByte("facing", (byte) this.facing.ordinal());
ItemStack[] stacks = this.buildItemStackDataList(); ItemStack[] stacks = this.buildItemStackDataList();
if (stacks != null) if (stacks != null)
{ {
NBTTagList nbttaglist = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for (int i = 0; i < stacks.length; i++) for (int slot = 0; slot < stacks.length; slot++)
{ {
if (stacks[i] != null) if (stacks[slot] != null)
{ {
NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i); tag.setByte("Slot", (byte) slot);
stacks[i].writeToNBT(nbttagcompound1); stacks[slot].writeToNBT(tag);
nbttaglist.appendTag(nbttagcompound1); tagList.appendTag(tag);
} }
} }
nbt.setTag("stacks", nbttaglist); compound.setTag("stacks", tagList);
} }
return new SPacketUpdateTileEntity(this.pos, 0, nbt); return new SPacketUpdateTileEntity(this.pos, 0, compound);
} }
@Override @Override
@ -475,25 +541,30 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
if (pkt.getTileEntityType() == 0) if (pkt.getTileEntityType() == 0)
{ {
NBTTagCompound nbt = pkt.getNbtCompound(); NBTTagCompound compound = pkt.getNbtCompound();
this.facing = EnumFacing.VALUES[nbt.getByte("facing")];
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
NBTTagList tagList = compound.getTagList("stacks", Constants.NBT.TAG_COMPOUND);
NBTTagList tagList = nbt.getTagList("stacks", Constants.NBT.TAG_COMPOUND);
ItemStack[] stacks = new ItemStack[this.topStacks.length]; ItemStack[] stacks = new ItemStack[this.topStacks.length];
for (int i = 0; i < stacks.length; i++) for (int item = 0; item < stacks.length; item++)
{ {
NBTTagCompound nbt1 = tagList.getCompoundTagAt(i); NBTTagCompound itemStack = tagList.getCompoundTagAt(item);
int j = nbt1.getByte("Slot") & 0xff;
if (j >= 0 && j < stacks.length) int slot = itemStack.getByte("Slot") & 0xff;
if (slot >= 0 && slot < stacks.length)
{ {
stacks[j] = ItemStack.loadItemStackFromNBT(nbt1); stacks[slot] = ItemStack.loadItemStackFromNBT(itemStack);
} }
} }
if (this.getType().isTransparent() && stacks != null) if (this.getType().isTransparent() && stacks != null)
{ {
int pos = 0; int pos = 0;
for (int i = 0; i < this.topStacks.length; i++) for (int i = 0; i < this.topStacks.length; i++)
{ {
if (stacks[pos] != null) if (stacks[pos] != null)
@ -504,6 +575,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
this.topStacks[i] = null; this.topStacks[i] = null;
} }
pos++; pos++;
} }
} }
@ -515,7 +587,9 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
if (this.getType().isTransparent()) if (this.getType().isTransparent())
{ {
ItemStack[] sortList = new ItemStack[this.topStacks.length]; ItemStack[] sortList = new ItemStack[this.topStacks.length];
int pos = 0; int pos = 0;
for (ItemStack is : this.topStacks) for (ItemStack is : this.topStacks)
{ {
if (is != null) if (is != null)
@ -527,19 +601,23 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
sortList[pos++] = null; sortList[pos++] = null;
} }
} }
return sortList; return sortList;
} }
return null; return null;
} }
@Override @Override
public ItemStack removeStackFromSlot(int par1) public ItemStack removeStackFromSlot(int index)
{ {
if (this.chestContents[par1] != null) if (this.chestContents[index] != null)
{ {
ItemStack var2 = this.chestContents[par1]; ItemStack stack = this.chestContents[index];
this.chestContents[par1] = null;
return var2; this.chestContents[index] = null;
return stack;
} }
else else
{ {
@ -548,9 +626,9 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int index, ItemStack stack)
{ {
return this.getType().acceptsStack(itemstack); return this.getType().acceptsStack(stack);
} }
public void rotateAround() public void rotateAround()
@ -559,7 +637,7 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing.ordinal()); this.worldObj.addBlockEvent(this.pos, IronChest.ironChestBlock, 2, this.facing.ordinal());
} }
public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) public void wasPlaced(EntityLivingBase entityliving, ItemStack stack)
{ {
} }
@ -587,14 +665,14 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
@Override @Override
public void clear() public void clear()
{ {
for (int i = 0; i < this.chestContents.length; ++i) for (int slot = 0; slot < this.chestContents.length; ++slot)
{ {
this.chestContents[i] = null; this.chestContents[slot] = null;
} }
} }
@Override @Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer player) public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{ {
return null; return null;
} }
@ -610,4 +688,10 @@ public class TileEntityIronChest extends TileEntityLockable implements ITickable
{ {
return true; return true;
} }
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
} }

View File

@ -2,7 +2,6 @@ package cpw.mods.ironchest;
public class TileEntityObsidianChest extends TileEntityIronChest public class TileEntityObsidianChest extends TileEntityIronChest
{ {
public TileEntityObsidianChest() public TileEntityObsidianChest()
{ {
super(IronChestType.OBSIDIAN); super(IronChestType.OBSIDIAN);

View File

@ -8,9 +8,9 @@ public class ValidatingSlot extends Slot
{ {
private IronChestType type; private IronChestType type;
public ValidatingSlot(IInventory par1iInventory, int par2, int par3, int par4, IronChestType type) public ValidatingSlot(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition, IronChestType type)
{ {
super(par1iInventory, par2, par3, par4); super(inventoryIn, slotIndex, xPosition, yPosition);
this.type = type; this.type = type;
} }