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.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSignalOutput;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import buildcraft.transport.triggers.TriggerPipeContents;
import buildcraft.transport.triggers.TriggerPipeContents.Kind;
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 actionYellowSignal = new ActionSignalOutput(DefaultProps.ACTION_YELLOW_SIGNAL, IPipe.WireColor.Yellow);
public static Action actionEnergyPulser = new ActionEnergyPulser(DefaultProps.ACTION_ENERGY_PULSER);
public static Action actionSingleEnergyPulse = new ActionSingleEnergyPulse(DefaultProps.ACTION_SINGLE_ENERGY_PULSE);
@Instance("BuildCraft|Transport")
public static BuildCraftTransport instance;

View file

@ -154,4 +154,6 @@ public class DefaultProps {
public static int ACTION_OFF = 7;
public static int ACTION_LOOP = 8;
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 boolean isActive = false;
private float progress = 0;
private int progressPart = 0;
private float pulseSpeed = 0;
private int maxHeat = 1000;
private boolean isActive;
private boolean singlePulse;
private boolean hasPulsed;
private int pulseCount;
private int tick;
public EnergyPulser(IPowerReceptor receptor) {
powerReceptor = receptor;
}
@ -22,32 +21,39 @@ public class EnergyPulser {
if (powerReceptor == null)
return;
// Check if we are already running
if (progressPart != 0) {
progress += getPulseSpeed();
if (progress > 0.5 && progressPart == 1) {
progressPart = 2;
// Give off energy pulse!
powerReceptor.getPowerProvider().receiveEnergy(1, ForgeDirection.WEST);
} else if (progress >= 1) {
progress = 0;
progressPart = 0;
if (isActive)
{
tick++;
if (!singlePulse || !hasPulsed) {
if (tick % 10 == 0 || !hasPulsed)
{
powerReceptor.getPowerProvider().receiveEnergy(Math.max(1 << (pulseCount-1),64), ForgeDirection.WEST);
if (singlePulse) {
hasPulsed = true;
}
}
}
} else if (isActive) {
progressPart = 1;
}
}
public void enablePulse() {
public void enableSinglePulse(int count) {
singlePulse = true;
isActive = true;
pulseCount = count;
}
public void enablePulse(int count) {
isActive = true;
singlePulse = false;
pulseCount = count;
}
public void disablePulse() {
if (!isActive) {
hasPulsed = false;
}
isActive = false;
pulseCount = 0;
}
public boolean isActive() {
@ -59,14 +65,12 @@ public class EnergyPulser {
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setBoolean("SinglePulse", singlePulse);
nbttagcompound.setBoolean("IsActive", isActive);
nbttagcompound.setShort("ProgressPart", (short) progressPart);
nbttagcompound.setFloat("Progress", progress);
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
isActive = nbttagcompound.getBoolean("IsActive");
progressPart = nbttagcompound.getShort("ProgressPart");
progress = nbttagcompound.getFloat("Progress");
singlePulse = nbttagcompound.getBoolean("SinglePulse");
}
}

View file

@ -90,7 +90,7 @@ public abstract class Gate {
public abstract void startResolution();
public abstract boolean resolveAction(IAction action);
public abstract boolean resolveAction(IAction action, int count);
// / TRIGGERS
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.transport.pipes.PipePowerWood;
import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
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.
*
*
* @param pipe
* @return
*/
@ -133,7 +134,7 @@ public class GateVanilla extends Gate {
/**
* Drops a gate item of the specified kind.
*
*
* @param kind
* @param world
* @param i
@ -202,6 +203,7 @@ public class GateVanilla extends Gate {
if (hasPulser()) {
list.add(BuildCraftTransport.actionEnergyPulser);
list.add(BuildCraftTransport.actionSingleEnergyPulse);
}
}
@ -214,13 +216,15 @@ public class GateVanilla extends Gate {
}
@Override
public boolean resolveAction(IAction action) {
public boolean resolveAction(IAction action, int count) {
if (action instanceof ActionEnergyPulser) {
pulser.enablePulse();
pulser.enablePulse(count);
return true;
} else if (action instanceof ActionSingleEnergyPulse) {
pulser.enableSinglePulse(count);
return true;
}
return false;
}

View file

@ -14,6 +14,9 @@ import java.util.LinkedList;
import java.util.Map;
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.EntityLiving;
import net.minecraft.entity.item.EntityItem;
@ -123,7 +126,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
logic.onBlockPlaced();
transport.onBlockPlaced();
}
public void onBlockPlacedBy(EntityLiving placer) {}
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()
*
*
* @param direction
* The orientation for the texture that is requested. Unknown for the center pipe center
* @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
* getTextureIndex(Orienations.Unknown) has logic
*
*
* @return
*/
public int getTextureIndexForItem() {
@ -547,6 +550,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
gate.startResolution();
HashMap<Integer, Boolean> actions = new HashMap<Integer, Boolean>();
Multiset<Integer> actionCount = HashMultiset.create();
// Computes the actions depending on the triggers
for (int it = 0; it < 8; ++it) {
@ -554,14 +558,17 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
IAction action = activatedActions[it];
ITriggerParameter parameter = triggerParameters[it];
if (trigger != null && action != null)
if (trigger != null && action != null) {
actionCount.add(action.getId());
if (!actions.containsKey(action.getId())) {
actions.put(action.getId(), isNearbyTriggerActive(trigger, parameter));
} else if (gate.getConditional() == GateConditional.AND) {
actions.put(action.getId(), actions.get(action.getId()) && isNearbyTriggerActive(trigger, parameter));
} else {
actions.put(action.getId(), actions.get(action.getId()) || isNearbyTriggerActive(trigger, parameter));
}
}
}
// Activate the actions
@ -569,7 +576,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
if (actions.get(i)) {
// Custom gate actions take precedence over defaults.
if (gate.resolveAction(ActionManager.actions[i])) {
if (gate.resolveAction(ActionManager.actions[i], actionCount.count(i))) {
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";
}
}