From 01f5d006fc7857feccfac9b812f09cdcb1b0d113 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 18 Sep 2017 08:20:54 +0100 Subject: [PATCH] Fix BlockFaceShape not being overridden for turtles and peripherals This meant one could perform various illogical actions to non-full-blocks, such as connecting fences and placing paitings. We also modify the behaviour of isOpaqueCube and isFullCube for peripherals, only returning false for the case of modems and cables. --- .../shared/peripheral/common/BlockCable.java | 23 ++++++++++++++++ .../peripheral/common/BlockPeripheral.java | 26 +++++++++++++++++++ .../common/BlockPeripheralBase.java | 14 ---------- .../peripheral/modem/BlockAdvancedModem.java | 25 +++++++++++++++++- .../shared/turtle/blocks/BlockTurtle.java | 9 +++++++ 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java index 36c400b3d..2fb4abb35 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java @@ -12,6 +12,7 @@ import dan200.computercraft.shared.peripheral.modem.TileCable; import net.minecraft.block.Block; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; @@ -251,4 +252,26 @@ public class BlockCable extends BlockPeripheralBase { return new TileCable(); } + + @Override + @Deprecated + public final boolean isOpaqueCube( IBlockState state ) + { + return false; + } + + @Override + @Deprecated + public final boolean isFullCube( IBlockState state ) + { + return false; + } + + @Nonnull + @Override + @Deprecated + public BlockFaceShape getBlockFaceShape( IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing side ) + { + return BlockFaceShape.UNDEFINED; + } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java index 828ca21a2..34ff51ee5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java @@ -16,6 +16,7 @@ import dan200.computercraft.shared.peripheral.speaker.TileSpeaker; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -612,4 +613,29 @@ public class BlockPeripheral extends BlockPeripheralBase } } } + + @Override + @Deprecated + public final boolean isOpaqueCube( IBlockState state ) + { + PeripheralType type = getPeripheralType( state ); + return type == PeripheralType.DiskDrive || type == PeripheralType.Printer + || type == PeripheralType.Monitor || type == PeripheralType.AdvancedMonitor + || type == PeripheralType.Speaker; + } + + @Override + @Deprecated + public final boolean isFullCube( IBlockState state ) + { + return isOpaqueCube( state ); + } + + @Nonnull + @Override + @Deprecated + public BlockFaceShape getBlockFaceShape( IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing side ) + { + return isOpaqueCube( state ) ? BlockFaceShape.SOLID : BlockFaceShape.UNDEFINED; + } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java index 39aa5089c..564a8f1b0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java @@ -31,20 +31,6 @@ public abstract class BlockPeripheralBase extends BlockDirectional protected abstract PeripheralType getPeripheralType( IBlockState state ); protected abstract TilePeripheralBase createTile( PeripheralType type ); - @Override - @Deprecated - public final boolean isOpaqueCube( IBlockState state ) - { - return false; - } - - @Override - @Deprecated - public final boolean isFullCube( IBlockState state ) - { - return false; - } - @Override public final boolean canPlaceBlockOnSide( @Nonnull World world, @Nonnull BlockPos pos, EnumFacing side ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java index 100caf7e1..af8d1a3ef 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java @@ -12,11 +12,12 @@ import dan200.computercraft.shared.peripheral.common.BlockPeripheralBase; import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import javax.annotation.Nonnull; @@ -114,4 +115,26 @@ public class BlockAdvancedModem extends BlockPeripheralBase { return new TileAdvancedModem(); } + + @Override + @Deprecated + public final boolean isOpaqueCube( IBlockState state ) + { + return false; + } + + @Override + @Deprecated + public final boolean isFullCube( IBlockState state ) + { + return false; + } + + @Nonnull + @Override + @Deprecated + public BlockFaceShape getBlockFaceShape( IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing side ) + { + return BlockFaceShape.UNDEFINED; + } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java index 924b88be6..32c2eeb46 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java @@ -13,6 +13,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyDirection; +import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -75,6 +76,14 @@ public class BlockTurtle extends BlockComputerBase return false; } + @Nonnull + @Override + @Deprecated + public BlockFaceShape getBlockFaceShape( IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing side ) + { + return BlockFaceShape.UNDEFINED; + } + @Nonnull @Override protected BlockStateContainer createBlockState()