From c1a5ac1678b997b20425c318181442494e4724fc Mon Sep 17 00:00:00 2001 From: KnightMiner Date: Sat, 3 Apr 2021 16:34:09 -0400 Subject: [PATCH] Try to prevent potential stack overflow with drain handlers (#4291) --- .../tileentity/SmelteryInputOutputTileEntity.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/slimeknights/tconstruct/smeltery/tileentity/SmelteryInputOutputTileEntity.java b/src/main/java/slimeknights/tconstruct/smeltery/tileentity/SmelteryInputOutputTileEntity.java index 4f6ca8d1302..898b56ffac4 100644 --- a/src/main/java/slimeknights/tconstruct/smeltery/tileentity/SmelteryInputOutputTileEntity.java +++ b/src/main/java/slimeknights/tconstruct/smeltery/tileentity/SmelteryInputOutputTileEntity.java @@ -59,11 +59,8 @@ protected void invalidateCaps() { protected void setMaster(@Nullable BlockPos master, @Nullable Block block) { assert world != null; - // invalidate handlers if the master changed - if (!Objects.equals(getMasterPos(), master)) { - clearHandler(); - world.notifyNeighborsOfStateChange(pos, getBlockState().getBlock()); - } + // keep track of master before it changed + boolean masterChanged = !Objects.equals(getMasterPos(), master); // update the master boolean hadMaster = getMasterPos() != null; super.setMaster(master, block); @@ -72,6 +69,11 @@ protected void setMaster(@Nullable BlockPos master, @Nullable Block block) { if (hadMaster != hasMaster) { world.setBlockState(pos, getBlockState().with(SmelteryIOBlock.ACTIVE, hasMaster)); } + // if we have a new master, invalidate handlers + if (masterChanged) { + clearHandler(); + world.notifyNeighborsOfStateChange(pos, getBlockState().getBlock()); + } } /**