fixed various regressions with gates logic
This commit is contained in:
parent
036f257505
commit
ffcd8188de
10 changed files with 108 additions and 91 deletions
|
@ -57,7 +57,8 @@ public class ActionParameterItemStack implements IActionParameter {
|
|||
if (object instanceof ActionParameterItemStack) {
|
||||
ActionParameterItemStack param = (ActionParameterItemStack) object;
|
||||
|
||||
return ItemStack.areItemStackTagsEqual(stack, param.stack);
|
||||
return ItemStack.areItemStacksEqual(stack, param.stack)
|
||||
&& ItemStack.areItemStackTagsEqual(stack, param.stack);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
package buildcraft.transport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -38,6 +39,7 @@ import buildcraft.api.transport.IPipe;
|
|||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.core.triggers.ActionRedstoneOutput;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.gates.GateDefinition.GateLogic;
|
||||
import buildcraft.transport.gates.GateDefinition.GateMaterial;
|
||||
import buildcraft.transport.gates.ItemGate;
|
||||
|
@ -61,6 +63,7 @@ public final class Gate implements IGate {
|
|||
public IActionParameter[][] actionParameters = new IActionParameter[8][MAX_PARAMETERS];
|
||||
|
||||
public ActionActiveState[] actionsState = new ActionActiveState[MAX_STATEMENTS];
|
||||
public ArrayList<ActionSlot> activeActions = new ArrayList<ActionSlot>();
|
||||
|
||||
public BitSet broadcastSignal = new BitSet(PipeWire.VALUES.length);
|
||||
public BitSet prevBroadcastSignal = new BitSet(PipeWire.VALUES.length);
|
||||
|
@ -340,60 +343,80 @@ public final class Gate implements IGate {
|
|||
ITriggerParameter[] parameter = triggerParameters[it];
|
||||
|
||||
if (trigger != null) {
|
||||
boolean active = isTriggerActive(trigger, parameter);
|
||||
if (isTriggerActive(trigger, parameter)) {
|
||||
actionsState[it] = ActionActiveState.Partial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (actionGroups[it] == it) {
|
||||
if (active) {
|
||||
actionsState[it] = ActionActiveState.Activated;
|
||||
}
|
||||
} else {
|
||||
if (active && actionsState[actionGroups[it]] != ActionActiveState.Activated) {
|
||||
actionsState[actionGroups[it]] = ActionActiveState.Partial;
|
||||
} else if (!active && actionsState[actionGroups[it]] == ActionActiveState.Activated) {
|
||||
actionsState[actionGroups[it]] = ActionActiveState.Partial;
|
||||
activeActions = new ArrayList<ActionSlot>();
|
||||
|
||||
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
||||
boolean andActivate = true;
|
||||
boolean orActivate = false;
|
||||
|
||||
if (actions[it] == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < MAX_STATEMENTS; ++j) {
|
||||
if (actionGroups[j] == it) {
|
||||
if (actionsState[j] != ActionActiveState.Partial) {
|
||||
andActivate = false;
|
||||
} else {
|
||||
orActivate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((logic == GateLogic.AND && andActivate) || (logic == GateLogic.OR && orActivate)) {
|
||||
if (logic == GateLogic.AND) {
|
||||
for (int j = 0; j < MAX_STATEMENTS; ++j) {
|
||||
if (actionGroups[j] == it) {
|
||||
actionsState[j] = ActionActiveState.Activated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ActionSlot slot = new ActionSlot();
|
||||
slot.action = actions[it];
|
||||
slot.parameters = actionParameters[it];
|
||||
activeActions.add(slot);
|
||||
}
|
||||
|
||||
if (logic == GateLogic.OR && actionsState[it] == ActionActiveState.Partial) {
|
||||
actionsState[it] = ActionActiveState.Activated;
|
||||
}
|
||||
}
|
||||
|
||||
// Activate the actions
|
||||
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
||||
if (actions[it] != null && actionGroups[it] == it && actionsState[it] == ActionActiveState.Activated) {
|
||||
IAction action = actions[it];
|
||||
action.actionActivate(this, actionParameters[it]);
|
||||
for (ActionSlot slot : activeActions) {
|
||||
IAction action = slot.action;
|
||||
action.actionActivate(this, slot.parameters);
|
||||
|
||||
// TODO: A lot of the code below should be removed in favor
|
||||
// of calls to actionActivate
|
||||
// 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)) {
|
||||
continue;
|
||||
}
|
||||
// Custom gate actions take precedence over defaults.
|
||||
if (resolveAction(action)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action instanceof ActionRedstoneOutput) {
|
||||
redstoneOutput = 15;
|
||||
} else if (action instanceof ActionRedstoneFaderOutput) {
|
||||
redstoneOutput = ((ActionRedstoneFaderOutput) action).level;
|
||||
} else {
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity tile = pipe.container.getTile(side);
|
||||
if (tile instanceof IActionReceptor) {
|
||||
IActionReceptor recept = (IActionReceptor) tile;
|
||||
recept.actionActivated(action);
|
||||
}
|
||||
if (action instanceof ActionRedstoneOutput) {
|
||||
redstoneOutput = 15;
|
||||
} else if (action instanceof ActionRedstoneFaderOutput) {
|
||||
redstoneOutput = ((ActionRedstoneFaderOutput) action).level;
|
||||
} else {
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity tile = pipe.container.getTile(side);
|
||||
if (tile instanceof IActionReceptor) {
|
||||
IActionReceptor recept = (IActionReceptor) tile;
|
||||
recept.actionActivated(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<IAction> activeActions = new LinkedList<IAction>();
|
||||
|
||||
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
||||
if (actionGroups[it] == it && actionsState[it] == ActionActiveState.Activated) {
|
||||
activeActions.add(actions[it]);
|
||||
}
|
||||
}
|
||||
|
||||
pipe.actionsActivated(activeActions);
|
||||
|
||||
if (oldRedstoneOutput != redstoneOutput) {
|
||||
|
|
|
@ -43,6 +43,7 @@ import buildcraft.core.IDropControlInventory;
|
|||
import buildcraft.core.inventory.InvUtils;
|
||||
import buildcraft.core.network.TilePacketWrapper;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.gates.GateFactory;
|
||||
import buildcraft.transport.pipes.events.PipeEvent;
|
||||
|
||||
|
@ -552,7 +553,7 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
|
|||
container.scheduleRenderUpdate();
|
||||
}
|
||||
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
}
|
||||
|
||||
public TileGenericPipe getContainer() {
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Iterator;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.transport.ActionActiveState;
|
||||
import buildcraft.transport.Gate;
|
||||
import buildcraft.transport.Pipe;
|
||||
|
||||
|
@ -37,20 +36,19 @@ public class ActionIterator implements Iterable<ActionSlot> {
|
|||
|
||||
public It() {
|
||||
while (!isValid()) {
|
||||
if (index < Gate.MAX_STATEMENTS - 1) {
|
||||
index++;
|
||||
} else if (curDir != ForgeDirection.UNKNOWN) {
|
||||
if (curDir == ForgeDirection.UNKNOWN) {
|
||||
break;
|
||||
} else if (pipe.gates[curDir.ordinal()] == null
|
||||
|| index >= pipe.gates[curDir.ordinal()].activeActions.size() - 1) {
|
||||
index = 0;
|
||||
curDir = ForgeDirection.values()[curDir.ordinal() + 1];
|
||||
} else {
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isValid()) {
|
||||
next = new ActionSlot();
|
||||
next.action = pipe.gates[curDir.ordinal()].actions[index];
|
||||
next.parameters = pipe.gates[curDir.ordinal()].actionParameters[index];
|
||||
next = pipe.gates[curDir.ordinal()].activeActions.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,21 +93,9 @@ public class ActionIterator implements Iterable<ActionSlot> {
|
|||
}
|
||||
|
||||
private boolean isValid() {
|
||||
if (curDir == ForgeDirection.UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Gate gate = pipe.gates[curDir.ordinal()];
|
||||
|
||||
if (gate == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gate.actions[index] == null || gate.actionsState[index] != ActionActiveState.Activated) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return curDir != ForgeDirection.UNKNOWN
|
||||
&& pipe.gates[curDir.ordinal()] != null
|
||||
&& index < pipe.gates[curDir.ordinal()].activeActions.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import buildcraft.transport.Pipe;
|
|||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportFluids;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.triggers.ActionPipeDirection;
|
||||
|
||||
public class PipeFluidsIron extends Pipe<PipeTransportFluids> {
|
||||
|
@ -101,12 +102,12 @@ public class PipeFluidsIron extends Pipe<PipeTransportFluids> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action).direction);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action.action).direction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import buildcraft.transport.PipeTransportItems;
|
|||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.TransportConstants;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.pipes.events.PipeEventItem;
|
||||
import buildcraft.transport.triggers.ActionPipeColor;
|
||||
import buildcraft.transport.triggers.ActionPipeDirection;
|
||||
|
@ -152,19 +153,19 @@ public class PipeItemsDaizuli extends Pipe<PipeTransportItems> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPipeColor) {
|
||||
setColor(((ActionPipeColor) action).color);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPipeColor) {
|
||||
setColor(((ActionPipeColor) action.action).color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action).direction);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action.action).direction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import buildcraft.core.utils.EnumColor;
|
|||
import buildcraft.transport.BlockGenericPipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.triggers.ActionExtractionPreset;
|
||||
|
||||
public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler {
|
||||
|
@ -141,14 +142,14 @@ public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
activeFlags.clear();
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionExtractionPreset) {
|
||||
setActivePreset(((ActionExtractionPreset) action).color);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionExtractionPreset) {
|
||||
setActivePreset(((ActionExtractionPreset) action.action).color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import buildcraft.transport.Pipe;
|
|||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.triggers.ActionPipeDirection;
|
||||
|
||||
public class PipeItemsIron extends Pipe<PipeTransportItems> {
|
||||
|
@ -110,12 +111,12 @@ public class PipeItemsIron extends Pipe<PipeTransportItems> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action).direction);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPipeDirection) {
|
||||
logic.setFacing(((ActionPipeDirection) action.action).direction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import buildcraft.transport.PipeIconProvider;
|
|||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TransportConstants;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.pipes.events.PipeEventItem;
|
||||
import buildcraft.transport.triggers.ActionPipeColor;
|
||||
|
||||
|
@ -99,12 +100,12 @@ public class PipeItemsLapis extends Pipe<PipeTransportItems> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPipeColor) {
|
||||
setColor(((ActionPipeColor) action).color);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPipeColor) {
|
||||
setColor(((ActionPipeColor) action.action).color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import buildcraft.core.utils.StringUtils;
|
|||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.PipeIconProvider;
|
||||
import buildcraft.transport.PipeTransportPower;
|
||||
import buildcraft.transport.gates.ActionSlot;
|
||||
import buildcraft.transport.triggers.ActionPowerLimiter;
|
||||
|
||||
public class PipePowerIron extends Pipe<PipeTransportPower> {
|
||||
|
@ -119,12 +120,12 @@ public class PipePowerIron extends Pipe<PipeTransportPower> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionsActivated(Collection<IAction> actions) {
|
||||
protected void actionsActivated(Collection<ActionSlot> actions) {
|
||||
super.actionsActivated(actions);
|
||||
|
||||
for (IAction action : actions) {
|
||||
if (action instanceof ActionPowerLimiter) {
|
||||
setMode(((ActionPowerLimiter) action).limit);
|
||||
for (ActionSlot action : actions) {
|
||||
if (action.action instanceof ActionPowerLimiter) {
|
||||
setMode(((ActionPowerLimiter) action.action).limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue