From 7d2e546a668af518c9f24e12e0d7ae003097e91c Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sun, 15 Jun 2014 15:01:10 +0200 Subject: [PATCH] Completed support for action parameters and parametrized pipe signal. Finalized implementation of emerald gate. Close #1880. --- api/buildcraft/api/gates/IAction.java | 3 + api/buildcraft/api/gates/IGate.java | 9 ++ api/buildcraft/api/gates/ITrigger.java | 5 +- .../api/gates/StatementManager.java | 37 ++++++-- common/buildcraft/BuildCraftSilicon.java | 7 ++ common/buildcraft/core/triggers/BCAction.java | 11 +++ .../buildcraft/core/triggers/BCStatement.java | 7 -- .../buildcraft/core/triggers/BCTrigger.java | 12 ++- .../core/triggers/TriggerRedstoneInput.java | 6 +- common/buildcraft/transport/Gate.java | 50 +++++++---- .../transport/gui/ContainerGateInterface.java | 8 ++ .../transport/gui/GuiGateInterface.java | 52 +++++++---- .../triggers/ActionParameterSignal.java | 86 +++++++++++++++++++ .../triggers/ActionSignalOutput.java | 30 +++++++ .../triggers/TriggerParameterSignal.java | 41 ++++++--- .../triggers/TriggerPipeContents.java | 17 ++-- .../transport/triggers/TriggerPipeSignal.java | 38 ++++++-- .../triggers/TriggerRedstoneFaderInput.java | 8 +- 18 files changed, 338 insertions(+), 89 deletions(-) create mode 100755 common/buildcraft/transport/triggers/ActionParameterSignal.java diff --git a/api/buildcraft/api/gates/IAction.java b/api/buildcraft/api/gates/IAction.java index a02c4486..c2fae11d 100755 --- a/api/buildcraft/api/gates/IAction.java +++ b/api/buildcraft/api/gates/IAction.java @@ -8,6 +8,9 @@ */ package buildcraft.api.gates; + public interface IAction extends IStatement { + void actionActivate(IGate gate, IActionParameter[] parameters); + } diff --git a/api/buildcraft/api/gates/IGate.java b/api/buildcraft/api/gates/IGate.java index 711d692d..2c957777 100644 --- a/api/buildcraft/api/gates/IGate.java +++ b/api/buildcraft/api/gates/IGate.java @@ -8,6 +8,15 @@ */ package buildcraft.api.gates; +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.transport.IPipe; + public interface IGate { + void setPulsing(boolean pulsing); + + IPipe getPipe(); + + ForgeDirection getSide(); } diff --git a/api/buildcraft/api/gates/ITrigger.java b/api/buildcraft/api/gates/ITrigger.java index 14168f90..e4fc5923 100755 --- a/api/buildcraft/api/gates/ITrigger.java +++ b/api/buildcraft/api/gates/ITrigger.java @@ -8,12 +8,9 @@ */ package buildcraft.api.gates; -import net.minecraftforge.common.util.ForgeDirection; - -import buildcraft.api.transport.IPipe; public interface ITrigger extends IStatement { - boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters); + boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters); } diff --git a/api/buildcraft/api/gates/StatementManager.java b/api/buildcraft/api/gates/StatementManager.java index be8f11e7..9fb047bc 100644 --- a/api/buildcraft/api/gates/StatementManager.java +++ b/api/buildcraft/api/gates/StatementManager.java @@ -22,6 +22,8 @@ import buildcraft.api.transport.IPipeTile; public final class StatementManager { public static Map statements = new HashMap(); + public static Map> idToParameter = new HashMap>(); + public static Map, String> parameterToId = new HashMap, String>(); private static List triggerProviders = new LinkedList(); private static List actionProviders = new LinkedList(); @@ -37,10 +39,21 @@ public final class StatementManager { } } + public static void registerActionProvider(IActionProvider provider) { + if (provider != null && !actionProviders.contains(provider)) { + actionProviders.add(provider); + } + } + public static void registerStatement(IStatement statement) { statements.put(statement.getUniqueTag(), statement); } + public static void registerParameterClass(String name, Class param) { + idToParameter.put(name, param); + parameterToId.put(param, name); + } + public static List getNeighborTriggers(Block block, TileEntity entity) { List result = new LinkedList(); @@ -59,12 +72,6 @@ public final class StatementManager { return result; } - public static void registerActionProvider(IActionProvider provider) { - if (provider != null && !actionProviders.contains(provider)) { - actionProviders.add(provider); - } - } - public static List getNeighborActions(Block block, TileEntity entity) { List result = new LinkedList(); @@ -100,7 +107,7 @@ public final class StatementManager { return result; } - + public static List getPipeActions(IPipeTile pipe) { List result = new LinkedList(); @@ -118,4 +125,20 @@ public final class StatementManager { return result; } + + public static String getParameterKind(IStatementParameter param) { + return parameterToId.get(param.getClass()); + } + + public static IStatementParameter createParameter(String kind) { + try { + return idToParameter.get(kind).newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return null; + } } diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 6235b346..7ce17b6d 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -27,6 +27,7 @@ import net.minecraftforge.oredict.OreDictionary; import buildcraft.api.blueprints.SchematicRegistry; import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.gates.StatementManager; +import buildcraft.api.gates.TriggerParameter; import buildcraft.api.recipes.BuildcraftRecipeRegistry; import buildcraft.api.transport.PipeWire; import buildcraft.builders.schematics.SchematicRotateMeta; @@ -69,6 +70,8 @@ import buildcraft.transport.gates.GateExpansionPulsar; import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionTimer; import buildcraft.transport.gates.ItemGate; +import buildcraft.transport.triggers.ActionParameterSignal; +import buildcraft.transport.triggers.TriggerParameterSignal; @Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT) public class BuildCraftSilicon extends BuildCraftMod { @@ -142,6 +145,10 @@ public class BuildCraftSilicon extends BuildCraftMod { } SiliconProxy.proxy.registerRenderers(); + + StatementManager.registerParameterClass("buildcraft:stackTrigger", TriggerParameter.class); + StatementManager.registerParameterClass("buildcraft:pipeWireTrigger", TriggerParameterSignal.class); + StatementManager.registerParameterClass("buildcraft:pipeWireAction", ActionParameterSignal.class); } public static void loadRecipes() { diff --git a/common/buildcraft/core/triggers/BCAction.java b/common/buildcraft/core/triggers/BCAction.java index 98883b5f..9d7f99a4 100644 --- a/common/buildcraft/core/triggers/BCAction.java +++ b/common/buildcraft/core/triggers/BCAction.java @@ -9,6 +9,8 @@ package buildcraft.core.triggers; import buildcraft.api.gates.IAction; +import buildcraft.api.gates.IActionParameter; +import buildcraft.api.gates.IGate; public abstract class BCAction extends BCStatement implements IAction { @@ -16,4 +18,13 @@ public abstract class BCAction extends BCStatement implements IAction { super(uniqueTag); } + @Override + public IActionParameter createParameter(int index) { + return null; + } + + @Override + public void actionActivate(IGate gate, IActionParameter[] parameters) { + + } } diff --git a/common/buildcraft/core/triggers/BCStatement.java b/common/buildcraft/core/triggers/BCStatement.java index cf24c276..e9a6a553 100755 --- a/common/buildcraft/core/triggers/BCStatement.java +++ b/common/buildcraft/core/triggers/BCStatement.java @@ -15,9 +15,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import buildcraft.api.gates.IStatement; -import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.StatementManager; -import buildcraft.api.gates.TriggerParameter; public abstract class BCStatement implements IStatement { @@ -72,9 +70,4 @@ public abstract class BCStatement implements IStatement { return ""; } - @Override - public ITriggerParameter createParameter(int index) { - return new TriggerParameter(); - } - } diff --git a/common/buildcraft/core/triggers/BCTrigger.java b/common/buildcraft/core/triggers/BCTrigger.java index af41c591..37622fbc 100644 --- a/common/buildcraft/core/triggers/BCTrigger.java +++ b/common/buildcraft/core/triggers/BCTrigger.java @@ -12,9 +12,11 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.gates.IGate; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; -import buildcraft.api.transport.IPipe; +import buildcraft.api.gates.TriggerParameter; +import buildcraft.transport.Pipe; /** * This class has to be implemented to create new triggers kinds to BuildCraft @@ -28,8 +30,9 @@ public abstract class BCTrigger extends BCStatement implements ITrigger { } @Override - public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters) { + public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) { ITriggerParameter p = parameters[0]; + Pipe pipe = (Pipe) gate.getPipe(); for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { if (isTriggerActive(side.getOpposite(), pipe.getAdjacentTile(side), p)) { @@ -44,4 +47,9 @@ public abstract class BCTrigger extends BCStatement implements ITrigger { return false; } + @Override + public ITriggerParameter createParameter(int index) { + return new TriggerParameter(); + } + } diff --git a/common/buildcraft/core/triggers/TriggerRedstoneInput.java b/common/buildcraft/core/triggers/TriggerRedstoneInput.java index c8040acc..e7c6b005 100644 --- a/common/buildcraft/core/triggers/TriggerRedstoneInput.java +++ b/common/buildcraft/core/triggers/TriggerRedstoneInput.java @@ -10,9 +10,9 @@ package buildcraft.core.triggers; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.gates.IGate; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; -import buildcraft.api.transport.IPipe; import buildcraft.core.utils.StringUtils; import buildcraft.transport.Pipe; @@ -31,8 +31,8 @@ public class TriggerRedstoneInput extends BCTrigger { } @Override - public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters) { - return !(active ^ isBeingPowered((Pipe) pipe, direction)); + public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) { + return !(active ^ isBeingPowered((Pipe) gate.getPipe(), gate.getSide())); } private boolean isBeingPowered(Pipe pipe, ForgeDirection direction) { diff --git a/common/buildcraft/transport/Gate.java b/common/buildcraft/transport/Gate.java index 81cf88d8..39623e6a 100644 --- a/common/buildcraft/transport/Gate.java +++ b/common/buildcraft/transport/Gate.java @@ -37,6 +37,7 @@ import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.StatementManager; import buildcraft.api.gates.TriggerParameter; +import buildcraft.api.transport.IPipe; import buildcraft.api.transport.PipeWire; import buildcraft.core.GuiIds; import buildcraft.core.triggers.ActionRedstoneOutput; @@ -45,7 +46,6 @@ import buildcraft.transport.gates.GateDefinition.GateMaterial; import buildcraft.transport.gates.ItemGate; import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.triggers.ActionRedstoneFaderOutput; -import buildcraft.transport.triggers.ActionSignalOutput; public final class Gate implements IGate { @@ -161,6 +161,7 @@ public final class Gate implements IGate { for (int j = 0; j < 3; ++j) { if (triggerParameters[i][j] != null) { NBTTagCompound cpt = new NBTTagCompound(); + cpt.setString("kind", StatementManager.getParameterKind(triggerParameters[i][j])); triggerParameters[i][j].writeToNBT(cpt); data.setTag("triggerParameters[" + i + "][" + j + "]", cpt); } @@ -169,6 +170,7 @@ public final class Gate implements IGate { for (int j = 0; j < 3; ++j) { if (actionParameters[i][j] != null) { NBTTagCompound cpt = new NBTTagCompound(); + cpt.setString("kind", StatementManager.getParameterKind(actionParameters[i][j])); actionParameters[i][j].writeToNBT(cpt); data.setTag("actionParameters[" + i + "][" + j + "]", cpt); } @@ -200,19 +202,18 @@ public final class Gate implements IGate { for (int j = 0; j < 3; ++j) { if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) { - NBTTagCompound cpt = new NBTTagCompound(); - // we need the real parameter type here - triggerParameters[i][j] = new TriggerParameter(); - triggerParameters[i][j].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "][" + j + "]")); + NBTTagCompound cpt = data.getCompoundTag("triggerParameters[" + i + "][" + j + "]"); + triggerParameters[i][j] = (ITriggerParameter) StatementManager.createParameter(cpt + .getString("kind")); + triggerParameters[i][j].readFromNBT(cpt); } } for (int j = 0; j < 3; ++j) { - if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) { - NBTTagCompound cpt = new NBTTagCompound(); - // actionParameters[i][j] = new ActionParameter(); - // actionParameters[i][j].readFromNBT(data.getCompoundTag("actionParameters[" - // + i + "][" + j + "]")); + if (data.hasKey("actionParameters[" + i + "][" + j + "]")) { + NBTTagCompound cpt = data.getCompoundTag("actionParameters[" + i + "][" + j + "]"); + actionParameters[i][j] = (IActionParameter) StatementManager.createParameter(cpt.getString("kind")); + actionParameters[i][j].readFromNBT(cpt); } } } @@ -345,9 +346,13 @@ public final class Gate implements IGate { } // Activate the actions - for (Map.Entry entry : activeActions.entrySet()) { - if (entry.getValue()) { - IAction action = entry.getKey(); + for (int it = 0; it < activeActions.size(); ++it) { + if (actionsState[it] == ActionState.Activated) { + IAction action = actions[it]; + action.actionActivate(this, actionParameters[it]); + + // TODO: A lot of the code below should be removed in favor + // of calls to actionActivate // Custom gate actions take precedence over defaults. if (resolveAction(action, actionCount.count(action))) { @@ -358,8 +363,6 @@ public final class Gate implements IGate { redstoneOutput = 15; } else if (action instanceof ActionRedstoneFaderOutput) { redstoneOutput = ((ActionRedstoneFaderOutput) action).level; - } else if (action instanceof ActionSignalOutput) { - broadcastSignal.set(((ActionSignalOutput) action).color.ordinal()); } else { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { TileEntity tile = pipe.container.getTile(side); @@ -401,7 +404,7 @@ public final class Gate implements IGate { return false; } - if (trigger.isTriggerActive(pipe, direction, parameters)) { + if (trigger.isTriggerActive(this, parameters)) { return true; } @@ -444,6 +447,7 @@ public final class Gate implements IGate { } } + @Override public void setPulsing (boolean pulsing) { if (pulsing != isPulsing) { isPulsing = pulsing; @@ -454,4 +458,18 @@ public final class Gate implements IGate { public float getPulseStage () { return pulseStage; } + + public void broadcastSignal(PipeWire color) { + broadcastSignal.set(color.ordinal()); + } + + @Override + public IPipe getPipe() { + return pipe; + } + + @Override + public ForgeDirection getSide() { + return direction; + } } diff --git a/common/buildcraft/transport/gui/ContainerGateInterface.java b/common/buildcraft/transport/gui/ContainerGateInterface.java index 7412c36a..5f238b18 100644 --- a/common/buildcraft/transport/gui/ContainerGateInterface.java +++ b/common/buildcraft/transport/gui/ContainerGateInterface.java @@ -347,6 +347,14 @@ public class ContainerGateInterface extends BuildCraftContainer { } } + public ITriggerParameter getTriggerParameter(int trigger, int param) { + if (gate == null) { + return null; + } else { + return gate.getTriggerParameter(trigger, param); + } + } + /** * ACTIONS * */ diff --git a/common/buildcraft/transport/gui/GuiGateInterface.java b/common/buildcraft/transport/gui/GuiGateInterface.java index c8cec3d1..6671e32f 100644 --- a/common/buildcraft/transport/gui/GuiGateInterface.java +++ b/common/buildcraft/transport/gui/GuiGateInterface.java @@ -22,6 +22,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import buildcraft.api.gates.IAction; +import buildcraft.api.gates.IActionParameter; import buildcraft.api.gates.IStatement; import buildcraft.api.gates.IStatementParameter; import buildcraft.api.gates.ITrigger; @@ -124,7 +125,7 @@ public class GuiGateInterface extends GuiAdvancedInterface { @Override public boolean isDefined() { - return gate.getTriggerParameter(statementSlot.slot, slot) != null; + return getParameter() != null; } @Override @@ -158,6 +159,8 @@ public class GuiGateInterface extends GuiAdvancedInterface { public boolean isRequired() { return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters(); } + + public abstract void setParameter(IStatementParameter param, boolean notifyServer); } class TriggerParameterSlot extends StatementParameterSlot { @@ -169,6 +172,11 @@ public class GuiGateInterface extends GuiAdvancedInterface { public IStatementParameter getParameter() { return gate.getTriggerParameter(statementSlot.slot, slot); } + + @Override + public void setParameter(IStatementParameter param, boolean notifyServer) { + container.setTriggerParameter(statementSlot.slot, slot, (ITriggerParameter) param, notifyServer); + } } class ActionParameterSlot extends StatementParameterSlot { @@ -180,6 +188,11 @@ public class GuiGateInterface extends GuiAdvancedInterface { public IStatementParameter getParameter() { return gate.getActionParameter(statementSlot.slot, slot); } + + @Override + public void setParameter(IStatementParameter param, boolean notifyServer) { + container.setActionParameter(statementSlot.slot, slot, (IActionParameter) param, notifyServer); + } } public GuiGateInterface(IInventory playerInventory, Pipe pipe) { @@ -335,26 +348,21 @@ public class GuiGateInterface extends GuiAdvancedInterface { if (slot instanceof TriggerSlot) { boolean halfWidth = container.actionsState[actionTracker] == ActionState.Partial; - if (gate.material.numTriggerParameters > 0) { - if (container.actionsState[actionTracker] != ActionState.Deactivated) { - mc.renderEngine.bindTexture(texture); - - drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4); - } - } else if (container.actionsState[actionTracker] != ActionState.Deactivated) { + if (container.actionsState[actionTracker] != ActionState.Deactivated) { mc.renderEngine.bindTexture(texture); - drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4); + drawTexturedModalRect(cornerX + slot.x + 17 + 18 * gate.material.numTriggerParameters, cornerY + + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4); } actionTracker++; } else if (slot instanceof StatementParameterSlot) { StatementParameterSlot paramSlot = (StatementParameterSlot) slot; - StatementSlot trigger = paramSlot.statementSlot; + StatementSlot statement = paramSlot.statementSlot; mc.renderEngine.bindTexture(texture); - if (trigger.isDefined()) { + if (statement.isDefined()) { if (!paramSlot.isAllowed()) { drawTexturedModalRect(cornerX + slot.x - 1, cornerY + slot.y - 1, 176, 0, 18, 18); } else if (paramSlot.isRequired() && paramSlot.getItemStack() == null) { @@ -464,16 +472,24 @@ public class GuiGateInterface extends GuiAdvancedInterface { } else { container.setAction(actionSlot.slot, changed.getUniqueTag(), true); } - } else if (slot instanceof TriggerParameterSlot) { - TriggerParameterSlot paramSlot = (TriggerParameterSlot) slot; - TriggerSlot trigger = (TriggerSlot) paramSlot.statementSlot; - if (trigger.isDefined() && trigger.getStatement().maxParameters() != 0) { - ITriggerParameter param = (ITriggerParameter) trigger.getStatement().createParameter(paramSlot.slot); + for (StatementParameterSlot p : actionSlot.parameters) { + container.setActionParameter(actionSlot.slot, p.slot, null, true); + } + } else if (slot instanceof StatementParameterSlot) { + StatementParameterSlot paramSlot = (StatementParameterSlot) slot; + StatementSlot statement = paramSlot.statementSlot; + + if (statement.isDefined() && statement.getStatement().maxParameters() != 0) { + IStatementParameter param = paramSlot.getParameter(); + + if (param == null) { + param = statement.getStatement().createParameter(paramSlot.slot); + } if (param != null) { - param.clicked(pipe.container, trigger.getStatement(), mc.thePlayer.inventory.getItemStack()); - container.setTriggerParameter(trigger.slot, paramSlot.slot, param, true); + param.clicked(pipe.container, statement.getStatement(), mc.thePlayer.inventory.getItemStack()); + paramSlot.setParameter(param, true); } } } diff --git a/common/buildcraft/transport/triggers/ActionParameterSignal.java b/common/buildcraft/transport/triggers/ActionParameterSignal.java new file mode 100755 index 00000000..a50d33c9 --- /dev/null +++ b/common/buildcraft/transport/triggers/ActionParameterSignal.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * 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.transport.triggers; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.IIcon; + +import buildcraft.api.core.NetworkData; +import buildcraft.api.gates.IActionParameter; +import buildcraft.api.gates.IStatement; +import buildcraft.api.transport.IPipeTile; +import buildcraft.api.transport.PipeWire; +import buildcraft.core.triggers.StatementIconProvider; + +public class ActionParameterSignal implements IActionParameter { + + @NetworkData + public PipeWire color = null; + + public ActionParameterSignal() { + + } + + @Override + public ItemStack getItemStackToDraw() { + return null; + } + + @Override + public IIcon getIconToDraw() { + int id = 0; + + if (color == null) { + return null; + } + + switch (color) { + case RED: + id = StatementIconProvider.Trigger_PipeSignal_Red_Active; + break; + case BLUE: + id = StatementIconProvider.Trigger_PipeSignal_Blue_Active; + break; + case GREEN: + id = StatementIconProvider.Trigger_PipeSignal_Green_Active; + break; + case YELLOW: + id = StatementIconProvider.Trigger_PipeSignal_Yellow_Active; + break; + } + + return StatementIconProvider.INSTANCE.getIcon(id); + } + + @Override + public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) { + if (color == null) { + color = PipeWire.RED; + } else if (color == PipeWire.YELLOW) { + color = null; + } else { + color = PipeWire.values()[color.ordinal() + 1]; + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + if (color != null) { + nbt.setByte("color", (byte) color.ordinal()); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + if (nbt.hasKey("color")) { + color = PipeWire.values()[nbt.getByte("color")]; + } + } +} diff --git a/common/buildcraft/transport/triggers/ActionSignalOutput.java b/common/buildcraft/transport/triggers/ActionSignalOutput.java index dfcee550..f2f26230 100644 --- a/common/buildcraft/transport/triggers/ActionSignalOutput.java +++ b/common/buildcraft/transport/triggers/ActionSignalOutput.java @@ -11,10 +11,13 @@ package buildcraft.transport.triggers; import java.util.Locale; import buildcraft.api.gates.IAction; +import buildcraft.api.gates.IActionParameter; +import buildcraft.api.gates.IGate; import buildcraft.api.transport.PipeWire; import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.StatementIconProvider; import buildcraft.core.utils.StringUtils; +import buildcraft.transport.Gate; public class ActionSignalOutput extends BCAction { @@ -50,4 +53,31 @@ public class ActionSignalOutput extends BCAction { public IAction rotateLeft() { return this; } + + @Override + public int maxParameters() { + return 3; + } + + @Override + public IActionParameter createParameter(int index) { + return new ActionParameterSignal(); + } + + @Override + public void actionActivate(IGate iGate, IActionParameter[] parameters) { + Gate gate = (Gate) iGate; + + gate.broadcastSignal(color); + + for (IActionParameter param : parameters) { + if (param != null) { + ActionParameterSignal signal = (ActionParameterSignal) param; + + if (signal.color != null) { + gate.broadcastSignal(signal.color); + } + } + } + } } diff --git a/common/buildcraft/transport/triggers/TriggerParameterSignal.java b/common/buildcraft/transport/triggers/TriggerParameterSignal.java index 14541c53..e6d79c20 100755 --- a/common/buildcraft/transport/triggers/TriggerParameterSignal.java +++ b/common/buildcraft/transport/triggers/TriggerParameterSignal.java @@ -22,19 +22,15 @@ import buildcraft.core.triggers.StatementIconProvider; public class TriggerParameterSignal implements ITriggerParameter { @NetworkData - private boolean active; + public boolean active = false; @NetworkData - private PipeWire color = PipeWire.RED; + public PipeWire color = null; public TriggerParameterSignal() { } - public TriggerParameterSignal(TriggerPipeSignal trigger) { - - } - @Override public ItemStack getItemStackToDraw() { return null; @@ -44,6 +40,10 @@ public class TriggerParameterSignal implements ITriggerParameter { public IIcon getIconToDraw() { int id = 0; + if (color == null) { + return null; + } + if (active) { switch (color) { case RED: @@ -81,18 +81,35 @@ public class TriggerParameterSignal implements ITriggerParameter { @Override public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) { - if (stmt instanceof TriggerPipeSignal) { - TriggerPipeSignal signal = (TriggerPipeSignal) stmt; + if (color == null) { + active = true; + color = PipeWire.RED; + } else if (active) { + active = false; + } else if (color == PipeWire.YELLOW) { + color = null; + } else { + color = PipeWire.values()[color.ordinal() + 1]; + active = true; + } + } + @Override + public void writeToNBT(NBTTagCompound nbt) { + nbt.setBoolean("active", active); + + if (color != null) { + nbt.setByte("color", (byte) color.ordinal()); } } @Override - public void writeToNBT(NBTTagCompound compound) { - } + public void readFromNBT(NBTTagCompound nbt) { + active = nbt.getBoolean("active"); - @Override - public void readFromNBT(NBTTagCompound compound) { + if (nbt.hasKey("color")) { + color = PipeWire.values()[nbt.getByte("color")]; + } } } diff --git a/common/buildcraft/transport/triggers/TriggerPipeContents.java b/common/buildcraft/transport/triggers/TriggerPipeContents.java index 97490d7e..0068c31f 100644 --- a/common/buildcraft/transport/triggers/TriggerPipeContents.java +++ b/common/buildcraft/transport/triggers/TriggerPipeContents.java @@ -21,9 +21,9 @@ import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; +import buildcraft.api.gates.IGate; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; -import buildcraft.api.transport.IPipe; import buildcraft.core.triggers.BCTrigger; import buildcraft.core.utils.StringUtils; import buildcraft.transport.Pipe; @@ -72,11 +72,12 @@ public class TriggerPipeContents extends BCTrigger { } @Override - public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters) { + public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) { + Pipe pipe = (Pipe) gate.getPipe(); ITriggerParameter parameter = parameters[0]; - if (((Pipe) pipe).transport instanceof PipeTransportItems) { - PipeTransportItems transportItems = (PipeTransportItems) ((Pipe) pipe).transport; + if (pipe.transport instanceof PipeTransportItems) { + PipeTransportItems transportItems = (PipeTransportItems) pipe.transport; if (kind == PipeContents.empty) { return transportItems.items.isEmpty(); } else if (kind == PipeContents.containsItems) { @@ -92,8 +93,8 @@ public class TriggerPipeContents extends BCTrigger { return !transportItems.items.isEmpty(); } } - } else if (((Pipe) pipe).transport instanceof PipeTransportFluids) { - PipeTransportFluids transportFluids = (PipeTransportFluids) ((Pipe) pipe).transport; + } else if (pipe.transport instanceof PipeTransportFluids) { + PipeTransportFluids transportFluids = (PipeTransportFluids) pipe.transport; FluidStack searchedFluid = null; @@ -120,8 +121,8 @@ public class TriggerPipeContents extends BCTrigger { return false; } - } else if (((Pipe) pipe).transport instanceof PipeTransportPower) { - PipeTransportPower transportPower = (PipeTransportPower) ((Pipe) pipe).transport; + } else if (pipe.transport instanceof PipeTransportPower) { + PipeTransportPower transportPower = (PipeTransportPower) pipe.transport; switch (kind) { case empty: diff --git a/common/buildcraft/transport/triggers/TriggerPipeSignal.java b/common/buildcraft/transport/triggers/TriggerPipeSignal.java index c1ef9e6e..f885cb39 100644 --- a/common/buildcraft/transport/triggers/TriggerPipeSignal.java +++ b/common/buildcraft/transport/triggers/TriggerPipeSignal.java @@ -10,11 +10,9 @@ package buildcraft.transport.triggers; import java.util.Locale; -import net.minecraftforge.common.util.ForgeDirection; - +import buildcraft.api.gates.IGate; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; -import buildcraft.api.transport.IPipe; import buildcraft.api.transport.PipeWire; import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.StatementIconProvider; @@ -45,12 +43,38 @@ public class TriggerPipeSignal extends BCTrigger { } @Override - public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameter) { + public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) { + Pipe pipe = (Pipe) gate.getPipe(); + if (active) { - return ((Pipe) pipe).signalStrength[color.ordinal()] > 0; + if (pipe.signalStrength[color.ordinal()] == 0) { + return false; + } } else { - return ((Pipe) pipe).signalStrength[color.ordinal()] == 0; + if (pipe.signalStrength[color.ordinal()] > 0) { + return false; + } } + + for (ITriggerParameter param : parameters) { + if (param != null) { + TriggerParameterSignal signal = (TriggerParameterSignal) param; + + if (signal.color != null) { + if (signal.active) { + if (pipe.signalStrength[signal.color.ordinal()] == 0) { + return false; + } + } else { + if (pipe.signalStrength[signal.color.ordinal()] > 0) { + return false; + } + } + } + } + } + + return true; } @Override @@ -89,6 +113,6 @@ public class TriggerPipeSignal extends BCTrigger { @Override public ITriggerParameter createParameter(int index) { - return new TriggerParameterSignal(this); + return new TriggerParameterSignal(); } } diff --git a/common/buildcraft/transport/triggers/TriggerRedstoneFaderInput.java b/common/buildcraft/transport/triggers/TriggerRedstoneFaderInput.java index 6ce00947..8149191a 100644 --- a/common/buildcraft/transport/triggers/TriggerRedstoneFaderInput.java +++ b/common/buildcraft/transport/triggers/TriggerRedstoneFaderInput.java @@ -14,11 +14,9 @@ import net.minecraft.util.IIcon; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraftforge.common.util.ForgeDirection; - +import buildcraft.api.gates.IGate; import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITriggerParameter; -import buildcraft.api.transport.IPipe; import buildcraft.core.triggers.BCTrigger; import buildcraft.core.utils.StringUtils; import buildcraft.transport.TileGenericPipe; @@ -41,8 +39,8 @@ public class TriggerRedstoneFaderInput extends BCTrigger { } @Override - public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameter) { - return ((TileGenericPipe) pipe.getTile()).redstoneInput[direction.ordinal()] == level; + public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameter) { + return ((TileGenericPipe) gate.getPipe().getTile()).redstoneInput[gate.getSide().ordinal()] == level; } @Override