From 1842f59eeb837edecfc31dae8a2b35fcda471b38 Mon Sep 17 00:00:00 2001 From: Mary <33456283+FourIsTheNumber@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:27:40 -0400 Subject: Mode switch button (#2730) * Button textures. Once again I am manually pulling changes from a different branch... sorry. If you want to read the full commit history, the modeswitchgui branch has it. * Texture enums * Implementation in ControllerWithOptionalFeatures * Implementation in GT_MetaTileEntity_MultiBlockBase * Implemented into all multi-machines * Lang changes * Added documentation * Added missing clear * Quick polish changes - button base texture is standard instead of pressed, and the click noise works. * MFE compatibility * TurboCan compatibility * Fix misordered icons in canner * Removed redundant code in button * Attempted to refactor with MachineMode enum. Also moved loadNBT and saveNBT logic to base class * sa * fix (cherry picked from commit 1f14a7abf460ad114f10e8ba58b6be44b7b18d48) * Rework machineMode into enum of IMachineMode completely * Fixed breaking typo * Made it stop crashing on normal multis that don't support mode switch * Revert * Finished revert and re-addressed changes from original review * spotless * Load nbt tags in correct order. Fixes backwards compat * Check nbt key on load instead * Run super last and make all MACHINEMODE static --------- Co-authored-by: Martin Robertz --- .../GT_MetaTileEntity_MultiBlockBase.java | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/main/java/gregtech/api/metatileentity/implementations') diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 3d34a6c62a..735119d8bf 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -44,6 +44,7 @@ import org.lwjgl.input.Keyboard; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.gtnewhorizons.modularui.api.NumberFormatMUI; +import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.math.Alignment; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.screen.ModularWindow; @@ -127,6 +128,8 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity public String mNEI; public int damageFactorLow = 5; public float damageFactorHigh = 0.6f; + public int machineMode = 0; + public List machineModeIcons = new ArrayList(); public boolean mLockedToSingleRecipe = getDefaultRecipeLockingMode(); protected boolean inputSeparation = getDefaultInputSeparationMode(); @@ -253,6 +256,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity aNBT.setInteger("mEfficiency", mEfficiency); aNBT.setInteger("mPollution", mPollution); aNBT.setInteger("mRuntime", mRuntime); + + if (supportsMachineModeSwitch()) { + aNBT.setInteger("machineMode", machineMode); + } + if (supportsSingleRecipeLocking()) { aNBT.setBoolean("mLockedToSingleRecipe", mLockedToSingleRecipe); if (mLockedToSingleRecipe && mSingleRecipeCheck != null) @@ -294,6 +302,9 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity mEfficiency = aNBT.getInteger("mEfficiency"); mPollution = aNBT.getInteger("mPollution"); mRuntime = aNBT.getInteger("mRuntime"); + if (aNBT.hasKey("machineMode")) { + machineMode = aNBT.getInteger("machineMode"); + } if (supportsSingleRecipeLocking()) { mLockedToSingleRecipe = aNBT.getBoolean("mLockedToSingleRecipe"); if (mLockedToSingleRecipe && aNBT.hasKey("mSingleRecipeCheck", Constants.NBT.TAG_COMPOUND)) { @@ -2212,6 +2223,50 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity return new Pos2d(26, 91); } + /** + * Creates the icon list for this machine. Override this and add the overlays to machineModeIcons in order. + */ + public void setMachineModeIcons() { + machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_DEFAULT); + machineModeIcons.add(GT_UITextures.OVERLAY_BUTTON_MACHINEMODE_DEFAULT); + } + + /** + * Override this if you are a multi-machine and want a GUI button. You will also want to override + * setMachineModeIcons(). + * Override nextMachineMode() if you have more than 2 modes. + */ + @Override + public boolean supportsMachineModeSwitch() { + return false; + } + + @Override + public int getMachineMode() { + return machineMode; + } + + @Override + public UITexture getMachineModeIcon(int index) { + return machineModeIcons.get(index); + } + + @Override + public void setMachineMode(int index) { + machineMode = index; + } + + @Override + public int nextMachineMode() { + if (machineMode == 0) return 1; + else return 0; + } + + @Override + public Pos2d getMachineModeSwitchButtonPos() { + return new Pos2d(80, 91); + } + @Override public boolean supportsBatchMode() { return false; @@ -2300,9 +2355,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity drawTexts(screenElements, inventorySlot); builder.widget(screenElements); + setMachineModeIcons(); builder.widget(createPowerSwitchButton(builder)) .widget(createVoidExcessButton(builder)) .widget(createInputSeparationButton(builder)) + .widget(createModeSwitchButton(builder)) .widget(createBatchModeButton(builder)) .widget(createLockToSingleRecipeButton(builder)); } -- cgit