1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-13 03:30:29 +00:00

Merge pull request #182 from SquidDev-CC/hotfix/redstone-checks

Redstone behaviour tweaks
This commit is contained in:
SquidDev 2019-04-24 09:45:28 +01:00 committed by GitHub
commit b867ada5e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 23 deletions

View File

@ -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;
@ -124,16 +128,14 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override
public boolean getRedstoneConnectivity( EnumFacing side )
{
if( side == null ) return false;
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side.getOpposite() ) );
return !isRedstoneBlockedOnSide( localDir );
return true;
}
@Override
public int getRedstoneOutput( EnumFacing side )
{
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
if( !isRedstoneBlockedOnSide( localDir ) && world != null && !world.isRemote )
if( world != null && !world.isRemote )
{
ServerComputer computer = getServerComputer();
if( computer != null ) return computer.getRedstoneOutput( localDir );
@ -144,15 +146,14 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override
public boolean getBundledRedstoneConnectivity( @Nonnull EnumFacing side )
{
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
return !isRedstoneBlockedOnSide( localDir );
return true;
}
@Override
public int getBundledRedstoneOutput( @Nonnull EnumFacing side )
{
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
if( !isRedstoneBlockedOnSide( localDir ) && !world.isRemote )
if( !world.isRemote )
{
ServerComputer computer = getServerComputer();
if( computer != null ) return computer.getBundledRedstoneOutput( localDir );
@ -259,11 +260,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
return false;
}
protected boolean isRedstoneBlockedOnSide( ComputerSide localSide )
{
return false;
}
protected ComputerSide remapLocalSide( ComputerSide localSide )
{
return localSide;
@ -273,17 +269,36 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{
EnumFacing offsetSide = dir.getOpposite();
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
if( !isRedstoneBlockedOnSide( localDir ) )
{
computer.setRedstoneInput( localDir, getWorld().getRedstonePower( offset, dir ) );
computer.setBundledRedstoneInput( localDir, BundledRedstone.getOutput( getWorld(), offset, offsetSide ) );
}
computer.setRedstoneInput( localDir, getRedstoneInput( world, offset, dir ) );
computer.setBundledRedstoneInput( localDir, BundledRedstone.getOutput( getWorld(), offset, offsetSide ) );
if( !isPeripheralBlockedOnSide( localDir ) )
{
computer.setPeripheral( localDir, Peripherals.getPeripheral( getWorld(), offset, offsetSide ) );
}
}
/**
* 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;

View File

@ -317,12 +317,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
return hasPeripheralUpgradeOnSide( localSide );
}
@Override
protected boolean isRedstoneBlockedOnSide( ComputerSide localSide )
{
return false;
}
// IDirectionalTile
@Override