From 4a9eb69b912ab749ecce39ef391f329badc3c81d Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 15 Oct 2013 16:38:30 -0700 Subject: [PATCH] Attempt to make pickBlock supports Gate/Plugs Whether a Gate is an Autoarchic Gate or not is not sync to the client unfortunately. --- .../buildcraft/transport/BlockGenericPipe.java | 17 +++++++++++++++++ common/buildcraft/transport/Gate.java | 6 +++++- common/buildcraft/transport/GateVanilla.java | 4 ++-- common/buildcraft/transport/ItemFacade.java | 10 +++++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 3fba366e..d33b9e4e 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -576,6 +576,23 @@ public class BlockGenericPipe extends BlockContainer { return pipe.itemID; } + @SideOnly(Side.CLIENT) + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + RaytraceResult rayTraceResult = doRayTrace(world, x, y, z, Minecraft.getMinecraft().thePlayer); + + if (rayTraceResult != null && rayTraceResult.boundingBox != null) { + switch (rayTraceResult.hitPart) { + case Gate: + Pipe pipe = getPipe(world, x, y, z); + return pipe.gate.getGateItem(); + case Plug: + return new ItemStack(BuildCraftTransport.plugItem); + } + } + return super.getPickBlock(target, world, x, y, z); + } + /* Wrappers ************************************************************ */ @Override public void onNeighborBlockChange(World world, int x, int y, int z, int id) { diff --git a/common/buildcraft/transport/Gate.java b/common/buildcraft/transport/Gate.java index e5453285..2c356c31 100644 --- a/common/buildcraft/transport/Gate.java +++ b/common/buildcraft/transport/Gate.java @@ -153,7 +153,11 @@ public abstract class Gate { // / UPDATING public abstract void update(); - public abstract void dropGate(); + public abstract ItemStack getGateItem(); + + public void dropGate() { + pipe.dropItem(getGateItem()); + } public void resetGate() { if (broadcastRedstone) { diff --git a/common/buildcraft/transport/GateVanilla.java b/common/buildcraft/transport/GateVanilla.java index 8d0726e3..16958cf5 100644 --- a/common/buildcraft/transport/GateVanilla.java +++ b/common/buildcraft/transport/GateVanilla.java @@ -140,7 +140,7 @@ public class GateVanilla extends Gate { * @param k */ @Override - public void dropGate() { + public ItemStack getGateItem() { int gateDamage; switch (kind) { @@ -175,7 +175,7 @@ public class GateVanilla extends Gate { gateItem = BuildCraftTransport.pipeGate; } - pipe.dropItem(new ItemStack(gateItem, 1, gateDamage)); + return new ItemStack(gateItem, 1, gateDamage); } diff --git a/common/buildcraft/transport/ItemFacade.java b/common/buildcraft/transport/ItemFacade.java index d520c6bc..f76c96e3 100644 --- a/common/buildcraft/transport/ItemFacade.java +++ b/common/buildcraft/transport/ItemFacade.java @@ -216,13 +216,13 @@ public class ItemFacade extends ItemBuildCraft { Block bl = Block.blocksList[blockId]; // No Meta if (bl != null && bl.getRenderType() == 31 && (blockMeta & 0xC) == 0) - return getStack(blockId, (blockMeta & 0x3) | 4); + return getStack(bl, (blockMeta & 0x3) | 4); // Meta | 4 = true if (bl != null && bl.getRenderType() == 31 && (blockMeta & 0x8) == 0) - return getStack(blockId, (blockMeta & 0x3) | 8); + return getStack(bl, (blockMeta & 0x3) | 8); // Meta | 8 = true if (bl != null && bl.getRenderType() == 31 && (blockMeta & 0x4) == 0) - return getStack(blockId, (blockMeta & 0x3)); + return getStack(bl, (blockMeta & 0x3)); } return null; } @@ -250,6 +250,10 @@ public class ItemFacade extends ItemBuildCraft { return 0; } + public static ItemStack getStack(Block block, int metadata) { + return getStack(block.blockID, metadata); + } + public static ItemStack getStack(int blockID, int metadata) { ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0); NBTTagCompound nbt = new NBTTagCompound("tag");