Search in sources :

Example 6 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Shrines by Silverminer007.

the class GeneralSettingsScreen method init.

@Override
public void init(Minecraft mc, int width, int height) {
    super.init(mc, width, height);
    int titleHeight = mc.font.wordWrapHeight(title.getString(), width - 2 * PADDING);
    int paddedTitleHeight = titleHeight + PADDING * 2;
    addButton(width - 120 - 2 * PADDING, 0, 60, paddedTitleHeight, new StringTextComponent("Back"), button -> mc.setScreen(parent));
    addButton(width - 60 - PADDING, 0, 60, paddedTitleHeight, new StringTextComponent("Save"), button -> {
        this.optionList.commitChanges();
        for (ForgeConfigSpec spec : configSpecs) spec.save();
        mc.setScreen(parent);
    });
    int optionListHeaderHeight = titleHeight + 2 * PADDING;
    this.optionList = new ModOptionList(configSpecs, minecraft, width, height, optionListHeaderHeight, height - optionListHeaderHeight, 26);
    this.children.add(optionList);
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 7 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.

the class CConfigureConfigPacket method handle.

@Override
public void handle(Supplier<NetworkEvent.Context> context) {
    context.get().enqueueWork(() -> {
        try {
            ServerPlayer sender = context.get().getSender();
            if (sender == null || !sender.hasPermissions(2))
                return;
            ForgeConfigSpec spec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.SERVER, modID);
            if (spec == null)
                return;
            ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(path);
            ForgeConfigSpec.ConfigValue<T> configValue = spec.getValues().get(path);
            T v = (T) deserialize(configValue.get(), value);
            if (!valueSpec.test(v))
                return;
            configValue.set(v);
        } catch (Exception e) {
            Create.LOGGER.warn("Unable to handle ConfigureConfig Packet. ", e);
        }
    });
    context.get().setPacketHandled(true);
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 8 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.

the class ConfigHelper method setConfigValue.

// Directly set a value
public static <T> void setConfigValue(ConfigPath path, String value) throws InvalidValueException {
    ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID());
    if (spec == null)
        return;
    List<String> pathList = Arrays.asList(path.getPath());
    ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(pathList);
    ForgeConfigSpec.ConfigValue<T> configValue = spec.getValues().get(pathList);
    T v = (T) CConfigureConfigPacket.deserialize(configValue.get(), value);
    if (!valueSpec.test(v))
        throw new InvalidValueException();
    configValue.set(v);
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec)

Example 9 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.

the class SubMenuConfigScreen method find.

public static SubMenuConfigScreen find(ConfigHelper.ConfigPath path) {
    // TODO 1.17: can be null
    ForgeConfigSpec spec = ConfigHelper.findForgeConfigSpecFor(path.getType(), path.getModID());
    UnmodifiableConfig values = spec.getValues();
    BaseConfigScreen base = new BaseConfigScreen(null, path.getModID());
    SubMenuConfigScreen screen = new SubMenuConfigScreen(base, "root", path.getType(), spec, values);
    List<String> remainingPath = Lists.newArrayList(path.getPath());
    path: while (!remainingPath.isEmpty()) {
        String next = remainingPath.remove(0);
        for (Map.Entry<String, Object> entry : values.valueMap().entrySet()) {
            String key = entry.getKey();
            Object obj = entry.getValue();
            if (!key.equalsIgnoreCase(next))
                continue;
            if (!(obj instanceof AbstractConfig)) {
                // highlight entry
                screen.highlights.add(path.getPath()[path.getPath().length - 1]);
                continue;
            }
            values = (UnmodifiableConfig) obj;
            screen = new SubMenuConfigScreen(screen, toHumanReadable(key), path.getType(), spec, values);
            continue path;
        }
        break;
    }
    ConfigScreen.modID = path.getModID();
    return screen;
}
Also used : AbstractConfig(com.electronwill.nightconfig.core.AbstractConfig) ValueEntry(com.simibubi.create.foundation.config.ui.entries.ValueEntry) SubMenuEntry(com.simibubi.create.foundation.config.ui.entries.SubMenuEntry) EnumEntry(com.simibubi.create.foundation.config.ui.entries.EnumEntry) LabeledEntry(com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry) BooleanEntry(com.simibubi.create.foundation.config.ui.entries.BooleanEntry) NumberEntry(com.simibubi.create.foundation.config.ui.entries.NumberEntry) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) UnmodifiableConfig(com.electronwill.nightconfig.core.UnmodifiableConfig)

Example 10 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project artifacts by ochotonida.

the class ModConfig method registerClient.

public static void registerClient() {
    Pair<ClientConfig, ForgeConfigSpec> clientSpecPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new);
    ForgeConfigSpec clientSpec = clientSpecPair.getRight();
    client = clientSpecPair.getLeft();
    ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.CLIENT, clientSpec);
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec)

Aggregations

ForgeConfigSpec (net.minecraftforge.common.ForgeConfigSpec)10 AbstractConfig (com.electronwill.nightconfig.core.AbstractConfig)1 CommentedConfig (com.electronwill.nightconfig.core.CommentedConfig)1 UnmodifiableConfig (com.electronwill.nightconfig.core.UnmodifiableConfig)1 CommentedFileConfig (com.electronwill.nightconfig.core.file.CommentedFileConfig)1 WritingMode (com.electronwill.nightconfig.core.io.WritingMode)1 Stopwatch (com.google.common.base.Stopwatch)1 Lists (com.google.common.collect.Lists)1 LabeledEntry (com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry)1 BooleanEntry (com.simibubi.create.foundation.config.ui.entries.BooleanEntry)1 EnumEntry (com.simibubi.create.foundation.config.ui.entries.EnumEntry)1 NumberEntry (com.simibubi.create.foundation.config.ui.entries.NumberEntry)1 SubMenuEntry (com.simibubi.create.foundation.config.ui.entries.SubMenuEntry)1 ValueEntry (com.simibubi.create.foundation.config.ui.entries.ValueEntry)1 PollinatedConfigBuilder (gg.moonflower.pollen.api.config.PollinatedConfigBuilder)1 PollinatedConfigType (gg.moonflower.pollen.api.config.PollinatedConfigType)1 PollinatedModConfig (gg.moonflower.pollen.api.config.PollinatedModConfig)1 ConfigEvent (gg.moonflower.pollen.api.event.events.ConfigEvent)1 File (java.io.File)1 IOException (java.io.IOException)1