use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.
the class GateLogic method resolveActions.
public void resolveActions() {
int groupCount = 0;
int groupActive = 0;
boolean[] prevTriggers = Arrays.copyOf(triggerOn, triggerOn.length);
boolean[] prevActions = Arrays.copyOf(actionOn, actionOn.length);
Arrays.fill(triggerOn, false);
Arrays.fill(actionOn, false);
activeActions.clear();
EnumSet<EnumDyeColor> previousBroadcasts = EnumSet.copyOf(wireBroadcasts);
wireBroadcasts.clear();
for (int triggerIndex = 0; triggerIndex < statements.length; triggerIndex++) {
StatementPair pair = statements[triggerIndex];
TriggerWrapper trigger = pair.trigger.get();
groupCount++;
if (trigger != null) {
IStatementParameter[] params = new IStatementParameter[pair.trigger.getParamCount()];
for (int p = 0; p < pair.trigger.getParamCount(); p++) {
params[p] = pair.trigger.getParamRef(p).get();
}
if (trigger.isTriggerActive(this, params)) {
groupActive++;
triggerOn[triggerIndex] = true;
}
}
if (connections.length == triggerIndex || !connections[triggerIndex]) {
boolean allActionsActive;
if (variant.logic == EnumGateLogic.AND) {
allActionsActive = groupActive == groupCount;
} else {
allActionsActive = groupActive > 0;
}
for (int i = groupCount - 1; i >= 0; i--) {
int actionIndex = triggerIndex - i;
StatementPair fullAction = statements[actionIndex];
ActionWrapper action = fullAction.action.get();
actionOn[actionIndex] = allActionsActive;
if (action != null) {
if (allActionsActive) {
StatementSlot slot = new StatementSlot();
slot.statement = action.delegate;
slot.parameters = fullAction.action.getParameters().clone();
slot.part = action.sourcePart;
activeActions.add(slot);
action.actionActivate(this, slot.parameters);
PipeEvent evt = new PipeEventActionActivate(getPipeHolder(), action.getDelegate(), slot.parameters, action.sourcePart);
getPipeHolder().fireEvent(evt);
} else {
action.actionDeactivated(this, fullAction.action.getParameters());
}
}
}
groupActive = 0;
groupCount = 0;
}
}
if (!previousBroadcasts.equals(wireBroadcasts)) {
IWireManager wires = getPipeHolder().getWireManager();
EnumSet<EnumDyeColor> turnedOff = EnumSet.copyOf(previousBroadcasts);
turnedOff.removeAll(wireBroadcasts);
// FIXME: add call to "wires.stopEmittingColour(turnedOff)"
EnumSet<EnumDyeColor> turnedOn = EnumSet.copyOf(wireBroadcasts);
turnedOn.removeAll(previousBroadcasts);
if (!getPipeHolder().getPipeWorld().isRemote) {
WorldSavedDataWireSystems.get(getPipeHolder().getPipeWorld()).gatesChanged = true;
}
}
if (!Arrays.equals(prevTriggers, triggerOn) || !Arrays.equals(prevActions, actionOn)) {
sendResolveData();
}
}
use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.
the class ActionPipeSignal method actionActivate.
@Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
if (!(container instanceof IWireEmitter)) {
return;
}
IWireEmitter emitter = (IWireEmitter) container;
emitter.emitWire(colour);
for (IStatementParameter param : parameters) {
if (param != null && param instanceof ActionParameterSignal) {
ActionParameterSignal signal = (ActionParameterSignal) param;
if (signal.getColor() != null) {
emitter.emitWire(signal.getColor());
}
}
}
}
use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.
the class FullStatement method writeToBuffer.
public void writeToBuffer(PacketBufferBC buffer) {
if (statement == null) {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
type.writeToBuffer(buffer, statement);
for (int p = 0; p < params.length; p++) {
IStatementParameter param = params[p];
StatementTypeParam.INSTANCE.writeToBuffer(buffer, param);
}
}
}
use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.
the class GuiGateInterface method mouseReleased.
@Override
protected void mouseReleased(int mouseX, int mouseY, int eventType) {
super.mouseReleased(mouseX, mouseY, eventType);
if (index >= 0) {
int i = index;
index = -1;
IStatement changeTo;
Iterator<IStatement> it;
if (trigger)
it = container.getTriggerIterator(false);
else
it = container.getActionIterator(false);
do {
changeTo = it.next();
i--;
} while (i >= 0);
AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
if (slot == null)
return;
if (trigger && slot instanceof TriggerSlot) {
TriggerSlot trig = (TriggerSlot) slot;
container.setTrigger(trig.slot, changeTo.getUniqueTag(), true);
for (StatementParameterSlot p : trig.parameters) {
IStatementParameter parameter = null;
if (p.slot < changeTo.minParameters()) {
parameter = changeTo.createParameter(p.slot);
}
container.setTriggerParameter(trig.slot, p.slot, parameter, true);
}
}
if (!trigger && slot instanceof ActionSlot) {
ActionSlot trig = (ActionSlot) slot;
container.setAction(trig.slot, changeTo.getUniqueTag(), true);
for (StatementParameterSlot p : trig.parameters) {
IStatementParameter parameter = null;
if (p.slot < changeTo.minParameters()) {
parameter = changeTo.createParameter(p.slot);
}
container.setActionParameter(trig.slot, p.slot, parameter, true);
}
}
}
}
use of buildcraft.api.statements.IStatementParameter in project BuildCraft by BuildCraft.
the class ActionRobotFilter method getGateFilterStacks.
public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
ArrayList<ItemStack> result = new ArrayList<>();
for (StatementSlot slot : station.getActiveActions()) {
if (slot.statement instanceof ActionRobotFilter) {
for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) {
StatementParameterItemStack param = (StatementParameterItemStack) p;
ItemStack stack = param.getItemStack();
if (stack != null) {
result.add(stack);
}
}
}
}
}
return result;
}
Aggregations