From ab0adfa25b6b0f93b6393a27c1c94920aeadfee1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 11 Jan 2016 22:41:33 +0100 Subject: [PATCH] Revert the fix, tried to fix it another way --- .../mod/network/VanillaPacketSyncer.java | 4 +- .../tile/TileEntityAtomicReconstructor.java | 17 ++---- .../mod/tile/TileEntityInventoryBase.java | 56 +++++++++---------- 3 files changed, 33 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/VanillaPacketSyncer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/VanillaPacketSyncer.java index 07d531664..05e2b0feb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/VanillaPacketSyncer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/VanillaPacketSyncer.java @@ -33,6 +33,8 @@ public class VanillaPacketSyncer{ } public static void sendTileToPlayer(TileEntity tile, EntityPlayerMP player){ - player.playerNetServerHandler.sendPacket(tile.getDescriptionPacket()); + if(player.getEntityWorld().getTileEntity(tile.getPos()) == tile){ + player.playerNetServerHandler.sendPacket(tile.getDescriptionPacket()); + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 6e482c98b..89a7a6276 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -39,8 +39,6 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple private boolean activateOnceWithSignal; private int oldEnergy; - public boolean syncSlotsNextTime; - public TileEntityAtomicReconstructor(){ super(1, "reconstructor"); } @@ -111,12 +109,11 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple super.writeSyncableNBT(compound, sync); compound.setInteger("CurrentTime", this.currentTime); this.storage.writeToNBT(compound); + } - if(this.syncSlotsNextTime){ - this.writeSlotsToCompound(compound); - compound.setBoolean("ShouldSync", true); - this.syncSlotsNextTime = false; - } + @Override + public boolean shouldSyncSlots(){ + return true; } @Override @@ -124,22 +121,16 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple super.readSyncableNBT(compound, sync); this.currentTime = compound.getInteger("CurrentTime"); this.storage.readFromNBT(compound); - - if(compound.getBoolean("ShouldSync")){ - this.readSlotsFromCompound(compound); - } } @Override public void setInventorySlotContents(int i, ItemStack stack){ super.setInventorySlotContents(i, stack); - this.syncSlotsNextTime = true; this.sendUpdate(); } @Override public ItemStack decrStackSize(int i, int j){ - this.syncSlotsNextTime = true; this.sendUpdate(); return super.decrStackSize(i, j); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java index 8f70acaf7..17b84f55c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityInventoryBase.java @@ -41,42 +41,38 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements @Override public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){ super.writeSyncableNBT(compound, isForSync); - if(!isForSync){ - this.writeSlotsToCompound(compound); + if(!isForSync || this.shouldSyncSlots()){ + if(this.slots.length > 0){ + NBTTagList tagList = new NBTTagList(); + for(int currentIndex = 0; currentIndex < slots.length; currentIndex++){ + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setByte("Slot", (byte)currentIndex); + if(slots[currentIndex] != null){ + slots[currentIndex].writeToNBT(tagCompound); + } + tagList.appendTag(tagCompound); + } + compound.setTag("Items", tagList); + } } } + public boolean shouldSyncSlots(){ + return false; + } + @Override public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){ super.readSyncableNBT(compound, isForSync); - if(!isForSync){ - this.readSlotsFromCompound(compound); - } - } - - public void writeSlotsToCompound(NBTTagCompound compound){ - if(this.slots.length > 0){ - NBTTagList tagList = new NBTTagList(); - for(int currentIndex = 0; currentIndex < slots.length; currentIndex++){ - NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setByte("Slot", (byte)currentIndex); - if(slots[currentIndex] != null){ - slots[currentIndex].writeToNBT(tagCompound); - } - tagList.appendTag(tagCompound); - } - compound.setTag("Items", tagList); - } - } - - public void readSlotsFromCompound(NBTTagCompound compound){ - if(this.slots.length > 0){ - NBTTagList tagList = compound.getTagList("Items", 10); - for(int i = 0; i < tagList.tagCount(); i++){ - NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); - byte slotIndex = tagCompound.getByte("Slot"); - if(slotIndex >= 0 && slotIndex < slots.length){ - slots[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound); + if(!isForSync || this.shouldSyncSlots()){ + if(this.slots.length > 0){ + NBTTagList tagList = compound.getTagList("Items", 10); + for(int i = 0; i < tagList.tagCount(); i++){ + NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); + byte slotIndex = tagCompound.getByte("Slot"); + if(slotIndex >= 0 && slotIndex < slots.length){ + slots[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound); + } } } }