Fix chests stuck open bug? Also, should reduce network chatter of chests a significant amount.

This commit is contained in:
Christian 2013-02-16 22:02:25 -05:00
parent 04f8f9207c
commit 1c1f0b224f
1 changed files with 31 additions and 5 deletions

View File

@ -12,14 +12,19 @@ package cpw.mods.ironchest;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
public class TileEntityIronChest extends TileEntity implements IInventory { public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync; private int ticksSinceSync;
@ -267,15 +272,35 @@ 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 (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0)
{ {
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); this.numUsingPlayers = 0;
if (inventoryTouched) float var1 = 5.0F;
List var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)this.xCoord - var1), (double)((float)this.yCoord - var1), (double)((float)this.zCoord - var1), (double)((float)(this.xCoord + 1) + var1), (double)((float)(this.yCoord + 1) + var1), (double)((float)(this.zCoord + 1) + var1)));
Iterator var3 = var2.iterator();
while (var3.hasNext())
{ {
inventoryTouched = false; EntityPlayer var4 = (EntityPlayer)var3.next();
sortTopStacks();
if (var4.openContainer instanceof ContainerIronChestBase)
{
++this.numUsingPlayers;
}
} }
} }
if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
}
if (!worldObj.isRemote && inventoryTouched)
{
inventoryTouched = false;
sortTopStacks();
}
this.ticksSinceSync++;
prevLidAngle = lidAngle; prevLidAngle = lidAngle;
float f = 0.1F; float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) if (numUsingPlayers > 0 && lidAngle == 0.0F)
@ -369,6 +394,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord); block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
newEntity.setFacing(facing); newEntity.setFacing(facing);
newEntity.sortTopStacks(); newEntity.sortTopStacks();
newEntity.ticksSinceSync = -1;
return newEntity; return newEntity;
} }