diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java index 7f7f1a65..835abf4d 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java @@ -15,7 +15,6 @@ import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -194,10 +193,8 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { @Deprecated @Override public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (worldIn.isRemote) { - if (!getCanInteract(blockState, Minecraft.getMinecraft().player)) { - return null; - } + if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { + return null; } return super.collisionRayTrace(blockState, worldIn, pos, start, end); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java index b0a9a320..8c9abe53 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java @@ -22,6 +22,8 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -146,6 +148,15 @@ public class BlockCloudAnvil extends BlockAnvil implements ICloudBlock { } } + @Deprecated + @Override + public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { + if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { + return null; + } + return super.collisionRayTrace(blockState, worldIn, pos, start, end); + } + @Deprecated @Override public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFarm.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFarm.java index 0d16e39a..68675fc9 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFarm.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFarm.java @@ -9,7 +9,6 @@ import com.minelittlepony.unicopia.UBlocks; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.BlockRenderLayer; @@ -105,10 +104,8 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock { @Deprecated @Override public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (worldIn.isRemote) { - if (!getCanInteract(blockState, Minecraft.getMinecraft().player)) { - return null; - } + if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { + return null; } return super.collisionRayTrace(blockState, worldIn, pos, start, end); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java index 1f217c81..3e465050 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java @@ -16,7 +16,6 @@ import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -113,10 +112,8 @@ public class BlockCloudSlab extends BlockSlab implements ICloudBlock { @Deprecated @Override public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (worldIn.isRemote) { - if (!getCanInteract(blockState, Minecraft.getMinecraft().player)) { - return null; - } + if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { + return null; } return super.collisionRayTrace(blockState, worldIn, pos, start, end); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java index 003d469f..27cb54cd 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java @@ -12,7 +12,6 @@ import net.minecraft.block.BlockSlab.EnumBlockHalf; import net.minecraft.block.BlockStairs; import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumFacing; @@ -108,10 +107,8 @@ public class BlockCloudStairs extends BlockStairs implements ICloudBlock { @Deprecated @Override public RayTraceResult collisionRayTrace(IBlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (worldIn.isRemote) { - if (!getCanInteract(blockState, Minecraft.getMinecraft().player)) { - return null; - } + if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { + return null; } return super.collisionRayTrace(blockState, worldIn, pos, start, end); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java index bc5ced64..843d3a81 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java @@ -4,15 +4,55 @@ import com.minelittlepony.unicopia.CloudType; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockTorch; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; public interface ICloudBlock { CloudType getCloudMaterialType(IBlockState blockState); + default boolean handleRayTraceSpecialCases(World world, BlockPos pos, IBlockState state) { + if (world.isRemote) { + EntityPlayer player = Minecraft.getMinecraft().player; + + if (!getCanInteract(state, player)) { + return true; + } + + ItemStack main = player.getHeldItemMainhand(); + if (main.isEmpty()) { + main = player.getHeldItemOffhand(); + } + + if (!main.isEmpty() && main.getItem() instanceof ItemBlock) { + Block block = ((ItemBlock)main.getItem()).getBlock(); + + if (block == null) { + return false; + } + + if (block instanceof BlockTorch && getCloudMaterialType(state) != CloudType.NORMAL) { + return false; + } + + if (block != Blocks.AIR && !(block instanceof ICloudBlock)) { + return true; + } + } + } + + return false; + } + default boolean getCanInteract(IBlockState state, Entity e) { return getCloudMaterialType(state).canInteract(e); }