use of buildcraft.api.transport.IWireManager in project BuildCraft by BuildCraft.
the class WireManager method updateBetweens.
@Override
public void updateBetweens(boolean recursive) {
betweens.clear();
parts.forEach((part, color) -> {
for (EnumWireBetween between : EnumWireBetween.VALUES) {
EnumWirePart[] betweenParts = between.parts;
if (between.to == null) {
if ((betweenParts[0] == part && getColorOfPart(betweenParts[1]) == color) || (betweenParts[1] == part && getColorOfPart(betweenParts[0]) == color)) {
betweens.put(between, color);
}
} else if (WireSystem.canWireConnect(holder, between.to)) {
IPipe pipe = holder.getNeighbourPipe(between.to);
if (pipe != null) {
IWireManager wireManager = pipe.getHolder().getWireManager();
if (betweenParts[0] == part && wireManager.getColorOfPart(betweenParts[1]) == color) {
betweens.put(between, color);
}
}
}
}
});
if (!recursive) {
for (EnumFacing side : EnumFacing.VALUES) {
TileEntity tile = holder.getPipeWorld().getTileEntity(holder.getPipePos().offset(side));
if (tile instanceof IPipeHolder) {
((IPipeHolder) tile).getWireManager().updateBetweens(true);
}
}
}
}
use of buildcraft.api.transport.IWireManager in project BuildCraft by BuildCraft.
the class TriggerPipeSignal method isTriggerActive.
@Override
public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) {
if (!(container instanceof IGate)) {
return false;
}
IGate gate = (IGate) container;
IWireManager wires = gate.getPipeHolder().getWireManager();
if (active) {
if (!wires.isAnyPowered(colour)) {
return false;
}
} else if (wires.isAnyPowered(colour)) {
return false;
}
for (IStatementParameter param : parameters) {
if (param != null && param instanceof TriggerParameterSignal) {
TriggerParameterSignal signal = (TriggerParameterSignal) param;
if (signal.colour != null) {
if (!wires.isAnyPowered(signal.colour)) {
return false;
}
} else if (wires.isAnyPowered(signal.colour)) {
return false;
}
}
}
return true;
}
use of buildcraft.api.transport.IWireManager 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();
}
}
Aggregations