Skip to content

Commit

Permalink
Try to prevent potential stack overflow with drain handlers (#4291)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Apr 3, 2021
1 parent bf06b8f commit c1a5ac1
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}
}

/**
Expand Down

0 comments on commit c1a5ac1

Please sign in to comment.