ActionValve and ActionParameterDirection

This commit is contained in:
RufusStark 2014-09-08 21:41:48 -05:00
parent 2f17a302e7
commit 7a436c5a31
18 changed files with 294 additions and 82 deletions

View file

@ -59,7 +59,10 @@ gate.action.pulsar.constant=Energy Pulsar
gate.action.pulsar.single=Single Energy Pulse
gate.action.pipe.wire=%s Pipe Signal
gate.action.robot.goto_station=Goto Station
gate.action.pipe.close=Close Pipe
gate.action.pipe.valve.open=Open
gate.action.pipe.valve.input_only=Input Only
gate.action.pipe.valve.output_only=Output Only
gate.action.pipe.valve.closed=Closed
gate.action.station.provide_items=Provide Items
gate.action.station.accept_items=Accept Items
gate.action.station.request_items=Request Items

View file

Before

Width:  |  Height:  |  Size: 243 B

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

View file

@ -108,6 +108,7 @@ import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.transport.gates.GateExpansionRedstoneFader;
import buildcraft.transport.gates.GateExpansionTimer;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.triggers.ActionParameterDirection;
import buildcraft.transport.triggers.ActionParameterSignal;
import buildcraft.transport.triggers.TriggerParameterSignal;
@ -267,6 +268,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
StatementManager.registerParameterClass("buildcraft:pipeWireTrigger", TriggerParameterSignal.class);
StatementManager.registerParameterClass("buildcraft:stackAction", ActionParameterItemStack.class);
StatementManager.registerParameterClass("buildcraft:pipeWireAction", ActionParameterSignal.class);
StatementManager.registerParameterClass("buildcraft:pipeActionDirection", ActionParameterDirection.class);
}
@Mod.EventHandler

View file

@ -51,7 +51,6 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.science.TechnoSimpleItem;
import buildcraft.core.science.TechnoStatement;
import buildcraft.core.science.Tier;
import buildcraft.core.triggers.ActionPipeClose;
import buildcraft.silicon.ItemRedstoneChipset.Chipset;
import buildcraft.transport.BlockFilteredBuffer;
import buildcraft.transport.BlockGenericPipe;
@ -119,6 +118,8 @@ import buildcraft.transport.triggers.ActionPowerLimiter;
import buildcraft.transport.triggers.ActionRedstoneFaderOutput;
import buildcraft.transport.triggers.ActionSignalOutput;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import buildcraft.transport.triggers.ActionValve;
import buildcraft.transport.triggers.ActionValve.ValveState;
import buildcraft.transport.triggers.TriggerClockTimer;
import buildcraft.transport.triggers.TriggerClockTimer.Time;
import buildcraft.transport.triggers.TriggerPipeContents;
@ -188,7 +189,6 @@ public class BuildCraftTransport extends BuildCraftMod {
public static ITrigger[] triggerTimer = new ITrigger[TriggerClockTimer.Time.VALUES.length];
public static ITrigger[] triggerRedstoneLevel = new ITrigger[15];
public static IAction[] actionPipeWire = new ActionSignalOutput[PipeWire.values().length];
public static IAction actionPipeClose = new ActionPipeClose();
public static IAction actionEnergyPulser = new ActionEnergyPulsar();
public static IAction actionSingleEnergyPulse = new ActionSingleEnergyPulse();
public static IAction[] actionPipeColor = new IAction[16];
@ -199,6 +199,7 @@ public class BuildCraftTransport extends BuildCraftMod {
public static IAction actionExtractionPresetBlue = new ActionExtractionPreset(EnumColor.BLUE);
public static IAction actionExtractionPresetGreen = new ActionExtractionPreset(EnumColor.GREEN);
public static IAction actionExtractionPresetYellow = new ActionExtractionPreset(EnumColor.YELLOW);
public static IAction[] actionValve = new IAction[4];
public static TechnoSimpleItem technoPipeItemsWood = new TechnoSimpleItem();
public static TechnoSimpleItem technoPipeItemsEmerald = new TechnoSimpleItem();
@ -239,7 +240,6 @@ public class BuildCraftTransport extends BuildCraftMod {
public static TechnoStatement technoTriggerPipe = new TechnoStatement();
public static TechnoStatement technoTriggerPipeWireActive = new TechnoStatement();
public static TechnoStatement technoActionPipeWire = new TechnoStatement();
public static TechnoStatement technoActionPipeClose = new TechnoStatement();
public static TechnoStatement technoActionPipeColor = new TechnoStatement();
public static TechnoStatement technoActionPipeDirection = new TechnoStatement();
public static TechnoStatement technoActionPowerLimiter = new TechnoStatement();
@ -471,6 +471,10 @@ public class BuildCraftTransport extends BuildCraftMod {
actionPipeDirection[direction.ordinal()] = new ActionPipeDirection(direction);
}
for (ValveState state : ValveState.VALUES) {
actionValve[state.ordinal()] = new ActionValve(state);
}
for (PowerMode limit : PowerMode.VALUES) {
actionPowerLimiter[limit.ordinal()] = new ActionPowerLimiter(limit);
}
@ -764,13 +768,6 @@ public class BuildCraftTransport extends BuildCraftMod {
Chipset.RED.getStack(5),
BuildCraftCore.technoSilicon);
technoActionPipeClose.initialize(
Tier.IronChipset,
actionPipeClose,
"",
Chipset.RED.getStack(5),
BuildCraftCore.technoSilicon);
technoActionPipeColor.initialize(
Tier.Chipset,
actionPipeColor[0],

View file

@ -1,38 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
public class ActionPipeClose extends BCActionActive {
public ActionPipeClose() {
super("buildcraft:pipe.close");
}
@Override
public String getDescription() {
return StringUtils.localize("gate.action.pipe.close");
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/action_pipe_close");
}
@Override
public void actionActivate(IGate gate, IActionParameter[] parameters) {
((Pipe) gate.getPipe()).close();
}
}

View file

@ -63,6 +63,14 @@ public final class StatementIconProvider implements IIconProvider {
public static final int Trigger_FluidContainer_Below50 = 37;
public static final int Trigger_FluidContainer_Below75 = 38;
public static final int Action_Parameter_Direction_Down = 39;
public static final int Action_Parameter_Direction_Up = 40;
public static final int Action_Parameter_Direction_North = 41;
public static final int Action_Parameter_Direction_South = 42;
public static final int Action_Parameter_Direction_West = 43;
public static final int Action_Parameter_Direction_East = 44;
public static final int MAX = 45;
@SideOnly(Side.CLIENT)
@ -120,5 +128,12 @@ public final class StatementIconProvider implements IIconProvider {
icons[StatementIconProvider.Trigger_FluidContainer_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below25");
icons[StatementIconProvider.Trigger_FluidContainer_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below50");
icons[StatementIconProvider.Trigger_FluidContainer_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below75");
icons[StatementIconProvider.Action_Parameter_Direction_Down] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_down");
icons[StatementIconProvider.Action_Parameter_Direction_Up] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_up");
icons[StatementIconProvider.Action_Parameter_Direction_North] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_north");
icons[StatementIconProvider.Action_Parameter_Direction_South] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_south");
icons[StatementIconProvider.Action_Parameter_Direction_West] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_west");
icons[StatementIconProvider.Action_Parameter_Direction_East] = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_east");
}
}

View file

@ -206,8 +206,7 @@ public final class Gate implements IGate {
for (int j = 0; j < MAX_PARAMETERS; ++j) {
if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) {
NBTTagCompound cpt = data.getCompoundTag("triggerParameters[" + i + "][" + j + "]");
triggerParameters[i][j] = (ITriggerParameter) StatementManager.createParameter(cpt
.getString("kind"));
triggerParameters[i][j] = (ITriggerParameter) StatementManager.createParameter(cpt.getString("kind"));
triggerParameters[i][j].readFromNBT(cpt);
}
}

View file

@ -46,6 +46,7 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.ActionSlot;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.pipes.events.PipeEvent;
import buildcraft.transport.triggers.ActionValve.ValveState;
public abstract class Pipe<T extends PipeTransport> implements IDropControlInventory, IPipe {
@ -62,7 +63,6 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
private boolean internalUpdateScheduled = false;
private boolean initialized = false;
private boolean closed = false;
private ArrayList<ActionState> actionStates = new ArrayList<ActionState>();
@ -212,7 +212,6 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
internalUpdateScheduled = false;
}
closed = false;
actionStates.clear();
// Update the gate if we have any
@ -535,7 +534,9 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
public LinkedList<IAction> getActions() {
LinkedList<IAction> result = new LinkedList<IAction>();
result.add(BuildCraftTransport.actionPipeClose);
for (ValveState state : ValveState.VALUES) {
result.add(BuildCraftTransport.actionValve[state.ordinal()]);
}
return result;
}
@ -662,14 +663,6 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
return container.getTile(dir);
}
public void close() {
closed = true;
}
public boolean isClosed() {
return closed;
}
private void pushActionState(ActionState state) {
actionStates.add(state);
}

View file

@ -18,18 +18,47 @@ import buildcraft.api.transport.IPipeTile.PipeType;
public abstract class PipeTransport {
public static final String PIPE_IO_SETTINGS = "iosetting";
public TileGenericPipe container;
protected boolean[] inputsOpen = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
protected boolean[] outputsOpen = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
public PipeTransport() {
for (int b = 0; b < ForgeDirection.VALID_DIRECTIONS.length; b++) {
inputsOpen[b] = true;
outputsOpen[b] = true;
}
}
public abstract PipeType getPipeType();
public World getWorld() {
return container.getWorldObj();
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
public void readFromNBT(NBTTagCompound nbt) {
if (nbt.hasKey(PIPE_IO_SETTINGS)) {
int iosettings = nbt.getInteger(PIPE_IO_SETTINGS);
for (int b = 0; b < ForgeDirection.VALID_DIRECTIONS.length; b++) {
inputsOpen[b] = (iosettings & (1 << b)) == 1;
outputsOpen[b] = (iosettings & (1 << (b + 8))) == 1;
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
public void writeToNBT(NBTTagCompound nbt) {
int iosettings = 0;
for (int b = 0; b < ForgeDirection.VALID_DIRECTIONS.length; b++) {
if (inputsOpen[b]) {
iosettings |= 1 << b;
}
if (outputsOpen[b]) {
iosettings |= 1 << (b + 8);
}
}
nbt.setInteger(PIPE_IO_SETTINGS, iosettings);
}
public void updateEntity() {
@ -53,11 +82,23 @@ public abstract class PipeTransport {
}
public boolean inputOpen(ForgeDirection from) {
return true;
return inputsOpen[from.ordinal()];
}
public boolean outputOpen(ForgeDirection to) {
return true;
return outputsOpen[to.ordinal()];
}
public void allowInput(ForgeDirection from, boolean allow) {
if (from != ForgeDirection.UNKNOWN) {
inputsOpen[from.ordinal()] = allow;
}
}
public void allowOutput(ForgeDirection to, boolean allow) {
if (to != ForgeDirection.UNKNOWN) {
outputsOpen[to.ordinal()] = allow;
}
}
public void dropContents() {

View file

@ -185,7 +185,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
if (entity instanceof TileGenericPipe) {
Pipe<?> pipe = ((TileGenericPipe) entity).pipe;
if (pipe == null || !pipe.inputOpen(o.getOpposite()) || pipe.isClosed()) {
if (pipe == null || !inputOpen(o.getOpposite())) {
return false;
}
}
@ -487,7 +487,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
outputTTL[direction.ordinal()] = OUTPUT_TTL;
continue;
}
if (canReceiveFluid(direction)) {
if (canReceiveFluid(direction) && outputOpen(direction)) {
transferState[direction.ordinal()] = TransferState.Output;
outputCount++;
}
@ -543,7 +543,8 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
}
private int fill(int tankIndex, FluidStack resource, boolean doFill) {
if (container.pipe.isClosed()) {
ForgeDirection d = ForgeDirection.getOrientation(tankIndex);
if (d != ForgeDirection.UNKNOWN && !inputOpen(d)) {
return 0;
}
@ -575,7 +576,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return true;
return inputOpen(from);
}
@Override

View file

@ -204,7 +204,8 @@ public class PipeTransportItems extends PipeTransport {
sides.remove(ForgeDirection.UNKNOWN);
for (ForgeDirection o : sides) {
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item)) {
//if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item)) {
if (outputOpen(o) && canReceivePipeObjects(o, item)) {
result.add(o);
}
}
@ -233,7 +234,8 @@ public class PipeTransportItems extends PipeTransport {
if (entity instanceof TileGenericPipe) {
TileGenericPipe pipe = (TileGenericPipe) entity;
return !pipe.pipe.isClosed() && pipe.pipe.transport instanceof PipeTransportItems;
//return !pipe.pipe.isClosed() && pipe.pipe.transport instanceof PipeTransportItems;
return pipe.pipe.inputOpen(o.getOpposite()) && pipe.pipe.transport instanceof PipeTransportItems;
} else if (entity instanceof IInventory && item.getInsertionHandler().canInsertItem(item, (IInventory) entity)) {
if (Transactor.getTransactorFor(entity).add(item.getItemStack(), o.getOpposite(), false).stackSize > 0) {
return true;

View file

@ -278,6 +278,10 @@ public class PipeTransportPower extends PipeTransport {
// Compute the tiles requesting energy that are not power pipes
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (!outputOpen(dir)) {
continue;
}
TileEntity tile = tiles [dir.ordinal()];
if (tile instanceof IEnergyHandler) {
IEnergyHandler handler = (IEnergyHandler) tile;
@ -307,6 +311,10 @@ public class PipeTransportPower extends PipeTransport {
for (int i = 0; i < 6; ++i) {
transferQuery[i] = 0;
if (!inputOpen(ForgeDirection.getOrientation(i))) {
continue;
}
for (int j = 0; j < 6; ++j) {
if (j != i) {
transferQuery[i] += powerQuery[j];
@ -419,15 +427,12 @@ public class PipeTransportPower extends PipeTransport {
public void requestEnergy(ForgeDirection from, int amount) {
step();
if (!container.pipe.isClosed()) {
if (this.container.pipe instanceof IPipeTransportPowerHook) {
nextPowerQuery[from.ordinal()] += ((IPipeTransportPowerHook) this.container.pipe).requestEnergy(from,
amount);
nextPowerQuery[from.ordinal()] += ((IPipeTransportPowerHook) this.container.pipe).requestEnergy(from, amount);
} else {
nextPowerQuery[from.ordinal()] += amount;
}
}
}
@Override
public void initialize() {

View file

@ -584,7 +584,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
/* IPIPEENTRY */
@Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from, EnumColor color) {
if (pipe.isClosed()) {
if (!pipe.inputOpen(from)) {
return 0;
}

View file

@ -0,0 +1,93 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.triggers;
//import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IStatement;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.triggers.StatementIconProvider;
public class ActionParameterDirection implements IActionParameter {
// static IIcon[] icons = new IIcon[ForgeDirection.values().length];
@NetworkData
public ForgeDirection direction = ForgeDirection.UNKNOWN;
public ActionParameterDirection() {
}
/*
@Override
public void registerIcons(IIconRegister register) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
icons[d.ordinal()] = register.registerIcon("buildcraft:triggers/trigger_dir_" + d.name().toLowerCase());
}
}
@Override
public IIcon getIconToDraw() {
return icons[direction.ordinal()];
}
*/
@Override
public ItemStack getItemStackToDraw() {
return null;
}
@Override
public IIcon getIconToDraw() {
if (direction == ForgeDirection.UNKNOWN) {
return null;
} else {
return StatementIconProvider.INSTANCE.getIcon(StatementIconProvider.INSTANCE.Action_Parameter_Direction_Down + direction.ordinal());
}
}
@Override
public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) {
do {
direction = ForgeDirection.getOrientation((direction.ordinal() + 1) % ForgeDirection.values().length);
} while (direction != ForgeDirection.UNKNOWN && !pipe.isPipeConnected(direction));
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("direction", direction.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
if (nbt.hasKey("direction")) {
direction = ForgeDirection.values()[nbt.getInteger("direction")];
} else {
direction = ForgeDirection.UNKNOWN;
}
}
@Override
public boolean equals(Object object) {
if (object instanceof ActionParameterDirection) {
ActionParameterDirection param = (ActionParameterDirection) object;
return param.direction == this.direction;
}
return false;
}
}

View file

@ -0,0 +1,99 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IGate;
import buildcraft.api.transport.IPipe;
import buildcraft.core.triggers.BCActionActive;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransport;
public class ActionValve extends BCActionActive {
public enum ValveState {
OPEN(true, true),
INPUT_ONLY(true, false),
OUTPUT_ONLY(false, true),
CLOSED(false, false);
public static final ValveState[] VALUES = values();
public final boolean inputOpen;
public final boolean outputOpen;
private ValveState(boolean in, boolean out) {
inputOpen = in;
outputOpen = out;
}
}
public final ValveState state;
public ActionValve(ValveState valveState) {
super("buildcraft:pipe.valve." + valveState.name().toLowerCase(Locale.ENGLISH));
state = valveState;
}
@Override
public String getDescription() {
return StringUtils.localize("gate.action.pipe.valve." + state.name().toLowerCase(Locale.ENGLISH));
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/action_valve_" + state.name().toLowerCase(Locale.ENGLISH));
}
@Override
public int maxParameters() {
return 1;
}
@Override
public int minParameters() {
return 1;
}
@Override
public IActionParameter createParameter(int index) {
IActionParameter param = null;
if (index == 0) {
param = new ActionParameterDirection();
}
return param;
}
@Override
public void actionActivate(IGate gate, IActionParameter[] parameters) {
if (parameters[0] != null) {
IPipe pipe = gate.getPipe();
if (pipe != null && pipe instanceof Pipe) {
PipeTransport transport = ((Pipe) pipe).transport;
ForgeDirection side = ((ActionParameterDirection) parameters[0]).direction;
if (side != ForgeDirection.UNKNOWN) {
transport.allowInput(side, state.inputOpen);
transport.allowOutput(side, state.outputOpen);
}
}
}
}
}