From f983308b936c54f3331424b0d6d51d8a3b11f415 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 30 Jul 2023 20:26:53 +0800 Subject: enable subclass to allow less voiding mode being set (#2191) * enable subclass to allow less voiding mode being set * fix bug * rename --- src/main/java/gregtech/api/enums/VoidingMode.java | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/main/java/gregtech/api/enums') 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 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 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 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 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 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. */ -- cgit