1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-06 01:56:21 +00:00

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

View File

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