From 2374bd1526fffc1c77eca9ec4338da141e3adaf8 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 19 Oct 2014 21:04:02 +0200 Subject: [PATCH] fix #1901 and #2061 --- common/buildcraft/BuildCraftTransport.java | 4 +- common/buildcraft/transport/Gate.java | 5 +-- .../transport/PipeActionProvider.java | 42 +++++++++++++++++++ .../buildcraft/transport/PipeTransport.java | 8 ++-- .../transport/PipeTriggerProvider.java | 17 ++++---- .../buildcraft/transport/TileGenericPipe.java | 17 ++------ .../transport/gui/ContainerGateInterface.java | 3 -- 7 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 common/buildcraft/transport/PipeActionProvider.java diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 3a6b5f4b..bb660f46 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -66,6 +66,7 @@ import buildcraft.transport.ItemPipeWire; import buildcraft.transport.ItemPlug; import buildcraft.transport.ItemRobotStation; import buildcraft.transport.Pipe; +import buildcraft.transport.PipeActionProvider; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTriggerProvider; import buildcraft.transport.TileFilteredBuffer; @@ -533,7 +534,8 @@ public class BuildCraftTransport extends BuildCraftMod { StatementManager.registerParameterClass("buildcraft:pipeWireTrigger", TriggerParameterSignal.class); StatementManager.registerParameterClass("buildcraft:pipeWireAction", ActionParameterSignal.class); StatementManager.registerTriggerProvider(new PipeTriggerProvider()); - + StatementManager.registerActionProvider(new PipeActionProvider()); + if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); } diff --git a/common/buildcraft/transport/Gate.java b/common/buildcraft/transport/Gate.java index 82e63166..7ed27980 100644 --- a/common/buildcraft/transport/Gate.java +++ b/common/buildcraft/transport/Gate.java @@ -21,9 +21,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; - import net.minecraftforge.common.util.ForgeDirection; - import buildcraft.BuildCraftTransport; import buildcraft.api.gates.GateExpansionController; import buildcraft.api.gates.IAction; @@ -465,8 +463,7 @@ public final class Gate implements IGate { } // TRIGGERS - public void addTrigger(List list) { - + public void addTriggers(List list) { for (PipeWire wire : PipeWire.VALUES) { if (pipe.wireSet[wire.ordinal()] && material.ordinal() >= wire.ordinal()) { list.add(BuildCraftTransport.triggerPipeWireActive[wire.ordinal()]); diff --git a/common/buildcraft/transport/PipeActionProvider.java b/common/buildcraft/transport/PipeActionProvider.java new file mode 100644 index 00000000..f905b05d --- /dev/null +++ b/common/buildcraft/transport/PipeActionProvider.java @@ -0,0 +1,42 @@ +package buildcraft.transport; + +import java.util.Collection; +import java.util.LinkedList; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import buildcraft.api.gates.IAction; +import buildcraft.api.gates.IActionProvider; +import buildcraft.api.transport.IPipeTile; + +public class PipeActionProvider implements IActionProvider { + + @Override + public Collection getPipeActions(IPipeTile tile) { + LinkedList result = new LinkedList(); + Pipe pipe = null; + if (tile instanceof TileGenericPipe) { + pipe = ((TileGenericPipe) tile).pipe; + } + + if (pipe == null) { + return result; + } + + result.addAll(pipe.getActions()); + + for (Gate gate : pipe.gates) { + if (gate != null) { + gate.addActions(result); + } + } + + return result; + } + + @Override + public Collection getNeighborActions(Block block, TileEntity tile) { + return null; + } + +} diff --git a/common/buildcraft/transport/PipeTransport.java b/common/buildcraft/transport/PipeTransport.java index 4bbcb448..145c66b3 100644 --- a/common/buildcraft/transport/PipeTransport.java +++ b/common/buildcraft/transport/PipeTransport.java @@ -39,8 +39,8 @@ public abstract class PipeTransport { } public void readFromNBT(NBTTagCompound nbt) { - if (nbt.hasKey("inputOpen")) { - BitSet inputBuf = BitSet.valueOf(new byte [] {nbt.getByte("inputOpen")}); + if (nbt.hasKey("inputOpen") && nbt.hasKey("outputOpen")) { + BitSet inputBuf = BitSet.valueOf(new byte[] {nbt.getByte("inputOpen")}); BitSet outputBuf = BitSet.valueOf(new byte[] {nbt.getByte("outputOpen")}); for (int b = 0; b < ForgeDirection.VALID_DIRECTIONS.length; b++) { @@ -51,8 +51,8 @@ public abstract class PipeTransport { } public void writeToNBT(NBTTagCompound nbt) { - BitSet inputBuf = new BitSet(); - BitSet outputBuf = new BitSet(); + BitSet inputBuf = new BitSet(ForgeDirection.VALID_DIRECTIONS.length); + BitSet outputBuf = new BitSet(ForgeDirection.VALID_DIRECTIONS.length); for (int b = 0; b < ForgeDirection.VALID_DIRECTIONS.length; b++) { if (inputsOpen[b]) { diff --git a/common/buildcraft/transport/PipeTriggerProvider.java b/common/buildcraft/transport/PipeTriggerProvider.java index e610dbd4..175edd21 100644 --- a/common/buildcraft/transport/PipeTriggerProvider.java +++ b/common/buildcraft/transport/PipeTriggerProvider.java @@ -36,15 +36,19 @@ public class PipeTriggerProvider implements ITriggerProvider { if (pipe == null) { return result; - } else if (pipe instanceof IOverrideDefaultTriggers) { - return ((IOverrideDefaultTriggers) pipe).getTriggers(); } + + boolean containsGate = false; for (Gate gate : pipe.gates) { if (gate != null) { - gate.addTrigger(result); + containsGate = true; + gate.addTriggers(result); } } + + result.add(BuildCraftCore.triggerRedstoneActive); + result.add(BuildCraftCore.triggerRedstoneInactive); switch (tile.getPipeType()) { case ITEM: @@ -59,11 +63,10 @@ public class PipeTriggerProvider implements ITriggerProvider { result.add(TriggerPipeContents.PipeContents.empty.trigger); result.add(TriggerPipeContents.PipeContents.containsEnergy.trigger); result.add(TriggerPipeContents.PipeContents.tooMuchEnergy.trigger); - result.add(TriggerPipeContents.PipeContents.requestsEnergy.trigger); - + result.add(TriggerPipeContents.PipeContents.requestsEnergy.trigger); + break; + case STRUCTURE: break; - case STRUCTURE: - break; } if (tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(ForgeDirection.UNKNOWN) > 0) { diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index ac56dfdd..872fabbc 100755 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -66,8 +66,8 @@ import buildcraft.transport.gates.ItemGate; import buildcraft.transport.utils.RobotStationState; public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, - IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, IEnergyHandler, - IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler { + IPipeTile, ITileBufferHolder, IEnergyHandler, IDropControlInventory, + ISyncedTile, ISolidSideTile, IGuiReturnHandler { public boolean initialized = false; public final PipeRenderState renderState = new PipeRenderState(); @@ -646,18 +646,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui sendClientUpdate = true; } - @Override - public LinkedList getTriggers() { - LinkedList result = new LinkedList(); - - if (BlockGenericPipe.isFullyDefined(pipe) && pipe.hasGate()) { - result.add(BuildCraftCore.triggerRedstoneActive); - result.add(BuildCraftCore.triggerRedstoneInactive); - } - - return result; - } - @Override public void blockRemoved(ForgeDirection from) { @@ -871,6 +859,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui public boolean addGate(ForgeDirection direction, Gate gate) { gate.setDirection(direction); + pipe.gates[direction.ordinal()] = gate; return setPluggable(direction, new ItemGate.GatePluggable(gate)); } diff --git a/common/buildcraft/transport/gui/ContainerGateInterface.java b/common/buildcraft/transport/gui/ContainerGateInterface.java index 83314095..6e727216 100644 --- a/common/buildcraft/transport/gui/ContainerGateInterface.java +++ b/common/buildcraft/transport/gui/ContainerGateInterface.java @@ -105,11 +105,8 @@ public class ContainerGateInterface extends BuildCraftContainer { // Do not attempt to create a list of potential actions and triggers on // the client. if (!pipe.container.getWorldObj().isRemote) { - potentialActions.addAll(gate.getActions()); - potentialActions.addAll(pipe.getActions()); potentialTriggers.addAll(StatementManager.getPipeTriggers(pipe.container)); potentialActions.addAll(StatementManager.getPipeActions(pipe.container)); - potentialTriggers.addAll(pipe.container.getTriggers()); for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { TileEntity tile = pipe.container.getTile(o);