Update Redstone in onNeighborChange

We removed onNeighborChange in 676fb5fb53,
on the basis that this was no longer needed for peripheral updates.
However, it *is* required for redstone updates, as MoreRed does not
trigger any block updates for bundled cables.

Fixes #2316.
This commit is contained in:
Jonathan Coates
2025-12-18 15:06:01 +00:00
parent f820cd8b43
commit 419d823d3b
3 changed files with 38 additions and 0 deletions
@@ -4,6 +4,7 @@
package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.annotations.ForgeOverride;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
import dan200.computercraft.shared.computer.items.IComputerItem;
@@ -24,6 +25,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
@@ -168,6 +170,12 @@ public abstract class AbstractComputerBlock<T extends AbstractComputerBlockEntit
return super.use(state, level, pos, player, hand, hit);
}
@ForgeOverride
public final void onNeighborChange(BlockState state, LevelReader world, BlockPos pos, BlockPos neighbour) {
var be = world.getBlockEntity(pos);
if (be instanceof AbstractComputerBlockEntity computer) computer.neighborBlockEntityChanged(neighbour);
}
@Override
@Deprecated
public final void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean isMoving) {
@@ -273,6 +273,27 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
invalidSides = DirectionUtil.ALL_SIDES; // Mark all peripherals as dirty.
}
/**
* Called when a neighbour block entity changes.
* <p>
* This is only required for MoreRed, which does not fire block updates when bundled redstone changes, see
* <a href="https://github.com/cc-tweaked/CC-Tweaked/issues/2316">#2316</a>
*
* @param neighbour The position of the neighbour block.
*/
public void neighborBlockEntityChanged(BlockPos neighbour) {
var computer = getServerComputer();
if (computer == null) return;
for (var dir : DirectionUtil.FACINGS) {
var offset = getBlockPos().relative(dir);
if (offset.equals(neighbour)) {
updateRedstoneInput(computer, dir, offset);
return;
}
}
}
/**
* Called when a neighbour block's shape changes.
* <p>
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
package dan200.computercraft.shared.peripheral.redstone;
import dan200.computercraft.annotations.ForgeOverride;
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
@@ -11,6 +12,7 @@ import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
@@ -70,6 +72,13 @@ public final class RedstoneRelayBlock extends HorizontalDirectionalBlock impleme
return level.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay ? relay.getBundledRedstoneOutput(side) : 0;
}
@ForgeOverride
public void onNeighborChange(BlockState state, LevelReader world, BlockPos pos, BlockPos neighbour) {
// This is only required for MoreRed, which does not fire block updates when bundled redstone changes, see
// <a href="https://github.com/cc-tweaked/CC-Tweaked/issues/2316">#2316</a>.
if (world.getBlockEntity(pos) instanceof RedstoneRelayBlockEntity relay) relay.neighborChanged(neighbour);
}
@Override
@Deprecated
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean isMoving) {