From 7071cc972bb504441dfb583abd1bc1f827f66ea1 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 22 Apr 2019 11:52:01 +0100 Subject: [PATCH] Make redstone behaviour consistent with repeaters This uses the same behaviour that repeaters and comparators do for determining their input, meaning that redstone directly connected to the computer is read (as you would expect). It's worth noting that this is a shift from previous behaviour. Therefore, it runs the (small) risk of breaking existing builds. However, I believe it is more consistent with the expected behaviour. --- .../computer/blocks/TileComputerBase.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index f9d7ae66e..c6f796ee4 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -22,7 +22,10 @@ import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.RedstoneUtil; import joptsimple.internal.Strings; import net.minecraft.block.Block; +import net.minecraft.block.BlockRedstoneWire; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -34,6 +37,7 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.IWorldNameable; +import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -266,7 +270,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT EnumFacing offsetSide = dir.getOpposite(); ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) ); - computer.setRedstoneInput( localDir, getWorld().getRedstonePower( offset, dir ) ); + computer.setRedstoneInput( localDir, getRedstoneInput( world, offset, dir ) ); computer.setBundledRedstoneInput( localDir, BundledRedstone.getOutput( getWorld(), offset, offsetSide ) ); if( !isPeripheralBlockedOnSide( localDir ) ) @@ -275,6 +279,26 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT } } + /** + * Gets the redstone input for an adjacent block + * + * @param world The world we exist in + * @param pos The position of the neighbour + * @param side The side we are reading from + * @return The effective redstone power + * @see net.minecraft.block.BlockRedstoneDiode#calculateInputStrength(World, BlockPos, IBlockState) + */ + protected static int getRedstoneInput( World world, BlockPos pos, EnumFacing side ) + { + int power = world.getRedstonePower( pos, side ); + if( power >= 15 ) return power; + + IBlockState neighbour = world.getBlockState( pos ); + return neighbour.getBlock() == Blocks.REDSTONE_WIRE + ? Math.max( power, neighbour.getValue( BlockRedstoneWire.POWER ) ) + : power; + } + public void updateInput() { if( getWorld() == null || getWorld().isRemote ) return;