Invalidate wired element when cable is added/removed

Otherwise we end up caching the old value of getWiredElement, which
might be absent if there is no cable!

Fixes #1759
This commit is contained in:
Jonathan Coates
2024-03-22 20:13:02 +00:00
parent c9caffb10f
commit cbafbca86b
@@ -94,10 +94,11 @@ public class CableBlockEntity extends BlockEntity {
@Deprecated @Deprecated
public void setBlockState(BlockState state) { public void setBlockState(BlockState state) {
var direction = getModemDirection(); var direction = getModemDirection();
var hasCable = hasCable();
super.setBlockState(state); super.setBlockState(state);
// We invalidate both the modem and element if the modem's direction is different. // We invalidate both the modem and element if the modem direction or cable are different.
if (getModemDirection() != direction && modemChanged != null) modemChanged.run(); if (modemChanged != null && (hasCable() != hasCable || getModemDirection() != direction)) modemChanged.run();
} }
@Nullable @Nullable