1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2026-01-07 04:39:04 +00:00

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
2025-12-15 14:44:30 +00:00
parent 6702ab8f9d
commit 013f2e500f

View File

@@ -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();
}