diff --git a/src/main/java/electroblob/wizardry/inventory/ContainerBookshelf.java b/src/main/java/electroblob/wizardry/inventory/ContainerBookshelf.java index abe711df..92520dea 100644 --- a/src/main/java/electroblob/wizardry/inventory/ContainerBookshelf.java +++ b/src/main/java/electroblob/wizardry/inventory/ContainerBookshelf.java @@ -35,13 +35,11 @@ public class ContainerBookshelf extends Container { } } - this.onSlotChanged(); - } /** Called from individual slots when their item is changed or removed. */ public void onSlotChanged(){ - this.tileentity.sync(); + //this.tileentity.sync(); } @Override diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java index 7f8125e6..ef18dcc9 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java @@ -37,6 +37,8 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, /** Controls the rotating rune and floating wand animations. */ public float timer = 0; + private boolean doNotSync; + public TileEntityArcaneWorkbench(){ inventory = NonNullList.withSize(ContainerArcaneWorkbench.UPGRADE_SLOT + 1, ItemStack.EMPTY); } @@ -48,7 +50,7 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, /** Called to manually sync the tile entity with clients. */ public void sync(){ - this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); + if(!doNotSync) this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); } @Override @@ -117,6 +119,7 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, ItemStack previous = inventory.set(slot, stack); // Only the central slot affects the in-world rendering, so only sync if that changes + // This must be done in the tile entity because containers only exist for player interaction, not hoppers etc. if(slot == ContainerArcaneWorkbench.CENTRE_SLOT && previous.isEmpty() != stack.isEmpty()) this.sync(); if(!stack.isEmpty() && stack.getCount() > getInventoryStackLimit()){ @@ -182,6 +185,10 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, @Override public void readFromNBT(NBTTagCompound tagCompound){ + // Prevent sync() happening when loading from NBT or weirdness ensues when loading a world + // Normally I'd pass this as a flag to setInventorySlotContents but we can't change the method signature + this.doNotSync = true; + super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory", NBT.TAG_COMPOUND); @@ -192,6 +199,8 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, setInventorySlotContents(slot, new ItemStack(tag)); } } + + this.doNotSync = false; } @Override diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java index c469e62d..7b70b5f7 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java @@ -24,13 +24,15 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick /** The inventory of the bookshelf. */ private NonNullList inventory; + private boolean doNotSync; + public TileEntityBookshelf(){ inventory = NonNullList.withSize(BlockBookshelf.SLOT_COUNT, ItemStack.EMPTY); } /** Called to manually sync the tile entity with clients. */ public void sync(){ - this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); + if(!doNotSync) this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); } @Override @@ -85,6 +87,7 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick ItemStack previous = inventory.set(slot, stack); + // This must be done in the tile entity because containers only exist for player interaction, not hoppers etc. if(previous.isEmpty() != stack.isEmpty()) this.sync(); if(!stack.isEmpty() && stack.getCount() > getInventoryStackLimit()){ @@ -136,6 +139,10 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick @Override public void readFromNBT(NBTTagCompound tagCompound){ + // Prevent sync() happening when loading from NBT or weirdness ensues when loading a world + // Normally I'd pass this as a flag to setInventorySlotContents but we can't change the method signature + this.doNotSync = true; + super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory", NBT.TAG_COMPOUND); @@ -146,6 +153,8 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick setInventorySlotContents(slot, new ItemStack(tag)); } } + + this.doNotSync = false; } @Override