From 3c510736537ae197a0b5d9f84ac017c1f3f60325 Mon Sep 17 00:00:00 2001
From: taelnia <shotchkiss+github@gmail.com>
Date: Wed, 27 Nov 2013 00:29:55 -0500
Subject: [PATCH 1/3] Add call to onInventoryChanged to extraction pipes

---
 common/buildcraft/transport/pipes/PipeItemsWood.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java
index 4149a055..b338bcc6 100644
--- a/common/buildcraft/transport/pipes/PipeItemsWood.java
+++ b/common/buildcraft/transport/pipes/PipeItemsWood.java
@@ -129,6 +129,8 @@ public class PipeItemsWood extends Pipe<PipeTransportItems> implements IPowerRec
 			if (extracted == null)
 				return;
 
+			tile.onInventoryChanged();
+
 			for (ItemStack stack : extracted) {
 				if (stack == null || stack.stackSize == 0) {
 					powerHandler.useEnergy(1, 1, true);

From 8fb31972762e1fa7665fdf39e2586399c4f8a52b Mon Sep 17 00:00:00 2001
From: CovertJaguar <CovertJaguar@gmail.com>
Date: Thu, 28 Nov 2013 03:03:11 -0800
Subject: [PATCH 2/3] Allow placement of Facades over Plugs

---
 common/buildcraft/transport/BlockGenericPipe.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java
index 0e15e145..73a93723 100644
--- a/common/buildcraft/transport/BlockGenericPipe.java
+++ b/common/buildcraft/transport/BlockGenericPipe.java
@@ -786,7 +786,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
 					return true;
 			}
 		}
-		if (rayTraceResult != null && (rayTraceResult.hitPart == Part.Pipe || rayTraceResult.hitPart == Part.Gate)) {
+		if (rayTraceResult != null && (rayTraceResult.hitPart != Part.Facade)) {
 			if (addFacade(player, pipe, rayTraceResult.sideHit != null && rayTraceResult.sideHit != ForgeDirection.UNKNOWN ? rayTraceResult.sideHit : side))
 				return true;
 		}

From 17e7cb9a11b8b794d9278eb2157aa9a5dd6c8f70 Mon Sep 17 00:00:00 2001
From: ganymedes01 <foka_12@hotmail.com>
Date: Thu, 28 Nov 2013 00:47:47 +0000
Subject: [PATCH 3/3] Fix for Gates with ItemStacks with NBT data Closes #1344

---
 .../api/gates/TriggerParameter.java           | 10 ++-
 .../transport/gui/ContainerGateInterface.java | 85 +++++++++++--------
 2 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/common/buildcraft/api/gates/TriggerParameter.java b/common/buildcraft/api/gates/TriggerParameter.java
index 0127bc85..6295d1cd 100644
--- a/common/buildcraft/api/gates/TriggerParameter.java
+++ b/common/buildcraft/api/gates/TriggerParameter.java
@@ -47,8 +47,9 @@ public class TriggerParameter implements ITriggerParameter {
 	@Override
 	public void writeToNBT(NBTTagCompound compound) {
 		if (stack != null) {
-			compound.setInteger("itemID", stack.itemID);
-			compound.setInteger("itemDMG", stack.getItemDamage());
+			NBTTagCompound tagCompound = new NBTTagCompound();
+			stack.writeToNBT(tagCompound);
+			compound.setCompoundTag("stack", tagCompound);
 		}
 	}
 
@@ -59,11 +60,14 @@ public class TriggerParameter implements ITriggerParameter {
 	 */
 	@Override
 	public void readFromNBT(NBTTagCompound compound) {
+		// Legacy code to prevent existing gates from losing their contents
 		int itemID = compound.getInteger("itemID");
-
 		if (itemID != 0) {
 			stack = new ItemStack(itemID, 1, compound.getInteger("itemDMG"));
+			return;
 		}
+		
+		stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
 	}
 
 	@Override
diff --git a/common/buildcraft/transport/gui/ContainerGateInterface.java b/common/buildcraft/transport/gui/ContainerGateInterface.java
index f163e5c2..bbaf9580 100644
--- a/common/buildcraft/transport/gui/ContainerGateInterface.java
+++ b/common/buildcraft/transport/gui/ContainerGateInterface.java
@@ -18,21 +18,28 @@ import buildcraft.core.network.PacketCoordinates;
 import buildcraft.core.network.PacketIds;
 import buildcraft.core.network.PacketPayload;
 import buildcraft.core.network.PacketPayloadArrays;
+import buildcraft.core.network.PacketPayloadStream;
 import buildcraft.core.network.PacketUpdate;
 import buildcraft.core.proxy.CoreProxy;
 import buildcraft.core.utils.BCLog;
 import buildcraft.transport.Gate;
 import buildcraft.transport.Pipe;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.NavigableSet;
 import java.util.TreeSet;
+
 import net.minecraft.block.Block;
 import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.inventory.ICrafting;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.inventory.Slot;
 import net.minecraft.item.ItemStack;
+import net.minecraft.network.packet.Packet;
 import net.minecraft.tileentity.TileEntity;
 import net.minecraft.util.ResourceLocation;
 import net.minecraftforge.common.ForgeDirection;
@@ -159,45 +166,53 @@ public class ContainerGateInterface extends BuildCraftContainer {
 	 * @param packet
 	 */
 	public void setSelection(PacketUpdate packet, boolean notify) {
-		PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
-		int position = payload.intPayload[0];
-
-		setTrigger(position, ActionManager.triggers.get(payload.stringPayload[0]), notify);
-		setAction(position, ActionManager.actions.get(payload.stringPayload[1]), notify);
-
-		int itemID = payload.intPayload[1];
-		if (itemID <= 0) {
-			setTriggerParameter(position, null, notify);
-			return;
+		try {
+			PacketPayloadStream payload = (PacketPayloadStream) packet.payload;
+			DataInputStream data = payload.stream;
+			
+			int position = data.readInt();
+	
+			setTrigger(position, ActionManager.triggers.get(data.readUTF()), notify);
+			setAction(position, ActionManager.actions.get(data.readUTF()), notify);
+	
+			ItemStack parameter = Packet.readItemStack(data);
+			if(parameter != null) {
+				ITriggerParameter param = new TriggerParameter();
+				param.set(parameter);
+				setTriggerParameter(position, param, notify);
+			} else {
+				setTriggerParameter(position, null, notify);
+			}
+		} catch(IOException e) {
+			e.printStackTrace();
 		}
-
-		ITriggerParameter param = new TriggerParameter();
-		param.set(new ItemStack(itemID, payload.intPayload[2], payload.intPayload[3]));
-		setTriggerParameter(position, param, notify);
 	}
+	
+	private PacketPayload getSelectionPayload(final int position) {
+		PacketPayloadStream payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
+			@Override
+			public void writeData(DataOutputStream data) throws IOException {
+				data.writeInt(position);
+				
+				if (pipe.gate.triggers[position] != null) {
+					data.writeUTF(pipe.gate.triggers[position].getUniqueTag());
+				} else {
+					data.writeUTF("");
+				}
 
-	private PacketPayload getSelectionPayload(int position) {
-		PacketPayloadArrays payload = new PacketPayloadArrays(4, 0, 2);
+				if (pipe.gate.actions[position] != null) {
+					data.writeUTF(pipe.gate.actions[position].getUniqueTag());
+				} else {
+					data.writeUTF("");
+				}
 
-		payload.intPayload[0] = position;
-
-		if (pipe.gate.triggers[position] != null) {
-			payload.stringPayload[0] = pipe.gate.triggers[position].getUniqueTag();
-		} else {
-			payload.stringPayload[0] = "";
-		}
-
-		if (pipe.gate.actions[position] != null) {
-			payload.stringPayload[1] = pipe.gate.actions[position].getUniqueTag();
-		} else {
-			payload.stringPayload[1] = "";
-		}
-
-		if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
-			payload.intPayload[1] = pipe.gate.triggerParameters[position].getItemStack().itemID;
-			payload.intPayload[2] = pipe.gate.triggerParameters[position].getItemStack().stackSize;
-			payload.intPayload[3] = pipe.gate.triggerParameters[position].getItemStack().getItemDamage();
-		}
+				if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
+					Packet.writeItemStack(pipe.gate.triggerParameters[position].getItemStack().copy(), data);
+				} else {
+					Packet.writeItemStack(null, data);
+				}
+			}
+		});
 
 		return payload;
 	}