aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-02-15 15:32:09 +0800
committershedaniel <daniel@shedaniel.me>2022-02-18 11:46:22 +0800
commitb7ca12d5e3073b4d0793ef947ce29c6e22c9c9d8 (patch)
treee16f31e048fc5900f6a4a7db12f98b1553eff471 /runtime/src/main/java
parent944734e3a5eabfee5efec37e69818a183c35d962 (diff)
downloadRoughlyEnoughItems-b7ca12d5e3073b4d0793ef947ce29c6e22c9c9d8.tar.gz
RoughlyEnoughItems-b7ca12d5e3073b4d0793ef947ce29c6e22c9c9d8.tar.bz2
RoughlyEnoughItems-b7ca12d5e3073b4d0793ef947ce29c6e22c9c9d8.zip
Close #768
Diffstat (limited to 'runtime/src/main/java')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java16
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java17
2 files changed, 29 insertions, 4 deletions
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 848c22fd7..0ba8dd440 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;
@@ -134,6 +135,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 99c79f906..96b9b2258 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
@@ -40,7 +40,9 @@ import me.shedaniel.rei.api.common.util.CollectionUtils;
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;
@@ -76,12 +78,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
@@ -512,7 +520,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();
@@ -572,7 +580,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
@Comment("Declares whether REI should remove the recipe book.") private boolean disableRecipeBook = 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 {