aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-01-30 18:23:55 +0800
committershedaniel <daniel@shedaniel.me>2020-01-30 18:23:55 +0800
commit260375f7d89fa419dd4856f322690adb883f3371 (patch)
tree3dedbe33058f5be36d71ac9b3c04ef1f97b0f663 /src/main
parent822790361c5cea055d9a7706094e24032c1cdd95 (diff)
downloadRoughlyEnoughItems-260375f7d89fa419dd4856f322690adb883f3371.tar.gz
RoughlyEnoughItems-260375f7d89fa419dd4856f322690adb883f3371.tar.bz2
RoughlyEnoughItems-260375f7d89fa419dd4856f322690adb883f3371.zip
3.3.17
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java39
-rw-r--r--src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java8
2 files changed, 22 insertions, 25 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
index 07049ac62..2d74500f3 100644
--- a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java
@@ -49,7 +49,6 @@ import net.minecraft.text.LiteralText;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.ApiStatus;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -61,7 +60,8 @@ import static me.sargunvohra.mcmods.autoconfig1u.util.Utils.setUnsafely;
public class ConfigManagerImpl implements ConfigManager {
private boolean craftableOnly;
- private List<EntryStack> favorites = new ArrayList<>();
+ // private List<EntryStack> favorites = new ArrayList<>();
+ private Gson gson = new GsonBuilder().create();
public ConfigManagerImpl() {
this.craftableOnly = false;
@@ -76,11 +76,14 @@ public class ConfigManagerImpl implements ConfigManager {
object.put("keyCode", new JsonPrimitive(keyCode.getKeyCode().getName()));
object.put("modifier", new JsonPrimitive(keyCode.getModifier().getValue()));
return object;
+ }).registerSerializer(EntryStack.class, (stack, marshaller) -> {
+ return new JsonPrimitive(gson.toJson(stack.toJson()));
+ }).registerPrimitiveTypeAdapter(EntryStack.class, it -> {
+ return it instanceof String ? EntryStack.readFromJson(gson.fromJson((String) it, JsonElement.class)) : null;
}).build()));
GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ConfigObjectImpl.class);
//noinspection rawtypes
guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> Collections.singletonList(ConfigEntryBuilder.create().startEnumSelector(i13n, (Class) field.getType(), getUnsafely(field, config, null)).setDefaultValue(() -> getUnsafely(field, defaults)).setSaveConsumer(newValue -> setUnsafely(field, config, newValue)).build()), field -> field.getType().isEnum(), ConfigObject.UseEnumSelectorInstead.class);
- loadFavoredEntries();
// guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> {
// @SuppressWarnings("rawtypes") List<AbstractConfigListEntry> entries = new ArrayList<>();
// for (FabricKeyBinding binding : ClientHelper.getInstance().getREIKeyBindings()) {
@@ -164,36 +167,24 @@ public class ConfigManagerImpl implements ConfigManager {
}
});
}, (field) -> field.getType() == RecipeScreenType.class, ConfigObject.UseSpecialRecipeTypeScreen.class);
- loadFavoredEntries();
+ saveConfig();
RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded.");
}
@Override
public List<EntryStack> getFavorites() {
- return favorites;
- }
-
- public void loadFavoredEntries() {
- favorites.clear();
- Gson gson = new GsonBuilder().create();
- for (String entry : ((ConfigObjectImpl) getConfig()).general.favorites) {
- EntryStack stack = EntryStack.readFromJson(gson.fromJson(entry, JsonElement.class));
- if (!stack.isEmpty())
- favorites.add(stack);
- }
- saveConfig();
+ return ((ConfigObjectImpl) getConfig()).general.favorites;
}
@Override
public void saveConfig() {
- Gson gson = new GsonBuilder().create();
- ConfigObjectImpl object = (ConfigObjectImpl) getConfig();
- object.general.favorites.clear();
- for (EntryStack stack : favorites) {
- JsonElement element = stack.toJson();
- if (element != null)
- object.general.favorites.add(gson.toJson(element));
- }
+ // ConfigObjectImpl object = (ConfigObjectImpl) getConfig();
+ // object.general.favorites.clear();
+ // for (EntryStack stack : favorites) {
+ // JsonElement element = stack.toJson();
+ // if (element != null)
+ // object.general.favorites.add(gson.toJson(element));
+ // }
((me.sargunvohra.mcmods.autoconfig1u.ConfigManager<ConfigObjectImpl>) AutoConfig.getConfigHolder(ConfigObjectImpl.class)).save();
}
diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
index f520184f0..efc483162 100644
--- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
+++ b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java
@@ -12,6 +12,7 @@ import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
import me.shedaniel.clothconfig2.api.Modifier;
import me.shedaniel.clothconfig2.api.ModifierKeyCode;
import me.shedaniel.rei.api.ConfigObject;
+import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.gui.config.ItemListOrdering;
import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
import me.shedaniel.rei.gui.config.RecipeScreenType;
@@ -31,6 +32,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
@ConfigEntry.Category("modules") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Modules modules = new Modules();
@ConfigEntry.Category("technical") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Technical technical = new Technical();
@ConfigEntry.Category("performance") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Performance performance = new Performance();
+ // @ConfigEntry.Category("filtering") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName private Filtering filtering = new Filtering();
@Override
public boolean isLighterButtonHover() {
@@ -279,7 +281,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
}
public static class General {
- @ConfigEntry.Gui.Excluded public List<String> favorites = new ArrayList<>();
+ @ConfigEntry.Gui.Excluded public List<EntryStack> favorites = new ArrayList<>();
@Comment("Declares whether cheating mode is on.") private boolean cheating = false;
@Comment("Declares whether REI is visible.") @ConfigEntry.Gui.Excluded private boolean overlayVisible = true;
private boolean favoritesEnabled = true;
@@ -339,4 +341,8 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
@Comment("Whether REI should render entry's enchantment glint") private boolean renderEntryEnchantmentGlint = true;
private boolean newFastEntryRendering = true;
}
+
+ public static class Filtering {
+ private List<EntryStack> filteredStacks = new ArrayList<>();
+ }
}