Rewrite Timer Trigger so it actually works...

...and add Clock Timer Gate Expansion.
This commit is contained in:
CovertJaguar 2013-12-24 00:22:17 -08:00
parent b3aa1aaafd
commit 4e3f4c1e94
15 changed files with 171 additions and 247 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

View file

@ -31,6 +31,7 @@ fluid.oil=Oil
fluid.fuel=Fuel
gate.action.pipe.item.color=Paint Items %s
gate.action.extraction=%s Extraction Preset
gate.expansion.pulsar=Autarchic Pulsar
gate.expansion.timer=Clock Timer
@ -55,6 +56,7 @@ gate.trigger.engine.blue=Engine Blue
gate.trigger.engine.green=Engine Green
gate.trigger.engine.yellow=Engine Yellow
gate.trigger.engine.red=Engine Red
gate.trigger.timer=%s Sec Timer
gui.building.resources=Building Resources
gui.del=Del

View file

@ -36,7 +36,6 @@ import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.Property;
@Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT)
@ -47,10 +46,6 @@ public class BuildCraftSilicon {
public static BlockLaser laserBlock;
public static BlockLaserTable assemblyTableBlock;
public static int timerIntervalShort;
public static int timerIntervalMedium;
public static int timerIntervalLong;
@Instance("BuildCraft|Silicon")
public static BuildCraftSilicon instance;
@ -62,13 +57,6 @@ public class BuildCraftSilicon {
Property redstoneChipsetId = BuildCraftCore.mainConfiguration.getItem("redstoneChipset.id", DefaultProps.REDSTONE_CHIPSET);
Property timerIntervalShort = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "timerShortInterval", 2);
timerIntervalShort.comment = "sets the 'short' duration of the quartz gate timer (default: 2 seconds)";
Property timerIntervalMedium = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "timerMediumInterval", 5);
timerIntervalMedium.comment = "sets the 'medium' duration of the quartz gate timer (default: 5 seconds)";
Property timerIntervalLong = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "timerLongInterval", 10);
timerIntervalLong.comment = "sets the 'long' duration of the quartz gate timer (default: 10 seconds)";
BuildCraftCore.mainConfiguration.save();
laserBlock = new BlockLaser(laserId.getInt());
@ -85,10 +73,6 @@ public class BuildCraftSilicon {
redstoneChipset.setUnlocalizedName("redstoneChipset");
CoreProxy.proxy.registerItem(redstoneChipset);
redstoneChipset.registerItemStacks();
this.timerIntervalShort = timerIntervalShort.getInt();
this.timerIntervalMedium = timerIntervalMedium.getInt();
this.timerIntervalLong = timerIntervalLong.getInt();
}
@EventHandler

View file

@ -41,6 +41,7 @@ import buildcraft.transport.blueprints.BptItemPipeWooden;
import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.transport.PipeWire;
import buildcraft.transport.gates.GateExpansionTimer;
import buildcraft.transport.network.PacketHandlerTransport;
import buildcraft.transport.network.TransportConnectionHandler;
import buildcraft.transport.pipes.PipeFluidsCobblestone;
@ -82,7 +83,8 @@ import buildcraft.transport.triggers.ActionPowerLimiter;
import buildcraft.transport.triggers.ActionSignalOutput;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import buildcraft.transport.triggers.TriggerPipeContents;
import buildcraft.transport.triggers.TriggerQuartzTimer;
import buildcraft.transport.triggers.TriggerClockTimer;
import buildcraft.transport.triggers.TriggerClockTimer.Time;
import buildcraft.transport.triggers.TriggerPipeContents.Kind;
import buildcraft.transport.triggers.TriggerPipeSignal;
import cpw.mods.fml.common.Mod;
@ -167,9 +169,7 @@ public class BuildCraftTransport {
public static BCTrigger triggerGreenSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_GREEN_SIGNAL_INACTIVE, false, PipeWire.Green);
public static BCTrigger triggerYellowSignalActive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_ACTIVE, true, PipeWire.Yellow);
public static BCTrigger triggerYellowSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_INACTIVE, false, PipeWire.Yellow);
public static BCTrigger triggerTimerShort = new TriggerQuartzTimer(DefaultProps.TRIGGER_TIMER_SHORT, TriggerQuartzTimer.Time.Short);
public static BCTrigger triggerTimerMedium = new TriggerQuartzTimer(DefaultProps.TRIGGER_TIMER_MEDIUM, TriggerQuartzTimer.Time.Medium);
public static BCTrigger triggerTimerLong = new TriggerQuartzTimer(DefaultProps.TRIGGER_TIMER_LONG, TriggerQuartzTimer.Time.Long);
public static BCTrigger[] triggerTimer = new TriggerClockTimer[TriggerClockTimer.Time.VALUES.length];
public static BCAction actionRedSignal = new ActionSignalOutput(DefaultProps.ACTION_RED_SIGNAL, PipeWire.Red);
public static BCAction actionBlueSignal = new ActionSignalOutput(DefaultProps.ACTION_BLUE_SIGNAL, PipeWire.Blue);
public static BCAction actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, PipeWire.Green);
@ -179,10 +179,10 @@ public class BuildCraftTransport {
public static BCAction[] actionPipeColor = new BCAction[16];
public static BCAction[] actionPipeDirection = new BCAction[16];
public static BCAction[] actionPowerLimiter = new BCAction[7];
public static BCAction actionExtractionPresetRed = new ActionExtractionPreset(-1, EnumColor.RED);
public static BCAction actionExtractionPresetBlue = new ActionExtractionPreset(-1, EnumColor.BLUE);
public static BCAction actionExtractionPresetGreen = new ActionExtractionPreset(-1, EnumColor.GREEN);
public static BCAction actionExtractionPresetYellow = new ActionExtractionPreset(-1, EnumColor.YELLOW);
public static BCAction actionExtractionPresetRed = new ActionExtractionPreset(EnumColor.RED);
public static BCAction actionExtractionPresetBlue = new ActionExtractionPreset(EnumColor.BLUE);
public static BCAction actionExtractionPresetGreen = new ActionExtractionPreset(EnumColor.GREEN);
public static BCAction actionExtractionPresetYellow = new ActionExtractionPreset(EnumColor.YELLOW);
public IIconProvider pipeIconProvider = new PipeIconProvider();
public IIconProvider wireIconProvider = new WireIconProvider();
@Instance("BuildCraft|Transport")
@ -266,6 +266,7 @@ public class BuildCraftTransport {
PipeManager.registerExtractionHandler(new ExtractionHandler(excludedItemBlocks, excludedFluidBlocks));
GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE);
GateExpansions.registerExpansion(GateExpansionTimer.INSTANCE);
Property groupItemsTriggerProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pipes.groupItemsTrigger", 32);
groupItemsTriggerProp.comment = "when reaching this amount of objects in a pipes, items will be automatically grouped";
@ -412,16 +413,20 @@ public class BuildCraftTransport {
public void postInit(FMLPostInitializationEvent evt) {
ItemFacade.initialize();
for (Time time : TriggerClockTimer.Time.VALUES) {
triggerTimer[time.ordinal()] = new TriggerClockTimer(time);
}
for (EnumColor color : EnumColor.VALUES) {
actionPipeColor[color.ordinal()] = new ActionPipeColor(-1, color);
actionPipeColor[color.ordinal()] = new ActionPipeColor(color);
}
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
actionPipeDirection[direction.ordinal()] = new ActionPipeDirection(-1, direction);
actionPipeDirection[direction.ordinal()] = new ActionPipeDirection(direction);
}
for (PowerMode limit : PowerMode.VALUES) {
actionPowerLimiter[limit.ordinal()] = new ActionPowerLimiter(-1, limit);
actionPowerLimiter[limit.ordinal()] = new ActionPowerLimiter(limit);
}
}

View file

@ -159,9 +159,6 @@ public class DefaultProps {
public static int TRIGGER_RED_ENGINE_HEAT = 28;
public static int TRIGGER_PIPE_REQUESTS_ENERGY = 29;
public static int TRIGGER_PIPE_TOO_MUCH_ENERGY = 30;
public static int TRIGGER_TIMER_SHORT = 31;
public static int TRIGGER_TIMER_MEDIUM = 32;
public static int TRIGGER_TIMER_LONG = 33;
public static int ACTION_REDSTONE = 1;
public static int ACTION_RED_SIGNAL = 2;

View file

@ -6,58 +6,57 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
/**
* Don't put new Trigger Icons in here please, put them in the Trigger classes
* like the TriggerQuartzTimer. This class will go away someday.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class ActionTriggerIconProvider implements IIconProvider {
public static ActionTriggerIconProvider INSTANCE = new ActionTriggerIconProvider();
public static final int Action_MachineControl_On = 0;
public static final int Action_MachineControl_Off = 1;
public static final int Action_MachineControl_Loop = 2;
public static final int Trigger_EngineHeat_Blue = 3;
public static final int Trigger_EngineHeat_Green = 4;
public static final int Trigger_EngineHeat_Yellow = 5;
public static final int Trigger_EngineHeat_Red = 6;
public static final int Trigger_Inventory_Empty = 7;
public static final int Trigger_Inventory_Contains = 8;
public static final int Trigger_Inventory_Space = 9;
public static final int Trigger_Inventory_Full = 10;
public static final int Trigger_FluidContainer_Empty = 11;
public static final int Trigger_FluidContainer_Contains = 12;
public static final int Trigger_FluidContainer_Space = 13;
public static final int Trigger_FluidContainer_Full = 14;
public static final int Trigger_Machine_Active = 15;
public static final int Trigger_Machine_Inactive = 16;
public static final int Trigger_PipeContents_Empty = 17;
public static final int Trigger_PipeContents_ContainsItems = 18;
public static final int Action_MachineControl_On = 0;
public static final int Action_MachineControl_Off = 1;
public static final int Action_MachineControl_Loop = 2;
public static final int Trigger_EngineHeat_Blue = 3;
public static final int Trigger_EngineHeat_Green = 4;
public static final int Trigger_EngineHeat_Yellow = 5;
public static final int Trigger_EngineHeat_Red = 6;
public static final int Trigger_Inventory_Empty = 7;
public static final int Trigger_Inventory_Contains = 8;
public static final int Trigger_Inventory_Space = 9;
public static final int Trigger_Inventory_Full = 10;
public static final int Trigger_FluidContainer_Empty = 11;
public static final int Trigger_FluidContainer_Contains = 12;
public static final int Trigger_FluidContainer_Space = 13;
public static final int Trigger_FluidContainer_Full = 14;
public static final int Trigger_Machine_Active = 15;
public static final int Trigger_Machine_Inactive = 16;
public static final int Trigger_PipeContents_Empty = 17;
public static final int Trigger_PipeContents_ContainsItems = 18;
public static final int Trigger_PipeContents_ContainsFluid = 19;
public static final int Trigger_PipeContents_ContainsEnergy = 20;
public static final int Trigger_PipeSignal_Red_Active = 21;
public static final int Trigger_PipeSignal_Blue_Active = 22;
public static final int Trigger_PipeSignal_Green_Active = 23;
public static final int Trigger_PipeSignal_Yellow_Active = 24;
public static final int Trigger_PipeSignal_Red_Inactive = 25;
public static final int Trigger_PipeSignal_Blue_Inactive = 26;
public static final int Trigger_PipeSignal_Green_Inactive = 27;
public static final int Trigger_PipeSignal_Yellow_Inactive = 28;
public static final int Trigger_RedstoneInput_Active = 29;
public static final int Trigger_RedstoneInput_Inactive = 30;
public static final int Trigger_PipeContents_RequestsEnergy = 31;
public static final int Trigger_PipeContents_TooMuchEnergy = 32;
public static final int Trigger_Inventory_Below25 = 33;
public static final int Trigger_Inventory_Below50 = 34;
public static final int Trigger_Inventory_Below75 = 35;
public static final int Trigger_Timer_Short = 36;
public static final int Trigger_Timer_Medium = 37;
public static final int Trigger_Timer_Long = 38;
public static final int MAX = 39;
public static final int Trigger_PipeSignal_Red_Active = 21;
public static final int Trigger_PipeSignal_Blue_Active = 22;
public static final int Trigger_PipeSignal_Green_Active = 23;
public static final int Trigger_PipeSignal_Yellow_Active = 24;
public static final int Trigger_PipeSignal_Red_Inactive = 25;
public static final int Trigger_PipeSignal_Blue_Inactive = 26;
public static final int Trigger_PipeSignal_Green_Inactive = 27;
public static final int Trigger_PipeSignal_Yellow_Inactive = 28;
public static final int Trigger_RedstoneInput_Active = 29;
public static final int Trigger_RedstoneInput_Inactive = 30;
public static final int Trigger_PipeContents_RequestsEnergy = 31;
public static final int Trigger_PipeContents_TooMuchEnergy = 32;
public static final int Trigger_Inventory_Below25 = 33;
public static final int Trigger_Inventory_Below50 = 34;
public static final int Trigger_Inventory_Below75 = 35;
public static final int MAX = 39;
@SideOnly(Side.CLIENT)
private final Icon[] icons = new Icon[MAX];
private ActionTriggerIconProvider(){}
private ActionTriggerIconProvider() {
}
@Override
@SideOnly(Side.CLIENT)
@ -105,9 +104,5 @@ public class ActionTriggerIconProvider implements IIconProvider {
icons[ActionTriggerIconProvider.Trigger_Inventory_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below25");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below50");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below75");
icons[ActionTriggerIconProvider.Trigger_Timer_Short] = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_short");
icons[ActionTriggerIconProvider.Trigger_Timer_Medium] = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_medium");
icons[ActionTriggerIconProvider.Trigger_Timer_Long] = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_long");
}
}

View file

@ -19,6 +19,15 @@ public abstract class BCAction implements IAction {
protected final int legacyId;
protected final String uniqueTag;
public BCAction(String uniqueTag) {
this(-1, uniqueTag);
}
/**
*
* @param legacyId this should be -1 for new Actions
* @param uniqueTag
*/
public BCAction(int legacyId, String uniqueTag) {
this.legacyId = legacyId;
this.uniqueTag = uniqueTag;

View file

@ -11,17 +11,12 @@ package buildcraft.transport.gates;
import buildcraft.api.gates.GateExpansionController;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.transport.triggers.TriggerClockTimer;
import buildcraft.transport.triggers.TriggerClockTimer.Time;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
/**
*
@ -42,101 +37,58 @@ public class GateExpansionTimer extends GateExpansionBuildcraft implements IGate
private class GateExpansionControllerTimer extends GateExpansionController {
private boolean isActive;
private boolean singlePulse;
private boolean hasPulsed;
private int pulseCount;
private int tick;
private class Timer {
private static final int ACTIVE_TIME = 5;
private final TriggerClockTimer.Time time;
private int clock;
public Timer(TriggerClockTimer.Time time) {
this.time = time;
}
public void tick() {
if (clock > -ACTIVE_TIME)
clock--;
else
clock = time.delay * 20 + ACTIVE_TIME;
}
public boolean isActive() {
return clock < 0;
}
}
private final Timer[] timers = new Timer[TriggerClockTimer.Time.VALUES.length];
public GateExpansionControllerTimer(TileEntity pipeTile) {
super(GateExpansionTimer.this, pipeTile);
}
@Override
public void startResolution() {
if (isActive()) {
disablePulse();
for (TriggerClockTimer.Time time : TriggerClockTimer.Time.VALUES) {
timers[time.ordinal()] = new Timer(time);
}
}
@Override
public boolean resolveAction(IAction action, int count) {
if (action instanceof ActionEnergyPulser) {
enablePulse(count);
return true;
} else if (action instanceof ActionSingleEnergyPulse) {
enableSinglePulse(count);
return true;
public boolean isTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
if (trigger instanceof TriggerClockTimer) {
TriggerClockTimer timerTrigger = (TriggerClockTimer) trigger;
return timers[timerTrigger.time.ordinal()].isActive();
}
return false;
return super.isTriggerActive(trigger, parameter);
}
@Override
public void addTriggers(List<ITrigger> list) {
super.addTriggers(list);
list.add(BuildCraftTransport.triggerTimerShort);
list.add(BuildCraftTransport.triggerTimerMedium);
list.add(BuildCraftTransport.triggerTimerLong);
for (Time time : TriggerClockTimer.Time.VALUES) {
list.add(BuildCraftTransport.triggerTimer[time.ordinal()]);
}
}
@Override
public void tick() {
if (!isActive && hasPulsed)
hasPulsed = false;
PowerHandler.PowerReceiver powerReceptor = ((IPowerReceptor) pipeTile).getPowerReceiver(ForgeDirection.UNKNOWN);
if (powerReceptor == null || !isActive || tick++ % 10 != 0)
return;
if (!singlePulse || !hasPulsed) {
powerReceptor.receiveEnergy(Type.GATE, Math.min(1 << (pulseCount - 1), 64) * 1.01f, ForgeDirection.WEST);
hasPulsed = true;
for (Timer timer : timers) {
timer.tick();
}
}
private void enableSinglePulse(int count) {
singlePulse = true;
isActive = true;
pulseCount = count;
}
private void enablePulse(int count) {
isActive = true;
singlePulse = false;
pulseCount = count;
}
private void disablePulse() {
if (!isActive) {
hasPulsed = false;
}
isActive = false;
pulseCount = 0;
}
@Override
public boolean isActive() {
return isActive;
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
nbt.setBoolean("singlePulse", singlePulse);
nbt.setBoolean("isActive", isActive);
nbt.setBoolean("hasPulsed", hasPulsed);
nbt.setInteger("pulseCount", pulseCount);
nbt.setInteger("tick", tick);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
isActive = nbt.getBoolean("isActive");
singlePulse = nbt.getBoolean("singlePulse");
hasPulsed = nbt.getBoolean("hasPulsed");
pulseCount = nbt.getInteger("pulseCount");
tick = nbt.getInteger("tick");
}
}
}

View file

@ -9,6 +9,7 @@ package buildcraft.transport.triggers;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
@ -18,15 +19,15 @@ public class ActionExtractionPreset extends BCAction {
private Icon icon;
public final EnumColor color;
public ActionExtractionPreset(int id, EnumColor color) {
super(id, "buildcraft.extraction.preset." + color.getTag());
public ActionExtractionPreset(EnumColor color) {
super("buildcraft.extraction.preset." + color.getTag());
this.color = color;
}
@Override
public String getDescription() {
return color.getName() + " Extraction Preset";
return String.format(StringUtils.localize("gate.action.extraction"), color.getName());
}
@Override

View file

@ -19,8 +19,8 @@ public class ActionPipeColor extends BCAction {
private Icon icon;
public final EnumColor color;
public ActionPipeColor(int id, EnumColor color) {
super(id, "buildcraft.pipe." + color.getTag());
public ActionPipeColor(EnumColor color) {
super("buildcraft.pipe." + color.getTag());
this.color = color;
}

View file

@ -18,8 +18,8 @@ public class ActionPipeDirection extends BCAction {
private Icon icon;
public final ForgeDirection direction;
public ActionPipeDirection(int id, ForgeDirection direction) {
super(id, "buildcraft.pipe.dir." + direction.name().toLowerCase(Locale.ENGLISH));
public ActionPipeDirection(ForgeDirection direction) {
super("buildcraft.pipe.dir." + direction.name().toLowerCase(Locale.ENGLISH));
this.direction = direction;
}

View file

@ -18,8 +18,8 @@ public class ActionPowerLimiter extends BCAction {
private Icon icon;
public final PowerMode limit;
public ActionPowerLimiter(int id, PowerMode limit) {
super(id, "buildcraft.power.limiter." + limit.name().toLowerCase(Locale.ENGLISH));
public ActionPowerLimiter(PowerMode limit) {
super("buildcraft.power.limiter." + limit.name().toLowerCase(Locale.ENGLISH));
this.limit = limit;
}

View file

@ -0,0 +1,52 @@
package buildcraft.transport.triggers;
import java.util.Locale;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
public class TriggerClockTimer extends BCTrigger {
public enum Time {
SHORT(5), MEDIUM(10), LONG(15);
public static final Time[] VALUES = values();
public final int delay;
private Icon icon;
private Time(int delay) {
this.delay = delay;
}
}
public final Time time;
public TriggerClockTimer(Time time) {
super(-1, "buildcraft.timer." + time.name().toLowerCase(Locale.ENGLISH));
this.time = time;
}
@Override
public Icon getIcon() {
return time.icon;
}
@Override
public String getDescription() {
return String.format(StringUtils.localize("gate.trigger.timer"), time.delay);
}
@Override
public boolean hasParameter() {
return false;
}
@Override
public void registerIcons(IconRegister iconRegister) {
Time.SHORT.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_short");
Time.MEDIUM.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_medium");
Time.LONG.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_long");
}
}

View file

@ -1,73 +0,0 @@
package buildcraft.transport.triggers;
import java.util.Locale;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
public class TriggerQuartzTimer extends BCTrigger implements IPipeTrigger {
public enum Time {
Short, Medium, Long
}
public Time time;
public SafeTimeTracker pulseTracker;
public long delay;
public TriggerQuartzTimer(int legacyId, Time time) {
super(legacyId, "buildcraft.timer." + time.name().toLowerCase(Locale.ENGLISH));
this.time = time;
pulseTracker = new SafeTimeTracker();
}
@Override
public int getIconIndex() {
switch (time) {
case Short:
return ActionTriggerIconProvider.Trigger_Timer_Short;
case Medium:
return ActionTriggerIconProvider.Trigger_Timer_Medium;
default:
return ActionTriggerIconProvider.Trigger_Timer_Long;
}
}
@Override
public String getDescription() {
switch (time) {
case Short:
return BuildCraftSilicon.timerIntervalShort + " Localize Me!";
case Medium:
return BuildCraftSilicon.timerIntervalMedium + " Localize Me!";
default:
return BuildCraftSilicon.timerIntervalLong + " Localize Me!";
}
}
@Override
public boolean hasParameter() {
return false;
}
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
if (time == Time.Short) {
delay = BuildCraftSilicon.timerIntervalShort * 20; // Multiply the seconds by 20 to convert to ticks
} else if (time == Time.Medium) {
delay = BuildCraftSilicon.timerIntervalMedium * 20;
} else {
delay = BuildCraftSilicon.timerIntervalLong * 20;
}
return pulseTracker.markTimeIfDelay(pipe.getWorld(), delay);
}
}