diff options
5 files changed, 57 insertions, 4 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index e60e5da7b..dfd8f08f6 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -50,6 +50,9 @@ public interface ConfigObject { void setCheating(boolean cheating); + @ApiStatus.Experimental + CheatingMode getCheatingMode(); + EntryPanelOrdering getItemListOrdering(); boolean isItemListAscending(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java new file mode 100644 index 000000000..aed84dff1 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/config/CheatingMode.java @@ -0,0 +1,24 @@ +package me.shedaniel.rei.api.client.gui.config; + +import net.minecraft.client.resources.language.I18n; + +public enum CheatingMode { + OFF, + ON, + WHEN_CREATIVE, + ; + + @Override + public String toString() { + switch (this) { + case ON: + return I18n.get("text.cloth-config.boolean.value.true"); + case OFF: + return I18n.get("text.cloth-config.boolean.value.false"); + case WHEN_CREATIVE: + return I18n.get("config.roughlyenoughitems.cheating.when_creative"); + default: + throw new IllegalStateException("Unknown CheatingMode: " + this); + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 9357313c5..6f9c5a085 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -51,6 +51,7 @@ import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.gui.config.CheatingMode; import me.shedaniel.rei.api.client.gui.config.DisplayScreenType; import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; @@ -135,6 +136,21 @@ public class ConfigManagerImpl implements ConfigManager { } private static Jankson buildJankson(Jankson.Builder builder) { + // CheatingMode + builder.registerSerializer(CheatingMode.class, (value, marshaller) -> { + if (value == CheatingMode.WHEN_CREATIVE) { + return new JsonPrimitive("WHEN_CREATIVE"); + } else { + return new JsonPrimitive(value == CheatingMode.ON); + } + }); + builder.registerDeserializer(Boolean.class, CheatingMode.class, (value, unmarshaller) -> { + return value ? CheatingMode.ON : CheatingMode.OFF; + }); + builder.registerDeserializer(String.class, CheatingMode.class, (value, unmarshaller) -> { + return CheatingMode.valueOf(value.toUpperCase(Locale.ROOT)); + }); + // InputConstants.Key builder.registerSerializer(InputConstants.Key.class, (value, marshaller) -> { return new JsonPrimitive(value.getName()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 01c92b70d..76c7e269c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -38,7 +38,9 @@ import me.shedaniel.rei.api.client.gui.config.*; import me.shedaniel.rei.impl.client.entry.filtering.FilteringRule; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; import net.minecraft.util.Mth; +import net.minecraft.world.level.GameType; import org.jetbrains.annotations.ApiStatus; import java.lang.annotation.ElementType; @@ -73,12 +75,18 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Override public boolean isCheating() { - return basics.cheating; + return basics.cheating == CheatingMode.ON || (basics.cheating == CheatingMode.WHEN_CREATIVE && Minecraft.getInstance().gameMode != null + && Minecraft.getInstance().gameMode.getPlayerMode() == GameType.CREATIVE); } @Override public void setCheating(boolean cheating) { - basics.cheating = cheating; + basics.cheating = cheating ? CheatingMode.ON : CheatingMode.OFF; + } + + @Override + public CheatingMode getCheatingMode() { + return basics.cheating; } @Override @@ -513,7 +521,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { public static class Basics { @ConfigEntry.Gui.Excluded public List<FavoriteEntry> favorites = new ArrayList<>(); - @Comment("Declares whether cheating mode is on.") private boolean cheating = false; + @Comment("Declares whether cheating mode is on.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private CheatingMode cheating = CheatingMode.OFF; private boolean favoritesEnabled = true; @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) private KeyBindings keyBindings = new KeyBindings(); @@ -574,7 +582,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares whether mob effects should be on the left side instead of the right side.") private boolean leftSideMobEffects = false; @Comment("Declares whether subsets is enabled.") private boolean isSubsetsEnabled = false; private boolean allowInventoryHighlighting = true; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; + @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + private ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; } public static class Advanced { diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index 99f039e67..866d202bd 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -158,6 +158,7 @@ "config.roughlyenoughitems.functionality": "Functionality", "config.roughlyenoughitems.advanced": "Advanced", "config.roughlyenoughitems.cheating": "Cheating:", + "config.roughlyenoughitems.cheating.when_creative": "During Creative Mode", "config.roughlyenoughitems.favoritesEnabled": "Favorites Enabled:", "config.roughlyenoughitems.keyBindings": "Keybindings", "config.roughlyenoughitems.keyBindings.recipeKeybind": "Show Recipe:", |
