From 1dfd9dbd3498f1013f8ff84949c3b714021c90d4 Mon Sep 17 00:00:00 2001 From: charles Date: Tue, 30 Mar 2021 11:20:20 -0600 Subject: Made it so that machine control covers disable themselves when the machine runs out of energy --- .../java/gregtech/common/covers/GT_Cover_ControlsWork.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/common/covers') 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 487d457b39..d8f2c19c37 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -16,11 +16,16 @@ import net.minecraftforge.fluids.Fluid; public class GT_Cover_ControlsWork extends GT_CoverBehavior { public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { if (aTileEntity instanceof IMachineProgress) { - if ((aInputRedstone > 0) == (aCoverVariable == 0) && aCoverVariable != 2) - ((IMachineProgress) aTileEntity).enableWorking(); - else + if (!((IMachineProgress) aTileEntity).wasShutdown()) { + if ((aInputRedstone > 0) == (aCoverVariable == 0) && aCoverVariable != 2) + ((IMachineProgress) aTileEntity).enableWorking(); + else + ((IMachineProgress) aTileEntity).disableWorking(); + ((IMachineProgress) aTileEntity).setWorkDataValue(aInputRedstone); + } else { ((IMachineProgress) aTileEntity).disableWorking(); - ((IMachineProgress) aTileEntity).setWorkDataValue(aInputRedstone); + return 2; + } } return aCoverVariable; } -- cgit From 320fc85f4b2856d83f98c8c58bc76853e2cea207 Mon Sep 17 00:00:00 2001 From: charles Date: Tue, 30 Mar 2021 20:23:50 -0600 Subject: Added GUI interface for cover "Safe Mode" Added tracking of last player to access a cover for future notification purposes. --- .../java/gregtech/api/util/GT_CoverBehavior.java | 3 ++ .../common/covers/GT_Cover_ControlsWork.java | 63 ++++++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-) (limited to 'src/main/java/gregtech/common/covers') diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index c0ad751add..ef332ddb01 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -15,6 +15,9 @@ import static gregtech.api.enums.GT_Values.E; * For Covers with a special behavior. */ public abstract class GT_CoverBehavior { + + public EntityPlayer lastPlayer = null; + /** * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. */ 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 d8f2c19c37..dbe9f7d9c0 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -1,30 +1,45 @@ package gregtech.common.covers; +import cpw.mods.fml.client.FMLClientHandler; import gregtech.api.enums.GT_Values; import gregtech.api.gui.GT_GUICover; import gregtech.api.gui.widgets.GT_GuiIcon; import gregtech.api.gui.widgets.GT_GuiIconButton; +import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; +import net.minecraft.world.WorldServer; + +import static gregtech.GT_Mod.GT_FML_LOGGER; public class GT_Cover_ControlsWork extends GT_CoverBehavior { public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { if (aTileEntity instanceof IMachineProgress) { - if (!((IMachineProgress) aTileEntity).wasShutdown()) { - if ((aInputRedstone > 0) == (aCoverVariable == 0) && aCoverVariable != 2) + if (aCoverVariable < 2) { + if ((aInputRedstone > 0) == (aCoverVariable == 0)) ((IMachineProgress) aTileEntity).enableWorking(); else ((IMachineProgress) aTileEntity).disableWorking(); ((IMachineProgress) aTileEntity).setWorkDataValue(aInputRedstone); - } else { + } + else if (aCoverVariable == 2) { ((IMachineProgress) aTileEntity).disableWorking(); - return 2; + } else { + if (((IMachineProgress) aTileEntity).wasShutdown()) { + ((IMachineProgress) aTileEntity).disableWorking(); + // TODO: Notify lastPlayer the name and location of machine and that it stopped + return 2; + } else { + return 3 + doCoverThings(aSide,aInputRedstone, aCoverID, aCoverVariable - 3, aTileEntity, aTimer); + } } } return aCoverVariable; @@ -63,17 +78,24 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { } 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)) % 3; + aCoverVariable = (aCoverVariable + (aPlayer.isSneaking()? -1 : 1)) % 5; if(aCoverVariable <0){aCoverVariable = 2;} if (aCoverVariable == 0) { - GT_Utility.sendChatToPlayer(aPlayer, trans("003", "Normal")); + GT_Utility.sendChatToPlayer(aPlayer, trans("003", "Enable with Signal")); } if (aCoverVariable == 1) { - GT_Utility.sendChatToPlayer(aPlayer, trans("004", "Inverted")); + GT_Utility.sendChatToPlayer(aPlayer, trans("004", "Disable with Signal")); } if (aCoverVariable == 2) { - GT_Utility.sendChatToPlayer(aPlayer, trans("005", "No Work at all")); + GT_Utility.sendChatToPlayer(aPlayer, trans("005", "Disabled")); + } + if (aCoverVariable == 3) { + GT_Utility.sendChatToPlayer(aPlayer, trans("505", "Enable with Signal (Safe)")); + } + if (aCoverVariable == 4) { + GT_Utility.sendChatToPlayer(aPlayer, trans("506", "Disable with Signal (Safe)")); } + // TODO: Set lastPlayer return aCoverVariable; } @@ -115,6 +137,8 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { b = new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.REDSTONE_ON); b = new GT_GuiIconButton(this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.REDSTONE_OFF); b = new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CROSS); + + b = new GT_GuiIconCheckButton(this, 3, startX + spaceX * 0, startY + spaceY * 3, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS); } @Override @@ -123,6 +147,7 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { this.fontRendererObj.drawString(trans("243", "Enable with Redstone"), 3+startX + spaceX*1, 4+startY+spaceY*0, 0xFF555555); this.fontRendererObj.drawString(trans("244", "Disable with Redstone"),3+startX + spaceX*1, 4+startY+spaceY*1, 0xFF555555); this.fontRendererObj.drawString(trans("245", "Disable machine"), 3+startX + spaceX*1, 4+startY+spaceY*2, 0xFF555555); + this.fontRendererObj.drawString(trans("507", "Safe Mode"), 3+startX + spaceX*1, 4+startY+spaceY*3, 0xFF555555); } @Override @@ -132,7 +157,14 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { public void buttonClicked(GuiButton btn) { if (getClickable(btn.id)) { - coverVariable = getNewCoverVariable(btn.id); + int bID = btn.id; + if (bID == 3) { + ((GT_GuiIconCheckButton) btn).setChecked(!((GT_GuiIconCheckButton) btn).isChecked()); + } else { + coverVariable = getNewCoverVariable(bID); + } + adjustCoverVariable(); + // TODO: Set lastPlayer; GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); } updateButtons(); @@ -151,7 +183,18 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { } private boolean getClickable(int id) { - return id != coverVariable; + return ((id != coverVariable && id != coverVariable - 3) || id == 3); + } + + private void adjustCoverVariable() { + boolean safeMode = ((GT_GuiIconCheckButton) buttonList.get(3)).isChecked(); + if (safeMode && coverVariable < 2) { + coverVariable += 3; + } + if (!safeMode && coverVariable > 2) { + coverVariable -= 3; + } } + } } -- cgit From 486dacc5d03c2d2c89297ab673479d2c17085d0e Mon Sep 17 00:00:00 2001 From: charles Date: Fri, 2 Apr 2021 16:53:33 -0600 Subject: Added scanning data reflecting if device shut down. Added notification to player that device shut down. Added scanning data reflecting if the device was disabled by soft mallet, cover, etc. --- src/main/java/gregtech/api/util/GT_Utility.java | 6 ++++++ src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/common/covers') diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index a9ba9b9bbc..9558df4608 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1981,6 +1981,12 @@ public class GT_Utility { } try { if (tTileEntity instanceof IMachineProgress) { + if (((IMachineProgress) tTileEntity).isAllowedToWork()) { + tList.add("Disabled." + EnumChatFormatting.RED + EnumChatFormatting.RESET); + } + if (((IMachineProgress) tTileEntity).wasShutdown()) { + tList.add("Shut down due to power loss." + EnumChatFormatting.RED + EnumChatFormatting.RESET); + } rEUAmount += 400; int tValue = 0; if (0 < (tValue = ((IMachineProgress) tTileEntity).getMaxProgress())) 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 dbe9f7d9c0..ba943e4286 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -8,6 +8,7 @@ import gregtech.api.gui.widgets.GT_GuiIconButton; import gregtech.api.gui.widgets.GT_GuiIconCheckButton; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; +import gregtech.api.metatileentity.BaseTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; @@ -35,7 +36,7 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { } else { if (((IMachineProgress) aTileEntity).wasShutdown()) { ((IMachineProgress) aTileEntity).disableWorking(); - // TODO: Notify lastPlayer the name and location of machine and that it stopped + 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); -- cgit