diff options
author | Martin Robertz <dream-master@gmx.net> | 2022-03-02 20:28:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 20:28:16 +0100 |
commit | cdb0f7adbe069f258ebe653cf553eca04c87e8db (patch) | |
tree | 2a2b15f1df5fd20042f8a73bfea95bf5a15b4e6d /src | |
parent | 058ef46cb368f3a311a39b2a67110b080d373221 (diff) | |
download | GT5-Unofficial-cdb0f7adbe069f258ebe653cf553eca04c87e8db.tar.gz GT5-Unofficial-cdb0f7adbe069f258ebe653cf553eca04c87e8db.tar.bz2 GT5-Unofficial-cdb0f7adbe069f258ebe653cf553eca04c87e8db.zip |
add locks to the node graph so paths can block power transfer #25 (#950)
Co-authored-by: bot <Krampus.sack.never@gmail.com>
Diffstat (limited to 'src')
11 files changed, 224 insertions, 44 deletions
diff --git a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java index 7ef57fa6d2..4d1b7a7461 100644 --- a/src/main/java/gregtech/api/graphs/GenerateNodeMap.java +++ b/src/main/java/gregtech/api/graphs/GenerateNodeMap.java @@ -67,10 +67,13 @@ abstract public class GenerateNodeMap { aNextNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mHighestNodeValue = tNextNode.mHighestNodeValue; aPipeNode.mNeighbourNodes[i] = tNextNode; - aPipeNode.mNodePaths[i] = aPipeNode.mReturnPath; + aPipeNode.mNodePaths[i] = aPipeNode.returnValues.mReturnPath; + aPipeNode.locks[i] = aPipeNode.returnValues.returnLock; + aPipeNode.mNodePaths[i].reloadLocks(); } } } + aPipe.reloadLocks(); } // on a valid tile entity create a new node @@ -98,7 +101,11 @@ abstract public class GenerateNodeMap { if (tInvalidSide > -1) { tPipeNode.mNeighbourNodes[tInvalidSide] = aPreviousNode; tPipeNode.mNodePaths[tInvalidSide] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); - aPreviousNode.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; + Lock lock = new Lock(); + tPipeNode.mNodePaths[tSideOp].lock = lock; + tPipeNode.locks[tInvalidSide] = lock; + aPreviousNode.returnValues.mReturnPath = tPipeNode.mNodePaths[tInvalidSide]; + aPreviousNode.returnValues.returnLock = lock; } if (tConnections > 1) generateNextNode(tPipe, tPipeNode, tInvalidSide, aNextNodeValue, aConsumers, aNodeMap); @@ -106,7 +113,10 @@ abstract public class GenerateNodeMap { ConsumerNode tConsumeNode = aConsumers.get(aConsumers.size() - 1); tConsumeNode.mNeighbourNodes[tSideOp] = aPreviousNode; tConsumeNode.mNodePaths[tSideOp] = getNewPath(aPipes.toArray(new MetaPipeEntity[0])); - aPreviousNode.mReturnPath = tConsumeNode.mNodePaths[tSideOp]; + Lock lock = new Lock(); + tConsumeNode.mNodePaths[tSideOp].lock = lock; + aPreviousNode.returnValues.mReturnPath = tConsumeNode.mNodePaths[tSideOp]; + aPreviousNode.returnValues.returnLock = lock; tThisNode = tConsumeNode; } return tThisNode; diff --git a/src/main/java/gregtech/api/graphs/Lock.java b/src/main/java/gregtech/api/graphs/Lock.java new file mode 100644 index 0000000000..0ba43b83de --- /dev/null +++ b/src/main/java/gregtech/api/graphs/Lock.java @@ -0,0 +1,37 @@ +package gregtech.api.graphs; + +import net.minecraft.tileentity.TileEntity; + +import java.util.ArrayList; + +public class Lock { + protected ArrayList<TileEntity> tiles = new ArrayList<>(); + + public void addTileEntity(TileEntity tileEntity) { + int i = contains(tileEntity); + if (i == -1) { + tiles.add(tileEntity); + } + } + + public void removeTileEntity(TileEntity tileEntity) { + int i = contains(tileEntity); + if (i > -1) { + tiles.remove(i); + } + } + + public boolean isLocked() { + return !tiles.isEmpty(); + } + + //i want to check for the exact object not equals + protected int contains(TileEntity tileEntity) { + for (int i = 0; i < tiles.size(); i++) { + if (tiles.get(i) == tileEntity) { + return i; + } + } + return -1; + } +} diff --git a/src/main/java/gregtech/api/graphs/Node.java b/src/main/java/gregtech/api/graphs/Node.java index 815c7dd46e..be499dea0d 100644 --- a/src/main/java/gregtech/api/graphs/Node.java +++ b/src/main/java/gregtech/api/graphs/Node.java @@ -4,11 +4,12 @@ import gregtech.api.graphs.consumers.ConsumerNode; import gregtech.api.graphs.paths.NodePath; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; + import java.util.ArrayList; // base Node class public class Node { - public Node(int aNodeValue,TileEntity aTileEntity,ArrayList<ConsumerNode> aConsumers){ + public Node(int aNodeValue, TileEntity aTileEntity, ArrayList<ConsumerNode> aConsumers) { this.mNodeValue = aNodeValue; this.mTileEntity = aTileEntity; this.mConsumers = aConsumers; @@ -18,13 +19,19 @@ public class Node { } - public int mCreationTime; - public NodePath mSelfPath; - public ArrayList<ConsumerNode> mConsumers; - public int mNodeValue; public final TileEntity mTileEntity; public Node[] mNeighbourNodes = new Node[6]; public NodePath[] mNodePaths = new NodePath[6]; - public NodePath mReturnPath; + public Lock[] locks = new Lock[6]; + public ReturnPair returnValues = new ReturnPair(); + public NodePath mSelfPath; + public ArrayList<ConsumerNode> mConsumers; + public int mCreationTime; + public int mNodeValue; public int mHighestNodeValue; + + public class ReturnPair { + public NodePath mReturnPath; + public Lock returnLock; + } } diff --git a/src/main/java/gregtech/api/graphs/PowerNodes.java b/src/main/java/gregtech/api/graphs/PowerNodes.java index 7a3364648a..e5d0e56699 100644 --- a/src/main/java/gregtech/api/graphs/PowerNodes.java +++ b/src/main/java/gregtech/api/graphs/PowerNodes.java @@ -34,7 +34,7 @@ public class PowerNodes { final Node tNextNode = aCurrentNode.mNeighbourNodes[j]; if (tNextNode != null && tNextNode.mNodeValue < aCurrentNode.mNodeValue) { if (tNextNode.mNodeValue == tConsumer.mNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, j, aMaxAmps - tAmpsUsed, aVoltage, false); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, j, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } else { @@ -56,7 +56,7 @@ public class PowerNodes { tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } @@ -92,7 +92,7 @@ public class PowerNodes { tConsumer = (ConsumerNode) aConsumers.getNode(); break; } else if (tNextNode.mNodeValue == tTargetNodeValue) { - tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage, true); + tAmpsUsed += processNodeInject(aCurrentNode, tConsumer, side, aMaxAmps - tAmpsUsed, aVoltage); tConsumer = (ConsumerNode) aConsumers.getNextNode(); break; } @@ -109,6 +109,10 @@ public class PowerNodes { } protected static long processNextNode(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) { + aConsumers.getNextNode(); + return 0; + } final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; @@ -126,6 +130,10 @@ public class PowerNodes { } protected static long processNextNodeAbove(Node aCurrentNode, Node aNextNode, NodeList aConsumers, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) { + aConsumers.getNextNode(); + return 0; + } final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; @@ -142,7 +150,8 @@ public class PowerNodes { return tAmps; } - protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, long aVoltage, boolean isUp) { + protected static long processNodeInject(Node aCurrentNode, ConsumerNode aConsumer, int aSide, long aMaxAmps, long aVoltage) { + if (aCurrentNode.locks[aSide].isLocked()) return 0; final PowerNodePath tPath = (PowerNodePath) aCurrentNode.mNodePaths[aSide]; final PowerNodePath tSelfPath = (PowerNodePath) aCurrentNode.mSelfPath; long tVoltLoss = 0; diff --git a/src/main/java/gregtech/api/graphs/paths/NodePath.java b/src/main/java/gregtech/api/graphs/paths/NodePath.java index bdf82ec5b0..efdcd1aecb 100644 --- a/src/main/java/gregtech/api/graphs/paths/NodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/NodePath.java @@ -1,11 +1,13 @@ package gregtech.api.graphs.paths; +import gregtech.api.graphs.Lock; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; //to contain all info about the path between nodes public class NodePath { protected MetaPipeEntity[] mPipes; + public Lock lock; public NodePath(MetaPipeEntity[] aCables) { this.mPipes = aCables; @@ -20,11 +22,20 @@ public class NodePath { } public void clearPath() { - for (int i = 0; i < mPipes.length; i++) { - BaseMetaPipeEntity tBasePipe = (BaseMetaPipeEntity) mPipes[i].getBaseMetaTileEntity(); + for (MetaPipeEntity mPipe : mPipes) { + BaseMetaPipeEntity tBasePipe = (BaseMetaPipeEntity) mPipe.getBaseMetaTileEntity(); if (tBasePipe != null) { tBasePipe.setNodePath(null); } } } + + public void reloadLocks() { + for (MetaPipeEntity pipe : mPipes) { + BaseMetaPipeEntity basePipe = (BaseMetaPipeEntity) pipe.getBaseMetaTileEntity(); + if (basePipe != null) { + basePipe.reloadLocks(); + } + } + } } diff --git a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java index 72b2edb334..d18d6bcdd3 100644 --- a/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java +++ b/src/main/java/gregtech/api/graphs/paths/PowerNodePath.java @@ -37,6 +37,7 @@ public class PowerNodePath extends NodePath { this.mVoltage = aVoltage; } if (aVoltage > mMaxVoltage) { + lock.addTileEntity(null); for (MetaPipeEntity tCable : mPipes) { if (((GT_MetaPipeEntity_Cable) tCable).mVoltage < this.mVoltage) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); @@ -51,6 +52,7 @@ public class PowerNodePath extends NodePath { private void reset(int aTimePassed) { if (aTimePassed < 0 || aTimePassed > 100) { mAmps = 0; + return; } mAmps = Math.max(0, mAmps - (mMaxAmps * aTimePassed)); } @@ -58,6 +60,7 @@ public class PowerNodePath extends NodePath { public void addAmps(long aAmps) { this.mAmps += aAmps; if (this.mAmps > mMaxAmps * 40) { + lock.addTileEntity(null); for (MetaPipeEntity tCable : mPipes) { if (((GT_MetaPipeEntity_Cable) tCable).mAmperage * 40 < this.mAmps) { BaseMetaPipeEntity tBaseCable = (BaseMetaPipeEntity) tCable.getBaseMetaTileEntity(); diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 338724cf20..2f7504a4ce 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -2,14 +2,18 @@ package gregtech.api.metatileentity; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.metatileentity.BaseMetaTileEntity.COVER_DATA_NBT_KEYS; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; +import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.graphs.Lock; import gregtech.api.graphs.Node; import gregtech.api.graphs.paths.NodePath; import gregtech.api.interfaces.ITexture; @@ -19,10 +23,9 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; import gregtech.api.net.GT_Packet_TileEntity; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; -import gregtech.api.util.GT_Utility; +import gregtech.api.util.*; +import gregtech.common.GT_Client; +import gregtech.common.covers.GT_Cover_Fluidfilter; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -30,12 +33,22 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.Packet; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.enums.GT_Values.NW; +import static gregtech.api.metatileentity.BaseMetaTileEntity.COVER_DATA_NBT_KEYS; + /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> @@ -69,6 +82,34 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I this.nodePath = nodePath; } + public void addToLock(TileEntity tileEntity, int side) { + if (node != null) { + Lock lock = node.locks[side]; + if (lock != null) { + lock.addTileEntity(tileEntity); + } + } else if (nodePath != null) { + nodePath.lock.addTileEntity(tileEntity); + } + } + + public void removeFromLock(TileEntity tileEntity, int side) { + if (node != null) { + Lock lock = node.locks[side]; + if (lock != null) { + lock.removeTileEntity(tileEntity); + } + } else if (nodePath != null) { + nodePath.lock.removeTileEntity(tileEntity); + } + } + + public void reloadLocks() { + IMetaTileEntity meta = getMetaTileEntity(); + if (meta instanceof MetaPipeEntity) { + ((MetaPipeEntity) meta).reloadLocks(); + } + } public BaseMetaPipeEntity() { } @@ -533,11 +574,13 @@ public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements I public void enableWorking() { if (!mWorks) mWorkUpdate = true; mWorks = true; + reloadLocks(); } @Override public void disableWorking() { mWorks = false; + reloadLocks(); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 7d4fd38b8b..c8727131c8 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -859,14 +859,24 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { public boolean letsIn(GT_CoverBehaviorBase<?> coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } public boolean letsOut(GT_CoverBehaviorBase<?> coverBehavior, byte aSide, int aCoverID, ISerializableObject aCoverVariable, ICoverable aTileEntity) { return false; } - public boolean canConnect(byte aSide, TileEntity tTileEntity) { return false; } - public boolean getGT6StyleConnection() { return false; } + public boolean canConnect(byte aSide, TileEntity tTileEntity) { + return false; + } + + public boolean getGT6StyleConnection() { + return false; + } @Override - public boolean shouldJoinIc2Enet() { return false; } + public boolean shouldJoinIc2Enet() { + return false; + } @Override public boolean isMachineBlockUpdateRecursive() { return false; } + + public void reloadLocks() { + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java index 788753f0cc..08f55715cb 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Cable.java @@ -8,11 +8,11 @@ import gregtech.api.enums.Dyes; import gregtech.api.enums.Materials; import gregtech.api.enums.TextureSet; import gregtech.api.enums.Textures; +import gregtech.api.graphs.Node; +import gregtech.api.graphs.NodeList; import gregtech.api.graphs.PowerNode; import gregtech.api.graphs.PowerNodes; import gregtech.api.graphs.consumers.ConsumerNode; -import gregtech.api.graphs.Node; -import gregtech.api.graphs.NodeList; import gregtech.api.graphs.paths.PowerNodePath; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -22,6 +22,7 @@ import gregtech.api.interfaces.tileentity.IEnergyConnected; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; +import gregtech.api.objects.GT_Cover_None; import gregtech.api.render.TextureFactory; import gregtech.api.util.*; import gregtech.common.GT_Client; @@ -449,7 +450,7 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile for( byte aSide = 0 ; aSide < 6 ; aSide++) if(isConnectedAtSide(aSide)) { final TileEntity tTileEntity = baseMeta.getTileEntityAtSide(aSide); final TileEntity tEmitter = (tTileEntity == null || tTileEntity instanceof IEnergyTile || EnergyNet.instance == null) ? tTileEntity : - EnergyNet.instance.getTileEntity(tTileEntity.getWorldObj(), tTileEntity.xCoord, tTileEntity.yCoord, tTileEntity.zCoord); + EnergyNet.instance.getTileEntity(tTileEntity.getWorldObj(), tTileEntity.xCoord, tTileEntity.yCoord, tTileEntity.zCoord); if (tEmitter instanceof IEnergyEmitter) return true; @@ -458,4 +459,42 @@ public class GT_MetaPipeEntity_Cable extends MetaPipeEntity implements IMetaTile } return false; } + + @Override + public void reloadLocks() { + BaseMetaPipeEntity pipe = (BaseMetaPipeEntity) getBaseMetaTileEntity(); + if (pipe.getNode() != null) { + for (byte i = 0; i < 6; i++) { + if (isConnectedAtSide(i)) { + final GT_CoverBehaviorBase<?> coverBehavior = pipe.getCoverBehaviorAtSideNew(i); + if (coverBehavior instanceof GT_Cover_None) continue; + final int coverId = pipe.getCoverIDAtSide(i); + ISerializableObject coverData = pipe.getComplexCoverDataAtSide(i); + if (!letsIn(coverBehavior, i, coverId, coverData, pipe) || !letsOut(coverBehavior, i, coverId, coverData, pipe)) { + pipe.addToLock(pipe, i); + } else { + pipe.removeFromLock(pipe, i); + } + } + } + } else { + boolean dontAllow = false; + for (byte i = 0; i < 6; i++) { + if (isConnectedAtSide(i)) { + final GT_CoverBehaviorBase<?> coverBehavior = pipe.getCoverBehaviorAtSideNew(i); + if (coverBehavior instanceof GT_Cover_None) continue; + final int coverId = pipe.getCoverIDAtSide(i); + ISerializableObject coverData = pipe.getComplexCoverDataAtSide(i); + if (!letsIn(coverBehavior, i, coverId, coverData, pipe) || !letsOut(coverBehavior, i, coverId, coverData, pipe)) { + dontAllow = true; + } + } + } + if (dontAllow) { + pipe.addToLock(pipe, 0); + } else { + pipe.removeFromLock(pipe, 0); + } + } + } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java index a25fb2b1f4..e1bb8bcd3e 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -18,22 +18,23 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { @Override public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { if (aTileEntity instanceof IMachineProgress) { + IMachineProgress machine = (IMachineProgress) aTileEntity; if (aCoverVariable < 2) { - if ((aInputRedstone > 0) == (aCoverVariable == 0)) - ((IMachineProgress) aTileEntity).enableWorking(); - else - ((IMachineProgress) aTileEntity).disableWorking(); - ((IMachineProgress) aTileEntity).setWorkDataValue(aInputRedstone); - } - else if (aCoverVariable == 2) { - ((IMachineProgress) aTileEntity).disableWorking(); + if ((aInputRedstone > 0) == (aCoverVariable == 0)) { + if (!machine.isAllowedToWork()) + machine.enableWorking(); + } else if (machine.isAllowedToWork()) + machine.disableWorking(); + machine.setWorkDataValue(aInputRedstone); + } else if (aCoverVariable == 2 && machine.isAllowedToWork()) { + machine.disableWorking(); } else { - if (((IMachineProgress) aTileEntity).wasShutdown()) { - ((IMachineProgress) aTileEntity).disableWorking(); - GT_Utility.sendChatToPlayer(lastPlayer, aTileEntity.getInventoryName() + " at " + String.format("(%d,%d,%d)", aTileEntity.getXCoord(), aTileEntity.getYCoord(), aTileEntity.getZCoord()) + " shut down."); + if (machine.wasShutdown()) { + machine.disableWorking(); + GT_Utility.sendChatToPlayer(lastPlayer, aTileEntity.getInventoryName() + "at " + String.format("(%d,%d,%d)", aTileEntity.getXCoord(), aTileEntity.getYCoord(), aTileEntity.getZCoord()) + " shut down."); return 2; } else { - return 3 + doCoverThings(aSide,aInputRedstone, aCoverID, aCoverVariable - 3, aTileEntity, aTimer); + return 3 + doCoverThings(aSide, aInputRedstone, aCoverID, aCoverVariable - 3, aTileEntity, aTimer); } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java b/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java index df800302c9..b8ce4260cd 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java @@ -6,6 +6,7 @@ import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; @@ -26,17 +27,26 @@ public class GT_Cover_Shutter extends GT_CoverBehavior { @Override public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { - aCoverVariable = (aCoverVariable + (aPlayer.isSneaking()? -1 : 1)) % 4; - if(aCoverVariable <0){aCoverVariable = 3;} - switch(aCoverVariable) { + aCoverVariable = (aCoverVariable + (aPlayer.isSneaking() ? -1 : 1)) % 4; + if (aCoverVariable < 0) { + aCoverVariable = 3; + } + switch (aCoverVariable) { case 0: - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("082", "Open if work enabled")); break; + GT_Utility.sendChatToPlayer(aPlayer, trans("082", "Open if work enabled")); + break; case 1: - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("083", "Open if work disabled")); break; + GT_Utility.sendChatToPlayer(aPlayer, trans("083", "Open if work disabled")); + break; case 2: - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("084", "Only Output allowed")); break; + GT_Utility.sendChatToPlayer(aPlayer, trans("084", "Only Output allowed")); + break; case 3: - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("085", "Only Input allowed")); break; + GT_Utility.sendChatToPlayer(aPlayer, trans("085", "Only Input allowed")); + break; + } + if (aTileEntity instanceof BaseMetaPipeEntity) { + ((BaseMetaPipeEntity) aTileEntity).reloadLocks(); } return aCoverVariable; } |