|
@@ -5,6 +5,7 @@ import blue.endless.jankson.JsonObject;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
import me.shedaniel.rei.RoughlyEnoughItemsCore;
|
|
|
+import me.shedaniel.rei.api.ConfigManager;
|
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
|
import net.minecraft.client.gui.Screen;
|
|
@@ -14,12 +15,11 @@ import net.minecraft.text.StringTextComponent;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
import java.util.List;
|
|
|
|
|
|
-public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
|
+public class ConfigManagerImpl implements ConfigManager {
|
|
|
|
|
|
private static final Gson GSON = new GsonBuilder().create();
|
|
|
private static final Jankson JANKSON = Jankson.builder().build();
|
|
@@ -27,7 +27,7 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
|
private ConfigObject config;
|
|
|
private boolean craftableOnly;
|
|
|
|
|
|
- public ConfigManager() {
|
|
|
+ public ConfigManagerImpl() {
|
|
|
this.veryOldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json");
|
|
|
this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json");
|
|
|
this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json5");
|
|
@@ -126,45 +126,49 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
|
|
|
|
@Override
|
|
|
public void openConfigScreen(Screen parent) {
|
|
|
+ MinecraftClient.getInstance().openScreen(getConfigScreen(parent));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Screen getConfigScreen(Screen parent) {
|
|
|
if (FabricLoader.getInstance().isModLoaded("cloth-config")) {
|
|
|
try {
|
|
|
- Class.forName("me.shedaniel.rei.utils.ClothScreenRegistry").getDeclaredMethod("openConfigScreen", Screen.class).invoke(null, parent);
|
|
|
- } catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
|
|
|
+ return Screen.class.cast(Class.forName("me.shedaniel.rei.utils.ClothScreenRegistry").getDeclaredMethod("getConfigScreen", Screen.class).invoke(null, parent));
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- } else {
|
|
|
- MinecraftClient.getInstance().openScreen(new Screen(new StringTextComponent("")) {
|
|
|
- @Override
|
|
|
- public void render(int int_1, int int_2, float float_1) {
|
|
|
- renderDirtBackground(0);
|
|
|
- List<String> list = minecraft.textRenderer.wrapStringToWidthAsList(I18n.translate("text.rei.no_config_api"), width - 100);
|
|
|
- int y = (int) (height / 2 - minecraft.textRenderer.fontHeight * 1.3f / 2 * list.size());
|
|
|
- for(int i = 0; i < list.size(); i++) {
|
|
|
- String s = list.get(i);
|
|
|
- drawCenteredString(minecraft.textRenderer, s, width / 2, y, -1);
|
|
|
- y += minecraft.textRenderer.fontHeight;
|
|
|
- }
|
|
|
- super.render(int_1, int_2, float_1);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void init() {
|
|
|
- super.init();
|
|
|
- addButton(new net.minecraft.client.gui.widget.ButtonWidget(width / 2 - 100, height - 26, 200, 20, I18n.translate("gui.done"), buttonWidget -> {
|
|
|
- this.minecraft.openScreen(parent);
|
|
|
- }));
|
|
|
+ }
|
|
|
+ return new Screen(new StringTextComponent("")) {
|
|
|
+ @Override
|
|
|
+ public void render(int int_1, int int_2, float float_1) {
|
|
|
+ renderDirtBackground(0);
|
|
|
+ List<String> list = minecraft.textRenderer.wrapStringToWidthAsList(I18n.translate("text.rei.config_api_failed"), width - 100);
|
|
|
+ int y = (int) (height / 2 - minecraft.textRenderer.fontHeight * 1.3f / 2 * list.size());
|
|
|
+ for(int i = 0; i < list.size(); i++) {
|
|
|
+ String s = list.get(i);
|
|
|
+ drawCenteredString(minecraft.textRenderer, s, width / 2, y, -1);
|
|
|
+ y += minecraft.textRenderer.fontHeight;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean keyPressed(int int_1, int int_2, int int_3) {
|
|
|
- if (int_1 == 256 && this.shouldCloseOnEsc()) {
|
|
|
- this.minecraft.openScreen(parent);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return super.keyPressed(int_1, int_2, int_3);
|
|
|
+ super.render(int_1, int_2, float_1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void init() {
|
|
|
+ super.init();
|
|
|
+ addButton(new net.minecraft.client.gui.widget.ButtonWidget(width / 2 - 100, height - 26, 200, 20, I18n.translate("text.rei.back"), buttonWidget -> {
|
|
|
+ this.minecraft.openScreen(parent);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean keyPressed(int int_1, int int_2, int int_3) {
|
|
|
+ if (int_1 == 256 && this.shouldCloseOnEsc()) {
|
|
|
+ this.minecraft.openScreen(parent);
|
|
|
+ return true;
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ return super.keyPressed(int_1, int_2, int_3);
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
}
|