Merge pull request #1932 from simon816/pipe-item-color

Add support for giving items a color when calling injectItem
This commit is contained in:
SpaceToad 2014-07-10 07:23:06 +02:00
commit a668977ff5
13 changed files with 33 additions and 18 deletions

View file

@ -6,9 +6,12 @@
* License 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.core.utils; package buildcraft.api.core;
import java.util.Locale; import java.util.Locale;
import java.util.Random;
import net.minecraft.util.StatCollector;
public enum EnumColor { public enum EnumColor {
@ -132,7 +135,7 @@ public enum EnumColor {
} }
public static EnumColor getRand() { public static EnumColor getRand() {
return VALUES[Utils.RANDOM.nextInt(VALUES.length)]; return VALUES[new Random().nextInt(VALUES.length)];
} }
public EnumColor getNext() { public EnumColor getNext() {
@ -162,7 +165,7 @@ public enum EnumColor {
} }
public String getLocalizedName() { public String getLocalizedName() {
return StringUtils.localize(getTag()); return StatCollector.translateToLocal(getTag());
} }
public String getDye() { public String getDye() {

View file

@ -9,8 +9,8 @@
package buildcraft.api.transport; package buildcraft.api.transport;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.EnumColor;
public interface IPipeTile { public interface IPipeTile {
@ -29,8 +29,16 @@ public interface IPipeTile {
* @param doAdd If false no actual addition should take place. Implementors * @param doAdd If false no actual addition should take place. Implementors
* should simulate. * should simulate.
* @param from Orientation the ItemStack is offered from. * @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. * @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); int injectItem(ItemStack stack, boolean doAdd, ForgeDirection from);
/** /**

View file

@ -33,6 +33,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter;
import buildcraft.api.blueprints.SchematicRegistry; import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools; import buildcraft.api.core.JavaTools;
import buildcraft.api.gates.GateExpansions; import buildcraft.api.gates.GateExpansions;
@ -51,7 +52,6 @@ import buildcraft.core.Version;
import buildcraft.core.network.BuildCraftChannelHandler; import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionPipeClose; import buildcraft.core.triggers.ActionPipeClose;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.BlockFilteredBuffer; import buildcraft.transport.BlockFilteredBuffer;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.GuiHandler; import buildcraft.transport.GuiHandler;

View file

@ -37,6 +37,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog; import buildcraft.api.core.BCLog;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.gates.IGateExpansion; import buildcraft.api.gates.IGateExpansion;
@ -579,7 +580,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
/* IPIPEENTRY */ /* IPIPEENTRY */
@Override @Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) { public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from, EnumColor color) {
if (pipe.isClosed()) { if (pipe.isClosed()) {
return 0; return 0;
} }
@ -590,6 +591,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
itemPos.moveBackwards(0.4); itemPos.moveBackwards(0.4);
TravelingItem pipedItem = TravelingItem.make(itemPos.x, itemPos.y, itemPos.z, payload); TravelingItem pipedItem = TravelingItem.make(itemPos.x, itemPos.y, itemPos.z, payload);
pipedItem.color = color;
((PipeTransportItems) pipe.transport).injectItem(pipedItem, itemPos.orientation); ((PipeTransportItems) pipe.transport).injectItem(pipedItem, itemPos.orientation);
} }
return payload.stackSize; return payload.stackSize;
@ -598,6 +600,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return 0; return 0;
} }
@Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
return injectItem(payload, doAdd, from, null);
}
@Override @Override
public PipeType getPipeType() { public PipeType getPipeType() {
if (BlockGenericPipe.isValid(pipe)) { if (BlockGenericPipe.isValid(pipe)) {

View file

@ -26,9 +26,9 @@ import cpw.mods.fml.relauncher.Side;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.core.inventory.StackHelper; import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.EnumColor;
public class TravelingItem { public class TravelingItem {

View file

@ -23,6 +23,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.core.gui.BuildCraftContainer; import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.gui.GuiBuildCraft; import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.gui.slots.SlotPhantom; 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.tooltips.ToolTipLine;
import buildcraft.core.gui.widgets.ButtonWidget; import buildcraft.core.gui.widgets.ButtonWidget;
import buildcraft.core.network.PacketGuiReturn; import buildcraft.core.network.PacketGuiReturn;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.RevolvingList; import buildcraft.core.utils.RevolvingList;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.pipes.PipeItemsEmzuli; import buildcraft.transport.pipes.PipeItemsEmzuli;

View file

@ -13,10 +13,9 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.EnumColor;
import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;
public class PacketPipeTransportTraveler extends BuildCraftPacket { public class PacketPipeTransportTraveler extends BuildCraftPacket {

View file

@ -24,11 +24,11 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.NetworkData; import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.tools.IToolWrench; import buildcraft.api.tools.IToolWrench;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;

View file

@ -24,12 +24,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.core.GuiIds; import buildcraft.core.GuiIds;
import buildcraft.core.inventory.InvUtils; import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.IGuiReturnHandler; import buildcraft.core.network.IGuiReturnHandler;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;

View file

@ -21,10 +21,10 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.tools.IToolWrench; import buildcraft.api.tools.IToolWrench;
import buildcraft.core.utils.EnumColor;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;

View file

@ -38,6 +38,7 @@ import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode; import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.BuildCraftTransport; import buildcraft.BuildCraftTransport;
import buildcraft.api.core.EnumColor;
import buildcraft.api.gates.IGateExpansion; import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.transport.IPipeTile.PipeType; import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
@ -46,7 +47,6 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.render.RenderEntityBlock; import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.RenderInfo; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import buildcraft.core.render.RenderUtils; import buildcraft.core.render.RenderUtils;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.Gate; import buildcraft.transport.Gate;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;

View file

@ -11,9 +11,8 @@ package buildcraft.transport.triggers;
import java.util.Locale; import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.api.core.EnumColor;
import buildcraft.core.triggers.BCActionPassive; import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
public class ActionExtractionPreset extends BCActionPassive { public class ActionExtractionPreset extends BCActionPassive {

View file

@ -11,9 +11,8 @@ package buildcraft.transport.triggers;
import java.util.Locale; import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.api.core.EnumColor;
import buildcraft.core.triggers.BCActionPassive; import buildcraft.core.triggers.BCActionPassive;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
public class ActionPipeColor extends BCActionPassive { public class ActionPipeColor extends BCActionPassive {