From cbafbca86bf4513319f2e52bb4ea4ed963decca2 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Fri, 22 Mar 2024 20:06:53 +0000 Subject: [PATCH] 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 --- .../shared/peripheral/modem/wired/CableBlockEntity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java index ea67bbf29..e52f1b299 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java @@ -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