Completed support for action parameters and parametrized pipe signal.

Finalized implementation of emerald gate.
Close #1880.
This commit is contained in:
SpaceToad 2014-06-15 15:01:10 +02:00
parent bc51e29746
commit 7d2e546a66
18 changed files with 338 additions and 89 deletions

View file

@ -8,6 +8,9 @@
*/ */
package buildcraft.api.gates; package buildcraft.api.gates;
public interface IAction extends IStatement { public interface IAction extends IStatement {
void actionActivate(IGate gate, IActionParameter[] parameters);
} }

View file

@ -8,6 +8,15 @@
*/ */
package buildcraft.api.gates; package buildcraft.api.gates;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IPipe;
public interface IGate { public interface IGate {
void setPulsing(boolean pulsing); void setPulsing(boolean pulsing);
IPipe getPipe();
ForgeDirection getSide();
} }

View file

@ -8,12 +8,9 @@
*/ */
package buildcraft.api.gates; package buildcraft.api.gates;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IPipe;
public interface ITrigger extends IStatement { public interface ITrigger extends IStatement {
boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters); boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters);
} }

View file

@ -22,6 +22,8 @@ import buildcraft.api.transport.IPipeTile;
public final class StatementManager { public final class StatementManager {
public static Map<String, IStatement> statements = new HashMap<String, IStatement>(); public static Map<String, IStatement> statements = new HashMap<String, IStatement>();
public static Map<String, Class<? extends IStatementParameter>> idToParameter = new HashMap<String, Class<? extends IStatementParameter>>();
public static Map<Class<? extends IStatementParameter>, String> parameterToId = new HashMap<Class<? extends IStatementParameter>, String>();
private static List<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>(); private static List<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
private static List<IActionProvider> actionProviders = new LinkedList<IActionProvider>(); private static List<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
@ -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) { public static void registerStatement(IStatement statement) {
statements.put(statement.getUniqueTag(), statement); statements.put(statement.getUniqueTag(), statement);
} }
public static void registerParameterClass(String name, Class<? extends IStatementParameter> param) {
idToParameter.put(name, param);
parameterToId.put(param, name);
}
public static List<ITrigger> getNeighborTriggers(Block block, TileEntity entity) { public static List<ITrigger> getNeighborTriggers(Block block, TileEntity entity) {
List<ITrigger> result = new LinkedList<ITrigger>(); List<ITrigger> result = new LinkedList<ITrigger>();
@ -59,12 +72,6 @@ public final class StatementManager {
return result; return result;
} }
public static void registerActionProvider(IActionProvider provider) {
if (provider != null && !actionProviders.contains(provider)) {
actionProviders.add(provider);
}
}
public static List<IAction> getNeighborActions(Block block, TileEntity entity) { public static List<IAction> getNeighborActions(Block block, TileEntity entity) {
List<IAction> result = new LinkedList<IAction>(); List<IAction> result = new LinkedList<IAction>();
@ -100,7 +107,7 @@ public final class StatementManager {
return result; return result;
} }
public static List<IAction> getPipeActions(IPipeTile pipe) { public static List<IAction> getPipeActions(IPipeTile pipe) {
List<IAction> result = new LinkedList<IAction>(); List<IAction> result = new LinkedList<IAction>();
@ -118,4 +125,20 @@ public final class StatementManager {
return result; 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;
}
} }

View file

@ -27,6 +27,7 @@ import net.minecraftforge.oredict.OreDictionary;
import buildcraft.api.blueprints.SchematicRegistry; import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.api.gates.StatementManager; import buildcraft.api.gates.StatementManager;
import buildcraft.api.gates.TriggerParameter;
import buildcraft.api.recipes.BuildcraftRecipeRegistry; import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
import buildcraft.builders.schematics.SchematicRotateMeta; import buildcraft.builders.schematics.SchematicRotateMeta;
@ -69,6 +70,8 @@ import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionRedstoneFader;
import buildcraft.transport.gates.GateExpansionTimer; import buildcraft.transport.gates.GateExpansionTimer;
import buildcraft.transport.gates.ItemGate; 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) @Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT)
public class BuildCraftSilicon extends BuildCraftMod { public class BuildCraftSilicon extends BuildCraftMod {
@ -142,6 +145,10 @@ public class BuildCraftSilicon extends BuildCraftMod {
} }
SiliconProxy.proxy.registerRenderers(); 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() { public static void loadRecipes() {

View file

@ -9,6 +9,8 @@
package buildcraft.core.triggers; package buildcraft.core.triggers;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
public abstract class BCAction extends BCStatement implements IAction { public abstract class BCAction extends BCStatement implements IAction {
@ -16,4 +18,13 @@ public abstract class BCAction extends BCStatement implements IAction {
super(uniqueTag); super(uniqueTag);
} }
@Override
public IActionParameter createParameter(int index) {
return null;
}
@Override
public void actionActivate(IGate gate, IActionParameter[] parameters) {
}
} }

View file

@ -15,9 +15,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.gates.IStatement; import buildcraft.api.gates.IStatement;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.StatementManager; import buildcraft.api.gates.StatementManager;
import buildcraft.api.gates.TriggerParameter;
public abstract class BCStatement implements IStatement { public abstract class BCStatement implements IStatement {
@ -72,9 +70,4 @@ public abstract class BCStatement implements IStatement {
return ""; return "";
} }
@Override
public ITriggerParameter createParameter(int index) {
return new TriggerParameter();
}
} }

View file

@ -12,9 +12,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; 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 * 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 @Override
public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters) { public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) {
ITriggerParameter p = parameters[0]; ITriggerParameter p = parameters[0];
Pipe pipe = (Pipe) gate.getPipe();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (isTriggerActive(side.getOpposite(), pipe.getAdjacentTile(side), p)) { if (isTriggerActive(side.getOpposite(), pipe.getAdjacentTile(side), p)) {
@ -44,4 +47,9 @@ public abstract class BCTrigger extends BCStatement implements ITrigger {
return false; return false;
} }
@Override
public ITriggerParameter createParameter(int index) {
return new TriggerParameter();
}
} }

View file

@ -10,9 +10,9 @@ package buildcraft.core.triggers;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
@ -31,8 +31,8 @@ public class TriggerRedstoneInput extends BCTrigger {
} }
@Override @Override
public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameters) { public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) {
return !(active ^ isBeingPowered((Pipe) pipe, direction)); return !(active ^ isBeingPowered((Pipe) gate.getPipe(), gate.getSide()));
} }
private boolean isBeingPowered(Pipe pipe, ForgeDirection direction) { private boolean isBeingPowered(Pipe pipe, ForgeDirection direction) {

View file

@ -37,6 +37,7 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.StatementManager; import buildcraft.api.gates.StatementManager;
import buildcraft.api.gates.TriggerParameter; import buildcraft.api.gates.TriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
import buildcraft.core.GuiIds; import buildcraft.core.GuiIds;
import buildcraft.core.triggers.ActionRedstoneOutput; import buildcraft.core.triggers.ActionRedstoneOutput;
@ -45,7 +46,6 @@ import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.ItemGate; import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.triggers.ActionRedstoneFaderOutput; import buildcraft.transport.triggers.ActionRedstoneFaderOutput;
import buildcraft.transport.triggers.ActionSignalOutput;
public final class Gate implements IGate { public final class Gate implements IGate {
@ -161,6 +161,7 @@ public final class Gate implements IGate {
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if (triggerParameters[i][j] != null) { if (triggerParameters[i][j] != null) {
NBTTagCompound cpt = new NBTTagCompound(); NBTTagCompound cpt = new NBTTagCompound();
cpt.setString("kind", StatementManager.getParameterKind(triggerParameters[i][j]));
triggerParameters[i][j].writeToNBT(cpt); triggerParameters[i][j].writeToNBT(cpt);
data.setTag("triggerParameters[" + i + "][" + j + "]", cpt); data.setTag("triggerParameters[" + i + "][" + j + "]", cpt);
} }
@ -169,6 +170,7 @@ public final class Gate implements IGate {
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if (actionParameters[i][j] != null) { if (actionParameters[i][j] != null) {
NBTTagCompound cpt = new NBTTagCompound(); NBTTagCompound cpt = new NBTTagCompound();
cpt.setString("kind", StatementManager.getParameterKind(actionParameters[i][j]));
actionParameters[i][j].writeToNBT(cpt); actionParameters[i][j].writeToNBT(cpt);
data.setTag("actionParameters[" + i + "][" + j + "]", cpt); data.setTag("actionParameters[" + i + "][" + j + "]", cpt);
} }
@ -200,19 +202,18 @@ public final class Gate implements IGate {
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) { if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) {
NBTTagCompound cpt = new NBTTagCompound(); NBTTagCompound cpt = data.getCompoundTag("triggerParameters[" + i + "][" + j + "]");
// we need the real parameter type here triggerParameters[i][j] = (ITriggerParameter) StatementManager.createParameter(cpt
triggerParameters[i][j] = new TriggerParameter(); .getString("kind"));
triggerParameters[i][j].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "][" + j + "]")); triggerParameters[i][j].readFromNBT(cpt);
} }
} }
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) { if (data.hasKey("actionParameters[" + i + "][" + j + "]")) {
NBTTagCompound cpt = new NBTTagCompound(); NBTTagCompound cpt = data.getCompoundTag("actionParameters[" + i + "][" + j + "]");
// actionParameters[i][j] = new ActionParameter(); actionParameters[i][j] = (IActionParameter) StatementManager.createParameter(cpt.getString("kind"));
// actionParameters[i][j].readFromNBT(data.getCompoundTag("actionParameters[" actionParameters[i][j].readFromNBT(cpt);
// + i + "][" + j + "]"));
} }
} }
} }
@ -345,9 +346,13 @@ public final class Gate implements IGate {
} }
// Activate the actions // Activate the actions
for (Map.Entry<IAction, Boolean> entry : activeActions.entrySet()) { for (int it = 0; it < activeActions.size(); ++it) {
if (entry.getValue()) { if (actionsState[it] == ActionState.Activated) {
IAction action = entry.getKey(); 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. // Custom gate actions take precedence over defaults.
if (resolveAction(action, actionCount.count(action))) { if (resolveAction(action, actionCount.count(action))) {
@ -358,8 +363,6 @@ public final class Gate implements IGate {
redstoneOutput = 15; redstoneOutput = 15;
} else if (action instanceof ActionRedstoneFaderOutput) { } else if (action instanceof ActionRedstoneFaderOutput) {
redstoneOutput = ((ActionRedstoneFaderOutput) action).level; redstoneOutput = ((ActionRedstoneFaderOutput) action).level;
} else if (action instanceof ActionSignalOutput) {
broadcastSignal.set(((ActionSignalOutput) action).color.ordinal());
} else { } else {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = pipe.container.getTile(side); TileEntity tile = pipe.container.getTile(side);
@ -401,7 +404,7 @@ public final class Gate implements IGate {
return false; return false;
} }
if (trigger.isTriggerActive(pipe, direction, parameters)) { if (trigger.isTriggerActive(this, parameters)) {
return true; return true;
} }
@ -444,6 +447,7 @@ public final class Gate implements IGate {
} }
} }
@Override
public void setPulsing (boolean pulsing) { public void setPulsing (boolean pulsing) {
if (pulsing != isPulsing) { if (pulsing != isPulsing) {
isPulsing = pulsing; isPulsing = pulsing;
@ -454,4 +458,18 @@ public final class Gate implements IGate {
public float getPulseStage () { public float getPulseStage () {
return pulseStage; return pulseStage;
} }
public void broadcastSignal(PipeWire color) {
broadcastSignal.set(color.ordinal());
}
@Override
public IPipe getPipe() {
return pipe;
}
@Override
public ForgeDirection getSide() {
return direction;
}
} }

View file

@ -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 * * ACTIONS *
*/ */

View file

@ -22,6 +22,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IStatement; import buildcraft.api.gates.IStatement;
import buildcraft.api.gates.IStatementParameter; import buildcraft.api.gates.IStatementParameter;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
@ -124,7 +125,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override @Override
public boolean isDefined() { public boolean isDefined() {
return gate.getTriggerParameter(statementSlot.slot, slot) != null; return getParameter() != null;
} }
@Override @Override
@ -158,6 +159,8 @@ public class GuiGateInterface extends GuiAdvancedInterface {
public boolean isRequired() { public boolean isRequired() {
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters(); return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters();
} }
public abstract void setParameter(IStatementParameter param, boolean notifyServer);
} }
class TriggerParameterSlot extends StatementParameterSlot { class TriggerParameterSlot extends StatementParameterSlot {
@ -169,6 +172,11 @@ public class GuiGateInterface extends GuiAdvancedInterface {
public IStatementParameter getParameter() { public IStatementParameter getParameter() {
return gate.getTriggerParameter(statementSlot.slot, slot); 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 { class ActionParameterSlot extends StatementParameterSlot {
@ -180,6 +188,11 @@ public class GuiGateInterface extends GuiAdvancedInterface {
public IStatementParameter getParameter() { public IStatementParameter getParameter() {
return gate.getActionParameter(statementSlot.slot, slot); 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) { public GuiGateInterface(IInventory playerInventory, Pipe pipe) {
@ -335,26 +348,21 @@ public class GuiGateInterface extends GuiAdvancedInterface {
if (slot instanceof TriggerSlot) { if (slot instanceof TriggerSlot) {
boolean halfWidth = container.actionsState[actionTracker] == ActionState.Partial; boolean halfWidth = container.actionsState[actionTracker] == ActionState.Partial;
if (gate.material.numTriggerParameters > 0) { if (container.actionsState[actionTracker] != ActionState.Deactivated) {
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) {
mc.renderEngine.bindTexture(texture); 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++; actionTracker++;
} else if (slot instanceof StatementParameterSlot) { } else if (slot instanceof StatementParameterSlot) {
StatementParameterSlot paramSlot = (StatementParameterSlot) slot; StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
StatementSlot trigger = paramSlot.statementSlot; StatementSlot statement = paramSlot.statementSlot;
mc.renderEngine.bindTexture(texture); mc.renderEngine.bindTexture(texture);
if (trigger.isDefined()) { if (statement.isDefined()) {
if (!paramSlot.isAllowed()) { if (!paramSlot.isAllowed()) {
drawTexturedModalRect(cornerX + slot.x - 1, cornerY + slot.y - 1, 176, 0, 18, 18); drawTexturedModalRect(cornerX + slot.x - 1, cornerY + slot.y - 1, 176, 0, 18, 18);
} else if (paramSlot.isRequired() && paramSlot.getItemStack() == null) { } else if (paramSlot.isRequired() && paramSlot.getItemStack() == null) {
@ -464,16 +472,24 @@ public class GuiGateInterface extends GuiAdvancedInterface {
} else { } else {
container.setAction(actionSlot.slot, changed.getUniqueTag(), true); 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) { for (StatementParameterSlot p : actionSlot.parameters) {
ITriggerParameter param = (ITriggerParameter) trigger.getStatement().createParameter(paramSlot.slot); 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) { if (param != null) {
param.clicked(pipe.container, trigger.getStatement(), mc.thePlayer.inventory.getItemStack()); param.clicked(pipe.container, statement.getStatement(), mc.thePlayer.inventory.getItemStack());
container.setTriggerParameter(trigger.slot, paramSlot.slot, param, true); paramSlot.setParameter(param, true);
} }
} }
} }

View file

@ -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")];
}
}
}

View file

@ -11,10 +11,13 @@ package buildcraft.transport.triggers;
import java.util.Locale; import java.util.Locale;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.StatementIconProvider; import buildcraft.core.triggers.StatementIconProvider;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate;
public class ActionSignalOutput extends BCAction { public class ActionSignalOutput extends BCAction {
@ -50,4 +53,31 @@ public class ActionSignalOutput extends BCAction {
public IAction rotateLeft() { public IAction rotateLeft() {
return this; 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);
}
}
}
}
} }

View file

@ -22,19 +22,15 @@ import buildcraft.core.triggers.StatementIconProvider;
public class TriggerParameterSignal implements ITriggerParameter { public class TriggerParameterSignal implements ITriggerParameter {
@NetworkData @NetworkData
private boolean active; public boolean active = false;
@NetworkData @NetworkData
private PipeWire color = PipeWire.RED; public PipeWire color = null;
public TriggerParameterSignal() { public TriggerParameterSignal() {
} }
public TriggerParameterSignal(TriggerPipeSignal trigger) {
}
@Override @Override
public ItemStack getItemStackToDraw() { public ItemStack getItemStackToDraw() {
return null; return null;
@ -44,6 +40,10 @@ public class TriggerParameterSignal implements ITriggerParameter {
public IIcon getIconToDraw() { public IIcon getIconToDraw() {
int id = 0; int id = 0;
if (color == null) {
return null;
}
if (active) { if (active) {
switch (color) { switch (color) {
case RED: case RED:
@ -81,18 +81,35 @@ public class TriggerParameterSignal implements ITriggerParameter {
@Override @Override
public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) { public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) {
if (stmt instanceof TriggerPipeSignal) { if (color == null) {
TriggerPipeSignal signal = (TriggerPipeSignal) stmt; 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 @Override
public void writeToNBT(NBTTagCompound compound) { public void readFromNBT(NBTTagCompound nbt) {
} active = nbt.getBoolean("active");
@Override if (nbt.hasKey("color")) {
public void readFromNBT(NBTTagCompound compound) { color = PipeWire.values()[nbt.getByte("color")];
}
} }
} }

View file

@ -21,9 +21,9 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
@ -72,11 +72,12 @@ public class TriggerPipeContents extends BCTrigger {
} }
@Override @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]; ITriggerParameter parameter = parameters[0];
if (((Pipe) pipe).transport instanceof PipeTransportItems) { if (pipe.transport instanceof PipeTransportItems) {
PipeTransportItems transportItems = (PipeTransportItems) ((Pipe) pipe).transport; PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
if (kind == PipeContents.empty) { if (kind == PipeContents.empty) {
return transportItems.items.isEmpty(); return transportItems.items.isEmpty();
} else if (kind == PipeContents.containsItems) { } else if (kind == PipeContents.containsItems) {
@ -92,8 +93,8 @@ public class TriggerPipeContents extends BCTrigger {
return !transportItems.items.isEmpty(); return !transportItems.items.isEmpty();
} }
} }
} else if (((Pipe) pipe).transport instanceof PipeTransportFluids) { } else if (pipe.transport instanceof PipeTransportFluids) {
PipeTransportFluids transportFluids = (PipeTransportFluids) ((Pipe) pipe).transport; PipeTransportFluids transportFluids = (PipeTransportFluids) pipe.transport;
FluidStack searchedFluid = null; FluidStack searchedFluid = null;
@ -120,8 +121,8 @@ public class TriggerPipeContents extends BCTrigger {
return false; return false;
} }
} else if (((Pipe) pipe).transport instanceof PipeTransportPower) { } else if (pipe.transport instanceof PipeTransportPower) {
PipeTransportPower transportPower = (PipeTransportPower) ((Pipe) pipe).transport; PipeTransportPower transportPower = (PipeTransportPower) pipe.transport;
switch (kind) { switch (kind) {
case empty: case empty:

View file

@ -10,11 +10,9 @@ package buildcraft.transport.triggers;
import java.util.Locale; import java.util.Locale;
import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.gates.IGate;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.PipeWire; import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.triggers.StatementIconProvider; import buildcraft.core.triggers.StatementIconProvider;
@ -45,12 +43,38 @@ public class TriggerPipeSignal extends BCTrigger {
} }
@Override @Override
public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameter) { public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameters) {
Pipe pipe = (Pipe) gate.getPipe();
if (active) { if (active) {
return ((Pipe) pipe).signalStrength[color.ordinal()] > 0; if (pipe.signalStrength[color.ordinal()] == 0) {
return false;
}
} else { } 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 @Override
@ -89,6 +113,6 @@ public class TriggerPipeSignal extends BCTrigger {
@Override @Override
public ITriggerParameter createParameter(int index) { public ITriggerParameter createParameter(int index) {
return new TriggerParameterSignal(this); return new TriggerParameterSignal();
} }
} }

View file

@ -14,11 +14,9 @@ import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; 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.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
@ -41,8 +39,8 @@ public class TriggerRedstoneFaderInput extends BCTrigger {
} }
@Override @Override
public boolean isTriggerActive(IPipe pipe, ForgeDirection direction, ITriggerParameter[] parameter) { public boolean isTriggerActive(IGate gate, ITriggerParameter[] parameter) {
return ((TileGenericPipe) pipe.getTile()).redstoneInput[direction.ordinal()] == level; return ((TileGenericPipe) gate.getPipe().getTile()).redstoneInput[gate.getSide().ordinal()] == level;
} }
@Override @Override