From 8682fcbe9162136e2c743e91ffa83a04f48194d8 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Sun, 12 Apr 2020 22:51:24 +0100 Subject: [PATCH] Only prevent syncing when first loading the world --- .../tileentity/TileEntityArcaneWorkbench.java | 11 +++++------ .../wizardry/tileentity/TileEntityBookshelf.java | 12 +++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java b/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java index ef18dcc9..a93acf55 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityArcaneWorkbench.java @@ -41,6 +41,9 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, public TileEntityArcaneWorkbench(){ inventory = NonNullList.withSize(ContainerArcaneWorkbench.UPGRADE_SLOT + 1, ItemStack.EMPTY); + // Prevent sync() happening when loading from NBT the first time 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; } @Override @@ -56,6 +59,8 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, @Override public void update(){ + this.doNotSync = false; + ItemStack stack = this.getStackInSlot(ContainerArcaneWorkbench.CENTRE_SLOT); // Decrements wand damage (increases mana) every 1.5 seconds if it has a condenser upgrade @@ -185,10 +190,6 @@ 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); @@ -199,8 +200,6 @@ 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 7b70b5f7..6d3565a7 100644 --- a/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java +++ b/src/main/java/electroblob/wizardry/tileentity/TileEntityBookshelf.java @@ -28,15 +28,19 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick public TileEntityBookshelf(){ inventory = NonNullList.withSize(BlockBookshelf.SLOT_COUNT, ItemStack.EMPTY); + // 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; } /** Called to manually sync the tile entity with clients. */ public void sync(){ - if(!doNotSync) this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); + if(!this.doNotSync) this.world.markAndNotifyBlock(pos, null, world.getBlockState(pos), world.getBlockState(pos), 3); } @Override public void update(){ + this.doNotSync = false; // Nothing here for now } @@ -139,10 +143,6 @@ 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); @@ -153,8 +153,6 @@ public class TileEntityBookshelf extends TileEntity implements IInventory, ITick setInventorySlotContents(slot, new ItemStack(tag)); } } - - this.doNotSync = false; } @Override