From bd274f64b801f4f725acf97e121e11f103c73e37 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sun, 22 Jan 2017 23:01:12 -1000 Subject: [PATCH] Fix redstone behavior for covers Tested with Machine Controller and Energy Detector, should work for the rest too. --- .../api/interfaces/tileentity/IRedstoneEmitter.java | 6 ++++++ .../api/metatileentity/BaseMetaPipeEntity.java | 10 ++++++++-- .../api/metatileentity/BaseMetaTileEntity.java | 10 ++++++++-- .../gregtech/common/blocks/GT_Block_Machines.java | 12 +++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java index 5be185b4..97a2a12b 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java @@ -34,4 +34,10 @@ public interface IRedstoneEmitter extends IHasWorldObjectAndCoords { * Gets the Output for the comparator on the given Side */ byte getComparatorValue(byte aSide); + + /** + * Return whether the TileEntity can output redstone to the given side. Used to visually connect + * vanilla redstone wires. + */ + boolean canOutputRedstone(byte aSide); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index e12826e2..f43bd60f 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -293,7 +293,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } if (mNeedsBlockUpdate) { - worldObj.notifyBlockOfStateChange(getPos(), getBlockType()); + worldObj.notifyNeighborsOfStateChange(getPos(), getBlockType()); mNeedsBlockUpdate = false; } } @@ -494,6 +494,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE return getInternalInputRedstoneSignal(aSide) > 0; } + @Override + public boolean canOutputRedstone(byte aSide) { + return (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) + || getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)); + } + public ITexture getCoverTexture(byte aSide) { return GregTech_API.sCovers.get(getCoverIDAtSide(aSide)); } @@ -1017,7 +1023,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInputRedstoneSignal(byte aSide) { - return (byte) (worldObj.getRedstonePower(getPos(), EnumFacing.VALUES[aSide]) & 15); + return (byte) (worldObj.getRedstonePower(getPos().offset(EnumFacing.VALUES[aSide]), EnumFacing.VALUES[aSide]) & 15); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index ba85b835..87eb8191 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -557,7 +557,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } if (mNeedsBlockUpdate) { - worldObj.notifyBlockOfStateChange(getPos(), getBlockOffset(0, 0, 0)); + worldObj.notifyNeighborsOfStateChange(getPos(), getBlockOffset(0, 0, 0)); mNeedsBlockUpdate = false; } } @@ -734,6 +734,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return getInternalInputRedstoneSignal(aSide) > 0; } + @Override + public boolean canOutputRedstone(byte aSide) { + return (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) + || getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)); + } + public ITexture getCoverTexture(byte aSide) { return GregTech_API.sCovers.get(getCoverIDAtSide(aSide)); } @@ -1437,7 +1443,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInputRedstoneSignal(byte aSide) { - return (byte) (worldObj.getRedstonePower(getPos(), EnumFacing.VALUES[aSide]) & 15); + return (byte) (worldObj.getRedstonePower(getPos().offset(EnumFacing.VALUES[aSide]), EnumFacing.VALUES[aSide]) & 15); } @Override diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java index 09ead87a..6eeed06f 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java @@ -137,9 +137,15 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo return false; } + /** + * NB: Vanilla redstone behavior is that wires will connect to redstone emitters but not consumers. + * Thus we only say we can connect if we are an emitter. (This is usually delegated to a cover behavior.) + * + */ @Override public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { - return true; + IGregTechTileEntity gregTechTileEntity = getGregTile(world, pos); + return gregTechTileEntity != null && gregTechTileEntity.canOutputRedstone((byte) side.getOpposite().getIndex()); } @Override @@ -356,7 +362,7 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { IGregTechTileEntity gregTechTileEntity = getGregTile(blockAccess, pos); if(gregTechTileEntity != null) { - gregTechTileEntity.getOutputRedstoneSignal((byte) side.getIndex()); + return gregTechTileEntity.getOutputRedstoneSignal((byte) side.getOpposite().getIndex()); } return 0; } @@ -365,7 +371,7 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { IGregTechTileEntity gregTechTileEntity = getGregTile(blockAccess, pos); if(gregTechTileEntity != null) { - gregTechTileEntity.getStrongOutputRedstoneSignal((byte) side.getIndex()); + return gregTechTileEntity.getStrongOutputRedstoneSignal((byte) side.getOpposite().getIndex()); } return 0; }