diff options
| author | miozune <miozune@gmail.com> | 2023-05-28 18:21:42 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-28 11:21:42 +0200 |
| commit | 9af741164c5b59c4d884aba48ebeab7db5442d63 (patch) | |
| tree | 5bbbbb5feb67db85aefd5f21fd885a1a0ab71c78 /src/main | |
| parent | 24ad01683a084bebd26152b803ee19bffe78213c (diff) | |
| download | GT5-Unofficial-9af741164c5b59c4d884aba48ebeab7db5442d63.tar.gz GT5-Unofficial-9af741164c5b59c4d884aba48ebeab7db5442d63.tar.bz2 GT5-Unofficial-9af741164c5b59c4d884aba48ebeab7db5442d63.zip | |
Add new mode for void protection & implement it for more multis (#2024)
* Void protection improvements
* Rename methods: isXXXButtonEnabled -> supportsXXX
* Adjust texture for forbidden
* Add MultiBlockFeatureSupportDumpers
* Fix oversight in PCBFactory
* Revert void protection support for PA
* Rename class: ControllerWithButtons -> ControllerWithOptionalFeatures
Diffstat (limited to 'src/main')
48 files changed, 923 insertions, 503 deletions
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index 3d4180667a..d494c5b64c 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -343,7 +343,7 @@ public class GT_Values { UPGRADE_TANKS_COUNT = "gt.tankcount.upg", // Int UPGRADE_TANKS_PREFIX = "gt.tank.upg", // NBT Tag SEPARATE_INPUTS = "gt.separate.inputs", // Boolean - VOID_EXCESS = "gt.void.excess", // Boolean + VOIDING_MODE = "gt.voiding.mode", // String BATCH_MODE = "gt.batch.mode", // Boolean RECIPE_LOCK = "gt.recipe.lock", // Boolean diff --git a/src/main/java/gregtech/api/enums/VoidingMode.java b/src/main/java/gregtech/api/enums/VoidingMode.java new file mode 100644 index 0000000000..47f837daac --- /dev/null +++ b/src/main/java/gregtech/api/enums/VoidingMode.java @@ -0,0 +1,78 @@ +package gregtech.api.enums; + +import javax.annotation.Nonnull; + +import com.gtnewhorizons.modularui.api.drawable.UITexture; + +import gregtech.api.gui.modularui.GT_UITextures; + +public enum VoidingMode { + + /** + * Voids nothing, protects both item and fluid + */ + VOID_NONE(true, true, GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_NONE, "none"), + /** + * Voids item, protects fluid + */ + VOID_ITEM(false, true, GT_UITextures.BUTTON_STANDARD_PRESSED, GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_ITEM, + "item"), + /** + * Voids fluid, protects item + */ + VOID_FLUID(true, false, GT_UITextures.BUTTON_STANDARD_PRESSED, GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_FLUID, + "fluid"), + /** + * Voids all, protects nothing + */ + VOID_ALL(false, false, GT_UITextures.BUTTON_STANDARD_PRESSED, GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_ALL, "all"); + + public final boolean protectItem; + public final boolean protectFluid; + public final UITexture buttonTexture; + public final UITexture buttonOverlay; + public final String name; + + VoidingMode(boolean protectItem, boolean protectFluid, UITexture buttonTexture, UITexture buttonOverlay, + String name) { + this.protectItem = protectItem; + this.protectFluid = protectFluid; + this.buttonTexture = buttonTexture; + this.buttonOverlay = buttonOverlay; + this.name = name; + } + + public String getTransKey() { + return "GT5U.gui.button.voiding_mode_" + name; + } + + public VoidingMode next() { + return values()[(ordinal() + 1) % values().length]; + } + + public VoidingMode previous() { + return values()[(ordinal() + values().length - 1) % values().length]; + } + + /** + * Do not use this for loading mode from TEs, to prevent mode being shifted when new mode is added. + */ + @Nonnull + public static VoidingMode fromOrdinal(int ordinal) { + if (ordinal >= 0 && ordinal < values().length) { + return values()[ordinal]; + } + return VOID_NONE; + } + + @Nonnull + public static VoidingMode fromName(String name) { + for (VoidingMode mode : values()) { + if (mode.name.equals(name)) { + return mode; + } + } + return VOID_NONE; + } + +} diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java index e8c9f192a6..8dda90a630 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java @@ -220,6 +220,8 @@ public class GT_UITextures { public static final UITexture BUTTON_STANDARD = AdaptableUITexture .of(GregTech.ID, "gui/button/standard", 18, 18, 1); + public static final UITexture BUTTON_STANDARD_PRESSED = AdaptableUITexture + .of(GregTech.ID, "gui/button/standard_pressed", 18, 18, 1); public static final UITexture BUTTON_STANDARD_DISABLED = AdaptableUITexture .of(GregTech.ID, "gui/button/standard_disabled", 18, 18, 1); public static final UITexture BUTTON_STANDARD_TOGGLE = AdaptableUITexture @@ -242,14 +244,14 @@ public class GT_UITextures { .fullImage(GregTech.ID, "gui/overlay_button/power_switch_on"); public static final UITexture OVERLAY_BUTTON_POWER_SWITCH_OFF = UITexture .fullImage(GregTech.ID, "gui/overlay_button/power_switch_off"); - public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ON = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_excess_on"); - public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ON_DISABLED = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_excess_on_disabled"); - public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_OFF = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_excess_off"); - public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_OFF_DISABLED = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_excess_off_disabled"); + public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_NONE = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/void_excess_none"); + public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ITEM = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/void_excess_item"); + public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_FLUID = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/void_excess_fluid"); + public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ALL = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/void_excess_all"); public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_ON = UITexture .fullImage(GregTech.ID, "gui/overlay_button/input_separation_on"); public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_ON_DISABLED = UITexture @@ -274,6 +276,8 @@ public class GT_UITextures { .fullImage(GregTech.ID, "gui/overlay_button/batch_mode_off"); public static final UITexture OVERLAY_BUTTON_BATCH_MODE_OFF_DISABLED = UITexture .fullImage(GregTech.ID, "gui/overlay_button/batch_mode_off_disabled"); + public static final UITexture OVERLAY_BUTTON_FORBIDDEN = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/forbidden"); public static final UITexture OVERLAY_BUTTON_DOWN_TIERING_ON = UITexture .fullImage(GregTech.ID, "gui/overlay_button/down_tiering_on"); public static final UITexture OVERLAY_BUTTON_DOWN_TIERING_OFF = UITexture @@ -342,10 +346,10 @@ public class GT_UITextures { public static final UITexture OVERLAY_BUTTON_LOCK = UITexture.fullImage(GregTech.ID, "gui/overlay_button/lock"); public static final UITexture OVERLAY_BUTTON_INPUT_FROM_OUTPUT_SIDE = UITexture .fullImage(GregTech.ID, "gui/overlay_button/input_from_output_side"); - public static final UITexture OVERLAY_BUTTON_VOID_EXCESS = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_excess"); - public static final UITexture OVERLAY_BUTTON_VOID_ALL = UITexture - .fullImage(GregTech.ID, "gui/overlay_button/void_all"); + public static final UITexture OVERLAY_BUTTON_TANK_VOID_EXCESS = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/tank_void_excess"); + public static final UITexture OVERLAY_BUTTON_TANK_VOID_ALL = UITexture + .fullImage(GregTech.ID, "gui/overlay_button/tank_void_all"); public static final UITexture OVERLAY_BUTTON_NEI = UITexture.fullImage(GregTech.ID, "gui/overlay_button/nei"); /** diff --git a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java new file mode 100644 index 0000000000..cf740a6bc6 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java @@ -0,0 +1,304 @@ +package gregtech.api.interfaces.modularui; + +import static gregtech.api.metatileentity.BaseTileEntity.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.util.StatCollector; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.VoidingMode; +import gregtech.api.gui.modularui.GT_UITextures; + +/** + * Machines implementing this interface can have logic and GUI buttons + * to configure various behaviors regarding multiblock. + * <ul> + * <li>Power switch</li> + * <li>Void protection</li> + * <li>Separated input buses</li> + * <li>Batch mode</li> + * <li>Recipe locking</li> + * </ul> + */ +public interface ControllerWithOptionalFeatures { + + boolean isAllowedToWork(); + + void disableWorking(); + + void enableWorking(); + + Pos2d getPowerSwitchButtonPos(); + + default ButtonWidget createPowerSwitchButton(IWidgetBuilder<?> builder) { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (isAllowedToWork()) { + disableWorking(); + } else { + enableWorking(); + } + }) + .setPlayClickSoundResource( + () -> isAllowedToWork() ? SoundResource.GUI_BUTTON_UP.resourceLocation + : SoundResource.GUI_BUTTON_DOWN.resourceLocation) + .setBackground(() -> { + if (isAllowedToWork()) { + return new IDrawable[] { GT_UITextures.BUTTON_STANDARD_PRESSED, + GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_ON }; + } else { + return new IDrawable[] { GT_UITextures.BUTTON_STANDARD, + GT_UITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF }; + } + }) + .attachSyncer(new FakeSyncWidget.BooleanSyncer(this::isAllowedToWork, val -> { + if (val) enableWorking(); + else disableWorking(); + }), builder) + .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.power_switch")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(getPowerSwitchButtonPos()) + .setSize(16, 16); + return (ButtonWidget) button; + } + + /** + * @return if this machine can prevent excess item and fluid from voiding. + */ + boolean supportsVoidProtection(); + + /** + * @return if this machine is configured to not void excess item. + */ + default boolean protectsExcessItem() { + return supportsVoidProtection() && getVoidingMode().protectItem; + } + + /** + * @return if this machine is configured to not void excess fluid. + */ + default boolean protectsExcessFluid() { + return supportsVoidProtection() && getVoidingMode().protectFluid; + } + + VoidingMode getVoidingMode(); + + void setVoidingMode(VoidingMode mode); + + Pos2d getVoidingModeButtonPos(); + + default ButtonWidget createVoidExcessButton(IWidgetBuilder<?> builder) { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (supportsVoidProtection()) { + switch (clickData.mouseButton) { + case 0 -> setVoidingMode(getVoidingMode().next()); + case 1 -> setVoidingMode(getVoidingMode().previous()); + } + widget.notifyTooltipChange(); + } + }) + .setPlayClickSound(supportsVoidProtection()) + .setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + ret.add(getVoidingMode().buttonTexture); + ret.add(getVoidingMode().buttonOverlay); + if (!supportsVoidProtection()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_FORBIDDEN); + } + return ret.toArray(new IDrawable[0]); + }) + .attachSyncer( + new FakeSyncWidget.IntegerSyncer( + () -> getVoidingMode().ordinal(), + val -> setVoidingMode(VoidingMode.fromOrdinal(val))), + builder) + .dynamicTooltip( + () -> Arrays.asList( + StatCollector.translateToLocal("GT5U.gui.button.voiding_mode"), + StatCollector.translateToLocal(getVoidingMode().getTransKey()))) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(getVoidingModeButtonPos()) + .setSize(16, 16); + if (!supportsVoidProtection()) { + button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); + } + return (ButtonWidget) button; + } + + /** + * @return if the multi supports input separation. + */ + boolean supportsInputSeparation(); + + /** + * @return true if input separation is enabled, else false. This is getter is used for displaying the icon in the + * GUI + */ + boolean isInputSeparationEnabled(); + + void setInputSeparation(boolean enabled); + + Pos2d getInputSeparationButtonPos(); + + default ButtonWidget createInputSeparationButton(IWidgetBuilder<?> builder) { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (supportsInputSeparation()) { + setInputSeparation(!isInputSeparationEnabled()); + } + }) + .setPlayClickSound(supportsInputSeparation()) + .setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + if (isInputSeparationEnabled()) { + ret.add(GT_UITextures.BUTTON_STANDARD_PRESSED); + if (supportsInputSeparation()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON_DISABLED); + } + } else { + ret.add(GT_UITextures.BUTTON_STANDARD); + if (supportsInputSeparation()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF_DISABLED); + } + } + if (!supportsInputSeparation()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_FORBIDDEN); + } + return ret.toArray(new IDrawable[0]); + }) + .attachSyncer( + new FakeSyncWidget.BooleanSyncer(this::isInputSeparationEnabled, this::setInputSeparation), + builder) + .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.input_separation")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(getInputSeparationButtonPos()) + .setSize(16, 16); + if (!supportsInputSeparation()) { + button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); + } + return (ButtonWidget) button; + } + + /** + * @return if the multi supports batch mode. + */ + boolean supportsBatchMode(); + + /** + * @return true if batch mode is enabled, else false. This is getter is used for displaying the icon in the GUI + */ + boolean isBatchModeEnabled(); + + void setBatchMode(boolean enabled); + + Pos2d getBatchModeButtonPos(); + + default ButtonWidget createBatchModeButton(IWidgetBuilder<?> builder) { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (supportsBatchMode()) { + setBatchMode(!isBatchModeEnabled()); + } + }) + .setPlayClickSound(supportsBatchMode()) + .setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + if (isBatchModeEnabled()) { + ret.add(GT_UITextures.BUTTON_STANDARD_PRESSED); + if (supportsBatchMode()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_ON); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_ON_DISABLED); + } + } else { + ret.add(GT_UITextures.BUTTON_STANDARD); + if (supportsBatchMode()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_OFF); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_BATCH_MODE_OFF_DISABLED); + } + } + if (!supportsBatchMode()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_FORBIDDEN); + } + return ret.toArray(new IDrawable[0]); + }) + .attachSyncer(new FakeSyncWidget.BooleanSyncer(this::isBatchModeEnabled, this::setBatchMode), builder) + .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.batch_mode")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(getBatchModeButtonPos()) + .setSize(16, 16); + if (!supportsBatchMode()) { + button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); + } + return (ButtonWidget) button; + } + + /** + * Override this if you are a multi-block that has added support for single recipe locking. + */ + boolean supportsSingleRecipeLocking(); + + /** + * @return true if recipe locking is enabled, else false. This is getter is used for displaying the icon in the GUI + */ + boolean isRecipeLockingEnabled(); + + void setRecipeLocking(boolean enabled); + + Pos2d getRecipeLockingButtonPos(); + + default ButtonWidget createLockToSingleRecipeButton(IWidgetBuilder<?> builder) { + Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { + if (supportsSingleRecipeLocking()) { + setRecipeLocking(!isRecipeLockingEnabled()); + } + }) + .setPlayClickSound(supportsSingleRecipeLocking()) + .setBackground(() -> { + List<UITexture> ret = new ArrayList<>(); + if (isRecipeLockingEnabled()) { + ret.add(GT_UITextures.BUTTON_STANDARD_PRESSED); + if (supportsSingleRecipeLocking()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_LOCKED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_LOCKED_DISABLED); + } + } else { + ret.add(GT_UITextures.BUTTON_STANDARD); + if (supportsSingleRecipeLocking()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED); + } else { + ret.add(GT_UITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED_DISABLED); + } + } + if (!supportsSingleRecipeLocking()) { + ret.add(GT_UITextures.OVERLAY_BUTTON_FORBIDDEN); + } + return ret.toArray(new IDrawable[0]); + }) + .attachSyncer( + new FakeSyncWidget.BooleanSyncer(this::isRecipeLockingEnabled, this::setRecipeLocking), + builder) + .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.lock_recipe")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(getRecipeLockingButtonPos()) + .setSize(16, 16); + if (!supportsSingleRecipeLocking()) { + button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); + } + return (ButtonWidget) button; + } +} diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java index d38a3d98fd..4c49a88819 100644 --- a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java @@ -23,7 +23,8 @@ public class ComplexParallelProcessingLogic { protected final long[] availableEut; protected final long[] eut; protected final long[] durations; - protected boolean[] isVoidProtected; + protected boolean[] isItemVoidProtected; + protected boolean[] isFluidVoidProtected; public ComplexParallelProcessingLogic(int maxComplexParallels) { this(null, maxComplexParallels); @@ -39,7 +40,8 @@ public class ComplexParallelProcessingLogic { eut = new long[maxComplexParallels]; availableEut = new long[maxComplexParallels]; durations = new long[maxComplexParallels]; - isVoidProtected = new boolean[maxComplexParallels]; + isItemVoidProtected = new boolean[maxComplexParallels]; + isFluidVoidProtected = new boolean[maxComplexParallels]; } public ComplexParallelProcessingLogic setRecipeMap(GT_Recipe.GT_Recipe_Map recipeMap) { @@ -73,9 +75,10 @@ public class ComplexParallelProcessingLogic { return this; } - public ComplexParallelProcessingLogic setVoidProtection(int index, boolean shouldVoidProtect) { + public ComplexParallelProcessingLogic setVoidProtection(int index, boolean protectItem, boolean protectFluid) { if (index >= 0 && index < maxComplexParallels) { - isVoidProtected[index] = shouldVoidProtect; + isItemVoidProtected[index] = protectItem; + isFluidVoidProtected[in |
