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:06:53 +00:00
parent c9caffb10f
commit cbafbca86b
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
1 changed files with 3 additions and 2 deletions

View File

@ -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