Refresh relay input/output on load

We now forcibly update all redstone inputs/outputs when the relay is
first placed.

It's not entirely clear to me if this is the right solution. The
alternative one would be to persist the redstone state instead. However,
most peripherals do *not* do this (e.g. monitor, speaker), so let's
match that for now.

Fixes #2175.
This commit is contained in:
Jonathan Coates committed 2025-12-15 14:47:27 +00:00
1 parent 6702ab8f9d
commit 013f2e500f
1 file changed
+6 -4
@@ -22,6 +22,7 @@ public final class RedstoneRelayBlockEntity extends BlockEntity {
private final RedstoneState redstoneState = new RedstoneState(() -> TickScheduler.schedule(tickToken));
private final RedstoneRelayPeripheral peripheral = new RedstoneRelayPeripheral(redstoneState);
private boolean updateAll = false;
public RedstoneRelayBlockEntity(BlockPos pos, BlockState blockState) {
super(ModRegistry.BlockEntities.REDSTONE_RELAY.get(), pos, blockState);
@@ -30,17 +31,18 @@ public final class RedstoneRelayBlockEntity extends BlockEntity {
@Override
public void clearRemoved() {
super.clearRemoved();
updateAll = true;
TickScheduler.schedule(tickToken);
}
void update() {
var changes = redstoneState.updateOutput();
if (changes != 0) {
for (var direction : DirectionUtil.FACINGS) {
if ((changes & (1 << mapSide(direction).ordinal())) != 0) updateRedstoneTo(direction);
}
for (var direction : DirectionUtil.FACINGS) {
if (updateAll || (changes & (1 << mapSide(direction).ordinal())) != 0) updateRedstoneTo(direction);
}
updateAll = false;
if (redstoneState.pollInputChanged()) peripheral.queueRedstoneEvent();
}