Add in a few tweaks to autarchic gates - stacks of items if 8 pulses are set, and a "single edge" trigger mode.
This commit is contained in:
parent
69ac580b3f
commit
276cacdef6
7 changed files with 84 additions and 38 deletions
|
@ -68,6 +68,7 @@ import buildcraft.transport.pipes.PipePowerWood;
|
||||||
import buildcraft.transport.pipes.PipeStructureCobblestone;
|
import buildcraft.transport.pipes.PipeStructureCobblestone;
|
||||||
import buildcraft.transport.triggers.ActionEnergyPulser;
|
import buildcraft.transport.triggers.ActionEnergyPulser;
|
||||||
import buildcraft.transport.triggers.ActionSignalOutput;
|
import buildcraft.transport.triggers.ActionSignalOutput;
|
||||||
|
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
|
||||||
import buildcraft.transport.triggers.TriggerPipeContents;
|
import buildcraft.transport.triggers.TriggerPipeContents;
|
||||||
import buildcraft.transport.triggers.TriggerPipeContents.Kind;
|
import buildcraft.transport.triggers.TriggerPipeContents.Kind;
|
||||||
import buildcraft.transport.triggers.TriggerPipeSignal;
|
import buildcraft.transport.triggers.TriggerPipeSignal;
|
||||||
|
@ -160,6 +161,7 @@ public class BuildCraftTransport {
|
||||||
public static Action actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, IPipe.WireColor.Green);
|
public static Action actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, IPipe.WireColor.Green);
|
||||||
public static Action actionYellowSignal = new ActionSignalOutput(DefaultProps.ACTION_YELLOW_SIGNAL, IPipe.WireColor.Yellow);
|
public static Action actionYellowSignal = new ActionSignalOutput(DefaultProps.ACTION_YELLOW_SIGNAL, IPipe.WireColor.Yellow);
|
||||||
public static Action actionEnergyPulser = new ActionEnergyPulser(DefaultProps.ACTION_ENERGY_PULSER);
|
public static Action actionEnergyPulser = new ActionEnergyPulser(DefaultProps.ACTION_ENERGY_PULSER);
|
||||||
|
public static Action actionSingleEnergyPulse = new ActionSingleEnergyPulse(DefaultProps.ACTION_SINGLE_ENERGY_PULSE);
|
||||||
|
|
||||||
@Instance("BuildCraft|Transport")
|
@Instance("BuildCraft|Transport")
|
||||||
public static BuildCraftTransport instance;
|
public static BuildCraftTransport instance;
|
||||||
|
|
|
@ -154,4 +154,6 @@ public class DefaultProps {
|
||||||
public static int ACTION_OFF = 7;
|
public static int ACTION_OFF = 7;
|
||||||
public static int ACTION_LOOP = 8;
|
public static int ACTION_LOOP = 8;
|
||||||
public static int ACTION_ENERGY_PULSER = 9;
|
public static int ACTION_ENERGY_PULSER = 9;
|
||||||
|
public static int ACTION_SINGLE_ENERGY_PULSE = 10;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,11 @@ public class EnergyPulser {
|
||||||
|
|
||||||
private IPowerReceptor powerReceptor;
|
private IPowerReceptor powerReceptor;
|
||||||
|
|
||||||
private boolean isActive = false;
|
private boolean isActive;
|
||||||
private float progress = 0;
|
private boolean singlePulse;
|
||||||
private int progressPart = 0;
|
private boolean hasPulsed;
|
||||||
private float pulseSpeed = 0;
|
private int pulseCount;
|
||||||
private int maxHeat = 1000;
|
private int tick;
|
||||||
|
|
||||||
public EnergyPulser(IPowerReceptor receptor) {
|
public EnergyPulser(IPowerReceptor receptor) {
|
||||||
powerReceptor = receptor;
|
powerReceptor = receptor;
|
||||||
}
|
}
|
||||||
|
@ -22,32 +21,39 @@ public class EnergyPulser {
|
||||||
if (powerReceptor == null)
|
if (powerReceptor == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if we are already running
|
if (isActive)
|
||||||
if (progressPart != 0) {
|
{
|
||||||
|
tick++;
|
||||||
progress += getPulseSpeed();
|
if (!singlePulse || !hasPulsed) {
|
||||||
|
if (tick % 10 == 0 || !hasPulsed)
|
||||||
if (progress > 0.5 && progressPart == 1) {
|
{
|
||||||
progressPart = 2;
|
powerReceptor.getPowerProvider().receiveEnergy(Math.max(1 << (pulseCount-1),64), ForgeDirection.WEST);
|
||||||
// Give off energy pulse!
|
if (singlePulse) {
|
||||||
powerReceptor.getPowerProvider().receiveEnergy(1, ForgeDirection.WEST);
|
hasPulsed = true;
|
||||||
|
}
|
||||||
} else if (progress >= 1) {
|
}
|
||||||
progress = 0;
|
}
|
||||||
progressPart = 0;
|
|
||||||
}
|
}
|
||||||
} else if (isActive) {
|
|
||||||
progressPart = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void enableSinglePulse(int count) {
|
||||||
|
singlePulse = true;
|
||||||
public void enablePulse() {
|
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
pulseCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enablePulse(int count) {
|
||||||
|
isActive = true;
|
||||||
|
singlePulse = false;
|
||||||
|
pulseCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disablePulse() {
|
public void disablePulse() {
|
||||||
|
if (!isActive) {
|
||||||
|
hasPulsed = false;
|
||||||
|
}
|
||||||
isActive = false;
|
isActive = false;
|
||||||
|
pulseCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
|
@ -59,14 +65,12 @@ public class EnergyPulser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
nbttagcompound.setBoolean("SinglePulse", singlePulse);
|
||||||
nbttagcompound.setBoolean("IsActive", isActive);
|
nbttagcompound.setBoolean("IsActive", isActive);
|
||||||
nbttagcompound.setShort("ProgressPart", (short) progressPart);
|
|
||||||
nbttagcompound.setFloat("Progress", progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
isActive = nbttagcompound.getBoolean("IsActive");
|
isActive = nbttagcompound.getBoolean("IsActive");
|
||||||
progressPart = nbttagcompound.getShort("ProgressPart");
|
singlePulse = nbttagcompound.getBoolean("SinglePulse");
|
||||||
progress = nbttagcompound.getFloat("Progress");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public abstract class Gate {
|
||||||
|
|
||||||
public abstract void startResolution();
|
public abstract void startResolution();
|
||||||
|
|
||||||
public abstract boolean resolveAction(IAction action);
|
public abstract boolean resolveAction(IAction action, int count);
|
||||||
|
|
||||||
// / TRIGGERS
|
// / TRIGGERS
|
||||||
public abstract void addTrigger(LinkedList<ITrigger> list);
|
public abstract void addTrigger(LinkedList<ITrigger> list);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import buildcraft.core.utils.StringUtil;
|
||||||
import buildcraft.core.utils.Utils;
|
import buildcraft.core.utils.Utils;
|
||||||
import buildcraft.transport.pipes.PipePowerWood;
|
import buildcraft.transport.pipes.PipePowerWood;
|
||||||
import buildcraft.transport.triggers.ActionEnergyPulser;
|
import buildcraft.transport.triggers.ActionEnergyPulser;
|
||||||
|
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
|
||||||
|
|
||||||
public class GateVanilla extends Gate {
|
public class GateVanilla extends Gate {
|
||||||
|
|
||||||
|
@ -202,6 +203,7 @@ public class GateVanilla extends Gate {
|
||||||
|
|
||||||
if (hasPulser()) {
|
if (hasPulser()) {
|
||||||
list.add(BuildCraftTransport.actionEnergyPulser);
|
list.add(BuildCraftTransport.actionEnergyPulser);
|
||||||
|
list.add(BuildCraftTransport.actionSingleEnergyPulse);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -214,13 +216,15 @@ public class GateVanilla extends Gate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean resolveAction(IAction action) {
|
public boolean resolveAction(IAction action, int count) {
|
||||||
|
|
||||||
if (action instanceof ActionEnergyPulser) {
|
if (action instanceof ActionEnergyPulser) {
|
||||||
pulser.enablePulse();
|
pulser.enablePulse(count);
|
||||||
|
return true;
|
||||||
|
} else if (action instanceof ActionSingleEnergyPulse) {
|
||||||
|
pulser.enableSinglePulse(count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.google.common.collect.HashMultiset;
|
||||||
|
import com.google.common.collect.Multiset;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLiving;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
@ -547,6 +550,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
gate.startResolution();
|
gate.startResolution();
|
||||||
|
|
||||||
HashMap<Integer, Boolean> actions = new HashMap<Integer, Boolean>();
|
HashMap<Integer, Boolean> actions = new HashMap<Integer, Boolean>();
|
||||||
|
Multiset<Integer> actionCount = HashMultiset.create();
|
||||||
|
|
||||||
// Computes the actions depending on the triggers
|
// Computes the actions depending on the triggers
|
||||||
for (int it = 0; it < 8; ++it) {
|
for (int it = 0; it < 8; ++it) {
|
||||||
|
@ -554,22 +558,25 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
|
||||||
IAction action = activatedActions[it];
|
IAction action = activatedActions[it];
|
||||||
ITriggerParameter parameter = triggerParameters[it];
|
ITriggerParameter parameter = triggerParameters[it];
|
||||||
|
|
||||||
if (trigger != null && action != null)
|
if (trigger != null && action != null) {
|
||||||
|
actionCount.add(action.getId());
|
||||||
if (!actions.containsKey(action.getId())) {
|
if (!actions.containsKey(action.getId())) {
|
||||||
actions.put(action.getId(), isNearbyTriggerActive(trigger, parameter));
|
actions.put(action.getId(), isNearbyTriggerActive(trigger, parameter));
|
||||||
} else if (gate.getConditional() == GateConditional.AND) {
|
} else if (gate.getConditional() == GateConditional.AND) {
|
||||||
actions.put(action.getId(), actions.get(action.getId()) && isNearbyTriggerActive(trigger, parameter));
|
actions.put(action.getId(), actions.get(action.getId()) && isNearbyTriggerActive(trigger, parameter));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
actions.put(action.getId(), actions.get(action.getId()) || isNearbyTriggerActive(trigger, parameter));
|
actions.put(action.getId(), actions.get(action.getId()) || isNearbyTriggerActive(trigger, parameter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Activate the actions
|
// Activate the actions
|
||||||
for (Integer i : actions.keySet())
|
for (Integer i : actions.keySet())
|
||||||
if (actions.get(i)) {
|
if (actions.get(i)) {
|
||||||
|
|
||||||
// Custom gate actions take precedence over defaults.
|
// Custom gate actions take precedence over defaults.
|
||||||
if (gate.resolveAction(ActionManager.actions[i])) {
|
if (gate.resolveAction(ActionManager.actions[i], actionCount.count(i))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package buildcraft.transport.triggers;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.Action;
|
||||||
|
import buildcraft.core.DefaultProps;
|
||||||
|
|
||||||
|
public class ActionSingleEnergyPulse extends Action {
|
||||||
|
|
||||||
|
public ActionSingleEnergyPulse(int id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIndexInTexture() {
|
||||||
|
return 4 * 16 + 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTexture() {
|
||||||
|
return DefaultProps.TEXTURE_TRIGGERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Single Energy Pulse";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue