ClothScreenRegistry.java 7.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package me.shedaniel.rei.utils;
  2. import me.shedaniel.cloth.api.ConfigScreenBuilder;
  3. import me.shedaniel.cloth.gui.ClothConfigScreen;
  4. import me.shedaniel.cloth.gui.entries.BooleanListEntry;
  5. import me.shedaniel.cloth.gui.entries.EnumListEntry;
  6. import me.shedaniel.cloth.gui.entries.IntegerSliderEntry;
  7. import me.shedaniel.cloth.gui.entries.StringListEntry;
  8. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  9. import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
  10. import me.shedaniel.rei.gui.credits.CreditsScreen;
  11. import net.minecraft.client.MinecraftClient;
  12. import net.minecraft.client.gui.Screen;
  13. import net.minecraft.client.gui.widget.ButtonWidget;
  14. import net.minecraft.client.resource.language.I18n;
  15. import net.minecraft.util.Pair;
  16. import java.io.IOException;
  17. import java.util.List;
  18. import java.util.Map;
  19. public class ClothScreenRegistry {
  20. public static void openConfigScreen(Screen parent) {
  21. ConfigScreenBuilder builder = new ClothConfigScreen.Builder(parent, "text.rei.config.title", savedConfig -> {
  22. try {
  23. RoughlyEnoughItemsCore.getConfigManager().saveConfig();
  24. } catch (IOException e) {
  25. e.printStackTrace();
  26. }
  27. }) {
  28. @Override
  29. public ClothConfigScreen build() {
  30. return new ClothConfigScreen(this.getParentScreen(), this.getTitle(), this.getDataMap(), this.doesConfirmSave(), this.shouldProcessErrors()) {
  31. public void onSave(Map<String, List<Pair<String, Object>>> o) {
  32. if (getOnSave() != null) {
  33. getOnSave().accept(new SelfSavedConfig(o));
  34. }
  35. }
  36. @Override
  37. protected void init() {
  38. super.init();
  39. ButtonWidget w;
  40. buttons.add(0, w = new ButtonWidget(6, 6, 60, 20, I18n.translate("text.rei.credits"), widget -> MinecraftClient.getInstance().openScreen(new CreditsScreen(MinecraftClient.getInstance().currentScreen))));
  41. children.add(0, w);
  42. }
  43. };
  44. }
  45. };
  46. builder.addCategory("text.rei.config.general").addOption(new BooleanListEntry("text.rei.config.cheating", RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = bool));
  47. ConfigScreenBuilder.CategoryBuilder appearance = builder.addCategory("text.rei.config.appearance");
  48. appearance.addOption(new BooleanListEntry("text.rei.config.side_search_box", RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField = bool));
  49. appearance.addOption(new EnumListEntry<ItemListOrderingConfig>("text.rei.config.list_ordering", ItemListOrderingConfig.class, ItemListOrderingConfig.from(RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering, RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending), "text.cloth-config.reset_value", () -> ItemListOrderingConfig.REGISTRY_ASCENDING, config -> {
  50. RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering = config.getOrdering();
  51. RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending = config.isAscending();
  52. }));
  53. appearance.addOption(new BooleanListEntry("text.rei.config.item_list_position", RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel = bool) {
  54. @Override
  55. public String getYesNoText(boolean bool) {
  56. return I18n.translate(bool ? "text.rei.config.item_list_position.left" : "text.rei.config.item_list_position.right");
  57. }
  58. });
  59. appearance.addOption(new IntegerSliderEntry("text.rei.config.max_recipes_per_page", 2, 99, RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage, "text.cloth-config.reset_value", () -> 3, i -> RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage = i));
  60. ConfigScreenBuilder.CategoryBuilder modules = builder.addCategory("text.rei.config.modules");
  61. modules.addOption(new BooleanListEntry("text.rei.config.enable_craftable_only", RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton, "text.cloth-config.reset_value", () -> true, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton = bool));
  62. modules.addOption(new BooleanListEntry("text.rei.config.enable_util_buttons", RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons = bool));
  63. modules.addOption(new BooleanListEntry("text.rei.config.disable_recipe_book", RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook = bool));
  64. ConfigScreenBuilder.CategoryBuilder advanced = builder.addCategory("text.rei.config.advanced");
  65. advanced.addOption(new StringListEntry("text.rei.give_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand, "text.cloth-config.reset_value", () -> "/give {player_name} {item_identifier}{nbt} {count}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand = s));
  66. advanced.addOption(new StringListEntry("text.rei.gamemode_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand, "text.cloth-config.reset_value", () -> "/gamemode {gamemode}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand = s));
  67. advanced.addOption(new StringListEntry("text.rei.weather_command", RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand, "text.cloth-config.reset_value", () -> "/weather {weather}", s -> RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand = s));
  68. advanced.addOption(new BooleanListEntry("text.rei.config.prefer_visible_recipes", RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes = bool));
  69. advanced.addOption(new BooleanListEntry("text.rei.config.enable_legacy_speedcraft_support", RoughlyEnoughItemsCore.getConfigManager().getConfig().enableLegacySpeedCraftSupport, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().enableLegacySpeedCraftSupport = bool));
  70. ConfigScreenBuilder.CategoryBuilder aprilFools = builder.addCategory("text.rei.config.april_fools");
  71. aprilFools.addOption(new BooleanListEntry("text.rei.config.april_fools.2019", RoughlyEnoughItemsCore.getConfigManager().getConfig().aprilFoolsFish2019, "text.cloth-config.reset_value", () -> false, bool -> RoughlyEnoughItemsCore.getConfigManager().getConfig().aprilFoolsFish2019 = bool));
  72. MinecraftClient.getInstance().openScreen(builder.build());
  73. }
  74. private static class SelfSavedConfig extends ClothConfigScreen.Builder.SavedConfig {
  75. protected SelfSavedConfig(Map<String, List<Pair<String, Object>>> map) {
  76. super(map);
  77. }
  78. }
  79. }