diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2023-07-30 20:26:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-30 14:26:53 +0200 |
commit | f983308b936c54f3331424b0d6d51d8a3b11f415 (patch) | |
tree | eabcbe297913884a7acc2997d7464d5fb355d2f2 /src/main/java/gregtech/api | |
parent | 9812da7aabe91ce96d9ece08f792912aa7d1882c (diff) | |
download | GT5-Unofficial-f983308b936c54f3331424b0d6d51d8a3b11f415.tar.gz GT5-Unofficial-f983308b936c54f3331424b0d6d51d8a3b11f415.tar.bz2 GT5-Unofficial-f983308b936c54f3331424b0d6d51d8a3b11f415.zip |
enable subclass to allow less voiding mode being set (#2191)
* enable subclass to allow less voiding mode being set
* fix bug
* rename
Diffstat (limited to 'src/main/java/gregtech/api')
4 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/enums/VoidingMode.java b/src/main/java/gregtech/api/enums/VoidingMode.java index 47f837daac..8ae9dda57d 100644 --- a/src/main/java/gregtech/api/enums/VoidingMode.java +++ b/src/main/java/gregtech/api/enums/VoidingMode.java @@ -1,5 +1,9 @@ package gregtech.api.enums; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Set; + import javax.annotation.Nonnull; import com.gtnewhorizons.modularui.api.drawable.UITexture; @@ -27,6 +31,18 @@ public enum VoidingMode { */ VOID_ALL(false, false, GT_UITextures.BUTTON_STANDARD_PRESSED, GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS_ALL, "all"); + /** + * Default set of voiding mode you will probably support. + */ + public static final Set<VoidingMode> ALL_OPTIONS = EnumSet.allOf(VoidingMode.class); + /** + * Set of voiding mode you will probably support if your machine has no item output + */ + public static final Set<VoidingMode> FLUID_ONLY_MODES = EnumSet.of(VOID_FLUID, VOID_NONE); + /** + * Set of voiding mode you will probably support if your machine has no fluid output + */ + public static final Set<VoidingMode> ITEM_ONLY_MODES = EnumSet.of(VOID_ITEM, VOID_NONE); public final boolean protectItem; public final boolean protectFluid; public final UITexture buttonTexture; @@ -54,6 +70,24 @@ public enum VoidingMode { return values()[(ordinal() + values().length - 1) % values().length]; } + public VoidingMode nextInCollection(Collection<VoidingMode> allowed) { + if (allowed.isEmpty()) throw new IllegalArgumentException("nothing allowed"); + VoidingMode ret = this; + do { + ret = ret.next(); + } while (!allowed.contains(ret)); + return ret; + } + + public VoidingMode previousInCollection(Collection<VoidingMode> allowed) { + if (allowed.isEmpty()) throw new IllegalArgumentException("nothing allowed"); + VoidingMode ret = this; + do { + ret = ret.previous(); + } while (!allowed.contains(ret)); + return ret; + } + /** * Do not use this for loading mode from TEs, to prevent mode being shifted when new mode is added. */ diff --git a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java index 3d4ed80f67..22694cdafd 100644 --- a/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java +++ b/src/main/java/gregtech/api/interfaces/modularui/ControllerWithOptionalFeatures.java @@ -6,6 +6,7 @@ import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import net.minecraft.util.StatCollector; @@ -80,9 +81,10 @@ public interface ControllerWithOptionalFeatures extends IVoidable, IRecipeLockab default ButtonWidget createVoidExcessButton(IWidgetBuilder<?> builder) { Widget button = new ButtonWidget().setOnClick((clickData, widget) -> { if (supportsVoidProtection()) { + Set<VoidingMode> allowed = getAllowedVoidingModes(); switch (clickData.mouseButton) { - case 0 -> setVoidingMode(getVoidingMode().next()); - case 1 -> setVoidingMode(getVoidingMode().previous()); + case 0 -> setVoidingMode(getVoidingMode().nextInCollection(allowed)); + case 1 -> setVoidingMode(getVoidingMode().previousInCollection(allowed)); } widget.notifyTooltipChange(); } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java index f4467a2e8c..72dda0ddec 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IVoidable.java @@ -1,6 +1,7 @@ package gregtech.api.interfaces.tileentity; import java.util.List; +import java.util.Set; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -18,6 +19,10 @@ public interface IVoidable { */ boolean supportsVoidProtection(); + default Set<VoidingMode> getAllowedVoidingModes() { + return VoidingMode.ALL_OPTIONS; + } + /** * @return if this machine is configured to not void excess item. */ 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 2f84151af9..e5fcc7a0a5 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 @@ -298,6 +298,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity // backward compatibility voidingMode = aNBT.getBoolean(VOID_EXCESS_NBT_KEY) ? VoidingMode.VOID_ALL : VoidingMode.VOID_NONE; } + if (!getAllowedVoidingModes().contains(voidingMode)) voidingMode = getDefaultVoidingMode(); int aOutputItemsLength = aNBT.getInteger("mOutputItemsLength"); if (aOutputItemsLength > 0) { |