From 7a941c12793b8e308bab4fa13eed17e6f43bc0ff Mon Sep 17 00:00:00 2001
From: simon816 <simonbarnes1@googlemail.com>
Date: Tue, 8 Jul 2014 22:38:24 +0100
Subject: [PATCH] Add support for injecting colored items in pipes

---
 .../utils => api/buildcraft/api/core}/EnumColor.java   |  9 ++++++---
 api/buildcraft/api/transport/IPipeTile.java            | 10 +++++++++-
 common/buildcraft/BuildCraftTransport.java             |  2 +-
 common/buildcraft/transport/TileGenericPipe.java       |  9 ++++++++-
 common/buildcraft/transport/TravelingItem.java         |  2 +-
 .../buildcraft/transport/gui/ContainerEmzuliPipe.java  |  2 +-
 .../transport/network/PacketPipeTransportTraveler.java |  3 +--
 .../buildcraft/transport/pipes/PipeItemsDaizuli.java   |  2 +-
 common/buildcraft/transport/pipes/PipeItemsEmzuli.java |  2 +-
 common/buildcraft/transport/pipes/PipeItemsLapis.java  |  2 +-
 .../buildcraft/transport/render/PipeRendererTESR.java  |  2 +-
 .../transport/triggers/ActionExtractionPreset.java     |  3 +--
 .../buildcraft/transport/triggers/ActionPipeColor.java |  3 +--
 13 files changed, 33 insertions(+), 18 deletions(-)
 rename {common/buildcraft/core/utils => api/buildcraft/api/core}/EnumColor.java (94%)

diff --git a/common/buildcraft/core/utils/EnumColor.java b/api/buildcraft/api/core/EnumColor.java
similarity index 94%
rename from common/buildcraft/core/utils/EnumColor.java
rename to api/buildcraft/api/core/EnumColor.java
index 00c85227..4e3332d5 100644
--- a/common/buildcraft/core/utils/EnumColor.java
+++ b/api/buildcraft/api/core/EnumColor.java
@@ -6,9 +6,12 @@
  * License 1.0, or MMPL. Please check the contents of the license located in
  * http://www.mod-buildcraft.com/MMPL-1.0.txt
  */
-package buildcraft.core.utils;
+package buildcraft.api.core;
 
 import java.util.Locale;
+import java.util.Random;
+
+import net.minecraft.util.StatCollector;
 
 public enum EnumColor {
 
@@ -132,7 +135,7 @@ public enum EnumColor {
 	}
 
 	public static EnumColor getRand() {
-		return VALUES[Utils.RANDOM.nextInt(VALUES.length)];
+		return VALUES[new Random().nextInt(VALUES.length)];
 	}
 
 	public EnumColor getNext() {
@@ -162,7 +165,7 @@ public enum EnumColor {
 	}
 
 	public String getLocalizedName() {
-		return StringUtils.localize(getTag());
+		return StatCollector.translateToLocal(getTag());
 	}
 
 	public String getDye() {
diff --git a/api/buildcraft/api/transport/IPipeTile.java b/api/buildcraft/api/transport/IPipeTile.java
index 94516c8f..fbb1021b 100644
--- a/api/buildcraft/api/transport/IPipeTile.java
+++ b/api/buildcraft/api/transport/IPipeTile.java
@@ -9,8 +9,8 @@
 package buildcraft.api.transport;
 
 import net.minecraft.item.ItemStack;
-
 import net.minecraftforge.common.util.ForgeDirection;
+import buildcraft.api.core.EnumColor;
 
 public interface IPipeTile {
 
@@ -29,8 +29,16 @@ public interface IPipeTile {
 	 * @param doAdd If false no actual addition should take place. Implementors
 	 * should simulate.
 	 * @param from Orientation the ItemStack is offered from.
+	 * @param color The color of the item to be added to the pipe, or null for no color.
 	 * @return Amount of items used from the passed stack.
 	 */
+	int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from, EnumColor color);
+
+	/**
+	 * Same as
+	 * {@link #injectItem(ItemStack, boolean, ForgeDirection, EnumColor)}
+	 * but with no color attribute.
+	 */
 	int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
 
 	/**
diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java
index 5423cb17..05fbdf78 100644
--- a/common/buildcraft/BuildCraftTransport.java
+++ b/common/buildcraft/BuildCraftTransport.java
@@ -33,6 +33,7 @@ import net.minecraftforge.common.util.ForgeDirection;
 import net.minecraftforge.oredict.RecipeSorter;
 
 import buildcraft.api.blueprints.SchematicRegistry;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.core.IIconProvider;
 import buildcraft.api.core.JavaTools;
 import buildcraft.api.gates.GateExpansions;
@@ -51,7 +52,6 @@ import buildcraft.core.Version;
 import buildcraft.core.network.BuildCraftChannelHandler;
 import buildcraft.core.proxy.CoreProxy;
 import buildcraft.core.triggers.ActionPipeClose;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.transport.BlockFilteredBuffer;
 import buildcraft.transport.BlockGenericPipe;
 import buildcraft.transport.GuiHandler;
diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java
index 1bcca4a3..e20e6ad3 100755
--- a/common/buildcraft/transport/TileGenericPipe.java
+++ b/common/buildcraft/transport/TileGenericPipe.java
@@ -37,6 +37,7 @@ import net.minecraftforge.fluids.IFluidHandler;
 import buildcraft.BuildCraftCore;
 import buildcraft.BuildCraftTransport;
 import buildcraft.api.core.BCLog;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.core.IIconProvider;
 import buildcraft.api.core.Position;
 import buildcraft.api.gates.IGateExpansion;
@@ -579,7 +580,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
 
 	/* IPIPEENTRY */
 	@Override
-	public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
+	public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from, EnumColor color) {
 		if (pipe.isClosed()) {
 			return 0;
 		}
@@ -590,6 +591,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
 				itemPos.moveBackwards(0.4);
 
 				TravelingItem pipedItem = TravelingItem.make(itemPos.x, itemPos.y, itemPos.z, payload);
+				pipedItem.color = color;
 				((PipeTransportItems) pipe.transport).injectItem(pipedItem, itemPos.orientation);
 			}
 			return payload.stackSize;
@@ -598,6 +600,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
 		return 0;
 	}
 
+	@Override
+	public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
+		return injectItem(payload, doAdd, from, null);
+	}
+
 	@Override
 	public PipeType getPipeType() {
 		if (BlockGenericPipe.isValid(pipe)) {
diff --git a/common/buildcraft/transport/TravelingItem.java b/common/buildcraft/transport/TravelingItem.java
index 92ba360f..c87e6de4 100644
--- a/common/buildcraft/transport/TravelingItem.java
+++ b/common/buildcraft/transport/TravelingItem.java
@@ -26,9 +26,9 @@ import cpw.mods.fml.relauncher.Side;
 import net.minecraftforge.common.util.ForgeDirection;
 
 import buildcraft.BuildCraftCore;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.core.Position;
 import buildcraft.core.inventory.StackHelper;
-import buildcraft.core.utils.EnumColor;
 
 public class TravelingItem {
 
diff --git a/common/buildcraft/transport/gui/ContainerEmzuliPipe.java b/common/buildcraft/transport/gui/ContainerEmzuliPipe.java
index 14d100c7..abb8c81c 100644
--- a/common/buildcraft/transport/gui/ContainerEmzuliPipe.java
+++ b/common/buildcraft/transport/gui/ContainerEmzuliPipe.java
@@ -23,6 +23,7 @@ import cpw.mods.fml.relauncher.Side;
 import cpw.mods.fml.relauncher.SideOnly;
 
 import buildcraft.BuildCraftTransport;
+import buildcraft.api.core.EnumColor;
 import buildcraft.core.gui.BuildCraftContainer;
 import buildcraft.core.gui.GuiBuildCraft;
 import buildcraft.core.gui.slots.SlotPhantom;
@@ -30,7 +31,6 @@ import buildcraft.core.gui.tooltips.ToolTip;
 import buildcraft.core.gui.tooltips.ToolTipLine;
 import buildcraft.core.gui.widgets.ButtonWidget;
 import buildcraft.core.network.PacketGuiReturn;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.core.utils.RevolvingList;
 import buildcraft.core.utils.StringUtils;
 import buildcraft.transport.pipes.PipeItemsEmzuli;
diff --git a/common/buildcraft/transport/network/PacketPipeTransportTraveler.java b/common/buildcraft/transport/network/PacketPipeTransportTraveler.java
index ce3426b7..8232ab8f 100644
--- a/common/buildcraft/transport/network/PacketPipeTransportTraveler.java
+++ b/common/buildcraft/transport/network/PacketPipeTransportTraveler.java
@@ -13,10 +13,9 @@ import io.netty.buffer.ByteBuf;
 import net.minecraft.util.MathHelper;
 
 import net.minecraftforge.common.util.ForgeDirection;
-
+import buildcraft.api.core.EnumColor;
 import buildcraft.core.network.BuildCraftPacket;
 import buildcraft.core.network.PacketIds;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.transport.TravelingItem;
 
 public class PacketPipeTransportTraveler extends BuildCraftPacket {
diff --git a/common/buildcraft/transport/pipes/PipeItemsDaizuli.java b/common/buildcraft/transport/pipes/PipeItemsDaizuli.java
index f2c28442..8e5a7d3c 100644
--- a/common/buildcraft/transport/pipes/PipeItemsDaizuli.java
+++ b/common/buildcraft/transport/pipes/PipeItemsDaizuli.java
@@ -24,11 +24,11 @@ import cpw.mods.fml.relauncher.SideOnly;
 import net.minecraftforge.common.util.ForgeDirection;
 
 import buildcraft.BuildCraftTransport;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.core.IIconProvider;
 import buildcraft.api.core.NetworkData;
 import buildcraft.api.gates.IAction;
 import buildcraft.api.tools.IToolWrench;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.transport.Pipe;
 import buildcraft.transport.PipeIconProvider;
 import buildcraft.transport.PipeTransportItems;
diff --git a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java
index ed510dd7..ef70a009 100644
--- a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java
+++ b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java
@@ -24,12 +24,12 @@ import net.minecraft.nbt.NBTTagCompound;
 import net.minecraftforge.common.util.ForgeDirection;
 
 import buildcraft.BuildCraftTransport;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.gates.IAction;
 import buildcraft.core.GuiIds;
 import buildcraft.core.inventory.InvUtils;
 import buildcraft.core.inventory.SimpleInventory;
 import buildcraft.core.network.IGuiReturnHandler;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.transport.BlockGenericPipe;
 import buildcraft.transport.PipeIconProvider;
 import buildcraft.transport.TravelingItem;
diff --git a/common/buildcraft/transport/pipes/PipeItemsLapis.java b/common/buildcraft/transport/pipes/PipeItemsLapis.java
index 11c0bc65..44ca1f62 100644
--- a/common/buildcraft/transport/pipes/PipeItemsLapis.java
+++ b/common/buildcraft/transport/pipes/PipeItemsLapis.java
@@ -21,10 +21,10 @@ import cpw.mods.fml.relauncher.SideOnly;
 import net.minecraftforge.common.util.ForgeDirection;
 
 import buildcraft.BuildCraftTransport;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.core.IIconProvider;
 import buildcraft.api.gates.IAction;
 import buildcraft.api.tools.IToolWrench;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.transport.Pipe;
 import buildcraft.transport.PipeIconProvider;
 import buildcraft.transport.PipeTransportItems;
diff --git a/common/buildcraft/transport/render/PipeRendererTESR.java b/common/buildcraft/transport/render/PipeRendererTESR.java
index 632ed790..0c0f8827 100644
--- a/common/buildcraft/transport/render/PipeRendererTESR.java
+++ b/common/buildcraft/transport/render/PipeRendererTESR.java
@@ -38,6 +38,7 @@ import net.minecraftforge.fluids.FluidStack;
 import buildcraft.BuildCraftCore;
 import buildcraft.BuildCraftCore.RenderMode;
 import buildcraft.BuildCraftTransport;
+import buildcraft.api.core.EnumColor;
 import buildcraft.api.gates.IGateExpansion;
 import buildcraft.api.transport.IPipeTile.PipeType;
 import buildcraft.api.transport.PipeWire;
@@ -46,7 +47,6 @@ import buildcraft.core.DefaultProps;
 import buildcraft.core.render.RenderEntityBlock;
 import buildcraft.core.render.RenderEntityBlock.RenderInfo;
 import buildcraft.core.render.RenderUtils;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.core.utils.MatrixTranformations;
 import buildcraft.transport.Gate;
 import buildcraft.transport.Pipe;
diff --git a/common/buildcraft/transport/triggers/ActionExtractionPreset.java b/common/buildcraft/transport/triggers/ActionExtractionPreset.java
index b424f192..2dfd10e6 100644
--- a/common/buildcraft/transport/triggers/ActionExtractionPreset.java
+++ b/common/buildcraft/transport/triggers/ActionExtractionPreset.java
@@ -11,9 +11,8 @@ package buildcraft.transport.triggers;
 import java.util.Locale;
 
 import net.minecraft.client.renderer.texture.IIconRegister;
-
+import buildcraft.api.core.EnumColor;
 import buildcraft.core.triggers.BCActionPassive;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.core.utils.StringUtils;
 
 public class ActionExtractionPreset extends BCActionPassive {
diff --git a/common/buildcraft/transport/triggers/ActionPipeColor.java b/common/buildcraft/transport/triggers/ActionPipeColor.java
index 960bc3f2..358f6124 100644
--- a/common/buildcraft/transport/triggers/ActionPipeColor.java
+++ b/common/buildcraft/transport/triggers/ActionPipeColor.java
@@ -11,9 +11,8 @@ package buildcraft.transport.triggers;
 import java.util.Locale;
 
 import net.minecraft.client.renderer.texture.IIconRegister;
-
+import buildcraft.api.core.EnumColor;
 import buildcraft.core.triggers.BCActionPassive;
-import buildcraft.core.utils.EnumColor;
 import buildcraft.core.utils.StringUtils;
 
 public class ActionPipeColor extends BCActionPassive {