aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/utils/ClothScreenRegistry.java
blob: dfda85b2b2aa1af99dfad56097e9577c9b0f798b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Roughly Enough Items by Danielshe.
 * Licensed under the MIT License.
 */

package me.shedaniel.rei.utils;

import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import me.shedaniel.fiber2cloth.api.Fiber2Cloth;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.api.ConfigManager;
import me.shedaniel.rei.gui.config.ItemCheatingMode;
import me.shedaniel.rei.gui.config.ItemListOrderingConfig;
import me.shedaniel.rei.gui.config.RecipeScreenType;
import me.zeroeightsix.fiber.exception.FiberException;
import me.zeroeightsix.fiber.tree.ConfigValue;
import net.minecraft.client.gui.screen.Screen;

import java.io.IOException;
import java.util.List;

import static me.shedaniel.fiber2cloth.impl.Fiber2ClothImpl.error;
import static me.shedaniel.fiber2cloth.impl.Fiber2ClothImpl.splitLine;

public class ClothScreenRegistry {
    
    public static Screen getConfigScreen(Screen parent) {
        final ConfigManager configManager = RoughlyEnoughItemsCore.getConfigManager();
        ConfigEntryBuilder configEntryBuilder = ConfigEntryBuilder.create();
        return Fiber2Cloth.create(parent, "roughlyenoughitems", configManager.getConfig().getConfigNode(), "config.roughlyenoughitems.title").setSaveRunnable(() -> {
            try {
                configManager.saveConfig();
            } catch (IOException | FiberException e) {
                e.printStackTrace();
            }
        }).registerConfigEntryFunction(ItemListOrderingConfig.class, o -> {
            ConfigValue<ItemListOrderingConfig> configValue = (ConfigValue<ItemListOrderingConfig>) o;
            return configEntryBuilder.startEnumSelector("config.roughlyenoughitems." + configValue.getName(), ItemListOrderingConfig.class, configValue.getValue())
                    .setDefaultValue(configValue.getDefaultValue())
                    .setTooltip(splitLine(configValue.getComment()))
                    .setSaveConsumer(var -> configValue.setValue((ItemListOrderingConfig) var))
                    .setErrorSupplier(var -> error((List) configValue.getConstraints(), var, ItemListOrderingConfig.class))
                    .build();
        }).registerConfigEntryFunction(RecipeScreenType.class, o -> {
            ConfigValue<RecipeScreenType> configValue = (ConfigValue<RecipeScreenType>) o;
            return configEntryBuilder.startEnumSelector("config.roughlyenoughitems." + configValue.getName(), RecipeScreenType.class, configValue.getValue())
                    .setDefaultValue(configValue.getDefaultValue())
                    .setTooltip(splitLine(configValue.getComment()))
                    .setSaveConsumer(var -> configValue.setValue((RecipeScreenType) var))
                    .setErrorSupplier(var -> error((List) configValue.getConstraints(), var, RecipeScreenType.class))
                    .build();
        }).registerConfigEntryFunction(ItemCheatingMode.class, o -> {
            ConfigValue<ItemCheatingMode> configValue = (ConfigValue<ItemCheatingMode>) o;
            return configEntryBuilder.startEnumSelector("config.roughlyenoughitems." + configValue.getName(), ItemCheatingMode.class, configValue.getValue())
                    .setDefaultValue(configValue.getDefaultValue())
                    .setTooltip(splitLine(configValue.getComment()))
                    .setSaveConsumer(var -> configValue.setValue((ItemCheatingMode) var))
                    .setErrorSupplier(var -> error((List) configValue.getConstraints(), var, ItemCheatingMode.class))
                    .build();
        }).build().getScreen();
    }
    
}