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:
Christian 2013-03-27 23:15:12 -04:00
parent 69ac580b3f
commit 276cacdef6
7 changed files with 84 additions and 38 deletions

View file

@ -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;

View file

@ -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;
} }

View file

@ -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 enablePulse() { public void enableSinglePulse(int count) {
singlePulse = true;
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");
} }
} }

View file

@ -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);

View file

@ -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 {
@ -117,7 +118,7 @@ public class GateVanilla extends Gate {
/** /**
* Tries to add an energy pulser to gates that accept energy. * Tries to add an energy pulser to gates that accept energy.
* *
* @param pipe * @param pipe
* @return * @return
*/ */
@ -133,7 +134,7 @@ public class GateVanilla extends Gate {
/** /**
* Drops a gate item of the specified kind. * Drops a gate item of the specified kind.
* *
* @param kind * @param kind
* @param world * @param world
* @param i * @param i
@ -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;
} }

View file

@ -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;
@ -123,7 +126,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
logic.onBlockPlaced(); logic.onBlockPlaced();
transport.onBlockPlaced(); transport.onBlockPlaced();
} }
public void onBlockPlacedBy(EntityLiving placer) {} public void onBlockPlacedBy(EntityLiving placer) {}
public void onNeighborBlockChange(int blockId) { public void onNeighborBlockChange(int blockId) {
@ -144,7 +147,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
/** /**
* Should return the textureindex in the file specified by getTextureFile() * Should return the textureindex in the file specified by getTextureFile()
* *
* @param direction * @param direction
* The orientation for the texture that is requested. Unknown for the center pipe center * The orientation for the texture that is requested. Unknown for the center pipe center
* @return the index in the texture sheet * @return the index in the texture sheet
@ -154,7 +157,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
/** /**
* Should return the textureindex used by the Pipe Item Renderer, as this is done client-side the default implementation might not work if your * Should return the textureindex used by the Pipe Item Renderer, as this is done client-side the default implementation might not work if your
* getTextureIndex(Orienations.Unknown) has logic * getTextureIndex(Orienations.Unknown) has logic
* *
* @return * @return
*/ */
public int getTextureIndexForItem() { public int getTextureIndexForItem() {
@ -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,14 +558,17 @@ 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
@ -569,7 +576,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
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;
} }

View file

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