Skip to content

Commit

Permalink
Invalidate wired element when cable is added/removed
Browse files Browse the repository at this point in the history
Otherwise we end up caching the old value of getWiredElement, which
might be absent if there is no cable!

Fixes #1759
  • Loading branch information
SquidDev committed Mar 22, 2024
1 parent c9caffb commit cbafbca
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ public void clearRemoved() {
@Deprecated
public void setBlockState(BlockState state) {
var direction = getModemDirection();
var hasCable = hasCable();
super.setBlockState(state);

// We invalidate both the modem and element if the modem's direction is different.
if (getModemDirection() != direction && modemChanged != null) modemChanged.run();
// We invalidate both the modem and element if the modem direction or cable are different.
if (modemChanged != null && (hasCable() != hasCable || getModemDirection() != direction)) modemChanged.run();
}

@Nullable
Expand Down

0 comments on commit cbafbca

Please sign in to comment.