From c5168ff04753c68aa0115476c2c6e18b084bb404 Mon Sep 17 00:00:00 2001 From: Chicken Bones Date: Thu, 1 Aug 2013 23:30:26 +1000 Subject: [PATCH] Fixed torch part placement on fences --- .../multipart/minecraft/EventHandler.java | 13 +++++++++- .../multipart/minecraft/McSidedMetaPart.java | 9 +++++-- .../multipart/minecraft/TorchPart.java | 25 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/codechicken/multipart/minecraft/EventHandler.java b/codechicken/multipart/minecraft/EventHandler.java index 55f0b26..836003b 100644 --- a/codechicken/multipart/minecraft/EventHandler.java +++ b/codechicken/multipart/minecraft/EventHandler.java @@ -6,6 +6,7 @@ import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.Vector3; import codechicken.multipart.TileMultipart; import net.minecraft.block.Block; +import net.minecraft.block.BlockFence; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.network.packet.Packet15Place; @@ -62,7 +63,7 @@ public class EventHandler { Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ); Block block = Block.blocksList[world.getBlockId(hit.blockX, hit.blockY, hit.blockZ)]; - if(block != null && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z)) + if(block != null && !ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float)f.x, (float)f.y, (float)f.z)) { player.swingItem(); PacketCustom.sendToServer(new Packet15Place( @@ -101,4 +102,14 @@ public class EventHandler } return true; } + + /** + * Because vanilla is weird. + */ + private static boolean ignoreActivate(Block block) + { + if(block instanceof BlockFence) + return true; + return false; + } } diff --git a/codechicken/multipart/minecraft/McSidedMetaPart.java b/codechicken/multipart/minecraft/McSidedMetaPart.java index 185fa2f..f2b4bac 100644 --- a/codechicken/multipart/minecraft/McSidedMetaPart.java +++ b/codechicken/multipart/minecraft/McSidedMetaPart.java @@ -26,10 +26,15 @@ public abstract class McSidedMetaPart extends McMetaPart dropIfCantStay(); } - public boolean dropIfCantStay() + public boolean canStay() { BlockCoord pos = new BlockCoord(getTile()).offset(sideForMeta(meta)); - if(!world().isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1))) + return world().isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1)); + } + + public boolean dropIfCantStay() + { + if(!canStay()) { drop(); return true; diff --git a/codechicken/multipart/minecraft/TorchPart.java b/codechicken/multipart/minecraft/TorchPart.java index facff82..ea8822b 100644 --- a/codechicken/multipart/minecraft/TorchPart.java +++ b/codechicken/multipart/minecraft/TorchPart.java @@ -65,13 +65,36 @@ public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick return metaSideMap[meta]; } + @Override + public boolean canStay() + { + if(sideForMeta(meta) == 0) + { + Block block = Block.blocksList[world().getBlockId(x(), y()-1, z())]; + if(block != null && block.canPlaceTorchOnTop(world(), x(), y()-1, z())) + return true; + } + return super.canStay(); + } + public static McBlockPart placement(World world, BlockCoord pos, int side) { if(side == 0) return null; pos = pos.copy().offset(side^1); if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side))) - return null; + { + if(side == 1) + { + Block block = Block.blocksList[world.getBlockId(pos.x, pos.y, pos.z)]; + if(block == null || !block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z)) + return null; + } + else + { + return null; + } + } return new TorchPart(sideMetaMap[side^1]); }