diff --git a/build.gradle b/build.gradle index c809ac6637..83fe449204 100644 --- a/build.gradle +++ b/build.gradle @@ -65,6 +65,9 @@ def dependencies(DependencyHandler deps) { exclude(group: "io.github.fabricators_of_create") // avoid duplicate Porting Lib } + deps.modApi(deps.include("com.electronwill.night-config:core:$night_config_version")) + deps.modApi(deps.include("com.electronwill.night-config:toml:$night_config_version")) + deps.modApi(deps.include("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:$forge_config_api_port_version")) deps.modApi(deps.include("com.jozufozu.flywheel:flywheel-fabric-$flywheel_minecraft_version:$flywheel_version")) deps.modApi(deps.include("com.jamieswhiteshirt:reach-entity-attributes:$reach_entity_attributes_version")) deps.modApi(deps.include("io.github.tropheusj:milk-lib:$milk_lib_version")) @@ -199,6 +202,7 @@ processResources { "minecraft_version": minecraft_version, "loader_version": loader_version, "fabric_version": fabric_version, + "forge_config_version": forge_config_api_port_version, "milk_lib_version": milk_lib_version, "reach_entity_attributes_version": reach_entity_attributes_version ] diff --git a/gradle.properties b/gradle.properties index caecd360ec..4ddef864d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,7 @@ qm_version = 23 parchment_version = 2023.09.03 # Dependencies +forge_config_api_port_version = 8.0.0 # https://ci.tterrag.com/job/Flywheel/job/Fabric/ flywheel_minecraft_version = 1.20.1 flywheel_version = 0.6.10-2 @@ -31,8 +32,9 @@ milk_lib_version = 1.2.60 port_lib_version = 2.3.5-beta.33+1.20.1 # adding a module also requires adding a dependency to the FMJ -port_lib_modules = accessors,base,entity,extensions,networking,obj_loader,tags,transfer,models,tool_actions,client_events,brewing,config +port_lib_modules = accessors,base,entity,extensions,networking,obj_loader,tags,transfer,models,tool_actions,client_events,brewing +night_config_version = 3.6.3 jsr305_version = 3.0.2 # Compat diff --git a/run/config/fabric_loader_dependencies.json b/run/config/fabric_loader_dependencies.json new file mode 100644 index 0000000000..913a60838c --- /dev/null +++ b/run/config/fabric_loader_dependencies.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "overrides": { + "forgeconfigapiport": { + "-depends": { + "com_electronwill_night-config_core": "", + "com_electronwill_night-config_toml": "" + } + } + } +} diff --git a/run/gametest/config/fabric_loader_dependencies.json b/run/gametest/config/fabric_loader_dependencies.json new file mode 100644 index 0000000000..913a60838c --- /dev/null +++ b/run/gametest/config/fabric_loader_dependencies.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "overrides": { + "forgeconfigapiport": { + "-depends": { + "com_electronwill_night-config_core": "", + "com_electronwill_night-config_toml": "" + } + } + } +} diff --git a/run/server/config/fabric_loader_dependencies.json b/run/server/config/fabric_loader_dependencies.json new file mode 100644 index 0000000000..913a60838c --- /dev/null +++ b/run/server/config/fabric_loader_dependencies.json @@ -0,0 +1,11 @@ +{ + "version": 1, + "overrides": { + "forgeconfigapiport": { + "-depends": { + "com_electronwill_night-config_core": "", + "com_electronwill_night-config_toml": "" + } + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/config/ConfigBase.java b/src/main/java/com/simibubi/create/foundation/config/ConfigBase.java index 8d9e190ec2..e8921fbf78 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ConfigBase.java +++ b/src/main/java/com/simibubi/create/foundation/config/ConfigBase.java @@ -1,24 +1,27 @@ package com.simibubi.create.foundation.config; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec.ConfigValue; - import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.function.Supplier; -import static io.github.fabricators_of_create.porting_lib.config.ModConfigSpec.*; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; +import net.minecraftforge.common.ForgeConfigSpec.Builder; +import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; +import net.minecraftforge.common.ForgeConfigSpec.DoubleValue; +import net.minecraftforge.common.ForgeConfigSpec.EnumValue; +import net.minecraftforge.common.ForgeConfigSpec.IntValue; public abstract class ConfigBase { - public ModConfigSpec specification; + public ForgeConfigSpec specification; protected int depth; protected List> allValues; protected List children; - public void registerAll(final Builder builder) { + public void registerAll(final ForgeConfigSpec.Builder builder) { for (CValue cValue : allValues) cValue.register(builder); } @@ -37,7 +40,7 @@ public void onReload() { @FunctionalInterface protected static interface IValueProvider> - extends Function { + extends Function { } protected ConfigBool b(boolean current, String name, String... comment) { @@ -75,7 +78,7 @@ protected ConfigGroup group(int depth, String name, String... comment) { protected T nested(int depth, Supplier constructor, String... comment) { T config = constructor.get(); new ConfigGroup(config.getName(), depth, comment); - new CValue(config.getName(), builder -> { + new CValue(config.getName(), builder -> { config.depth = depth; config.registerAll(builder); if (config.depth > depth) @@ -114,7 +117,7 @@ public void addComments(Builder builder, String... comment) { builder.comment("."); } - public void register(ModConfigSpec.Builder builder) { + public void register(ForgeConfigSpec.Builder builder) { value = provider.apply(builder); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java index eeae71d2b8..675505e988 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java @@ -8,9 +8,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; - import org.lwjgl.glfw.GLFW; import com.simibubi.create.Create; @@ -28,6 +25,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.config.ModConfig; public class BaseConfigScreen extends ConfigScreen { @@ -45,7 +44,7 @@ public class BaseConfigScreen extends ConfigScreen { * If you are a Create Addon dev and want to change the config labels, * add a default action here. * - * Make sure you call either {@link #withSpecs(ModConfigSpec, ModConfigSpec, ModConfigSpec)} + * Make sure you call either {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)} * or {@link #searchForSpecsInModContainer()} * * @param modID the modID of your addon/mod @@ -68,9 +67,9 @@ public static BaseConfigScreen forCreate(Screen parent) { protected BoxWidget others; protected BoxWidget title; - protected ModConfigSpec clientSpec; - protected ModConfigSpec commonSpec; - protected ModConfigSpec serverSpec; + protected ForgeConfigSpec clientSpec; + protected ForgeConfigSpec commonSpec; + protected ForgeConfigSpec serverSpec; protected String clientTitle = "Client Config"; protected String commonTitle = "Common Config"; protected String serverTitle = "Server Config"; @@ -94,7 +93,7 @@ private BaseConfigScreen(Screen parent) { /** * If you have static references to your Configs or ConfigSpecs (like Create does in {@link AllConfigs}), - * please use {@link #withSpecs(ModConfigSpec, ModConfigSpec, ModConfigSpec)} instead + * please use {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)} instead */ public BaseConfigScreen searchForSpecsInModContainer() { if (!ConfigHelper.hasAnyForgeConfig(this.modID)){ @@ -102,19 +101,19 @@ public BaseConfigScreen searchForSpecsInModContainer() { } try { - clientSpec = ConfigHelper.findModConfigSpecFor(ConfigType.CLIENT, this.modID); + clientSpec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.CLIENT, this.modID); } catch (Exception e) { Create.LOGGER.debug("Unable to find ClientConfigSpec for mod: " + this.modID); } try { - commonSpec = ConfigHelper.findModConfigSpecFor(ConfigType.COMMON, this.modID); + commonSpec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.COMMON, this.modID); } catch (Exception e) { Create.LOGGER.debug("Unable to find CommonConfigSpec for mod: " + this.modID); } try { - serverSpec = ConfigHelper.findModConfigSpecFor(ConfigType.SERVER, this.modID); + serverSpec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.SERVER, this.modID); } catch (Exception e) { Create.LOGGER.debug("Unable to find ServerConfigSpec for mod: " + this.modID); } @@ -122,7 +121,7 @@ public BaseConfigScreen searchForSpecsInModContainer() { return this; } - public BaseConfigScreen withSpecs(@Nullable ModConfigSpec client, @Nullable ModConfigSpec common, @Nullable ModConfigSpec server) { + public BaseConfigScreen withSpecs(@Nullable ForgeConfigSpec client, @Nullable ForgeConfigSpec common, @Nullable ForgeConfigSpec server) { clientSpec = client; commonSpec = common; serverSpec = server; @@ -151,7 +150,7 @@ protected void init() { addRenderableWidget(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16).showingElement(clientText)); if (clientSpec != null) { - clientConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ConfigType.CLIENT, clientSpec))); + clientConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.CLIENT, clientSpec))); clientText.withElementRenderer(BoxWidget.gradientFactory.apply(clientConfigWidget)); } else { clientConfigWidget.active = false; @@ -163,7 +162,7 @@ protected void init() { addRenderableWidget(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 16).showingElement(commonText)); if (commonSpec != null) { - commonConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ConfigType.COMMON, commonSpec))); + commonConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.COMMON, commonSpec))); commonText.withElementRenderer(BoxWidget.gradientFactory.apply(commonConfigWidget)); } else { commonConfigWidget.active = false; @@ -188,7 +187,7 @@ protected void init() { "Gameplay settings can only be accessed from the in-game menu after joining a World or Server."), Palette.ALL_GRAY)); } else { - serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ConfigType.SERVER, serverSpec))); + serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.SERVER, serverSpec))); serverText.withElementRenderer(BoxWidget.gradientFactory.apply(serverConfigWidget)); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/CConfigureConfigPacket.java b/src/main/java/com/simibubi/create/foundation/config/ui/CConfigureConfigPacket.java index 9666e2c543..2c0b896da3 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/CConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/CConfigureConfigPacket.java @@ -5,10 +5,10 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.networking.SimplePacketBase; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.config.ModConfig; public class CConfigureConfigPacket extends SimplePacketBase { @@ -43,11 +43,11 @@ public boolean handle(Context context) { if (sender == null || !sender.hasPermissions(2)) return; - ModConfigSpec spec = ConfigHelper.findModConfigSpecFor(ConfigType.SERVER, modID); + ForgeConfigSpec spec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.SERVER, modID); if (spec == null) return; - ModConfigSpec.ValueSpec valueSpec = spec.getRaw(path); - ModConfigSpec.ConfigValue configValue = spec.getValues().get(path); + ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(path); + ForgeConfigSpec.ConfigValue configValue = spec.getValues().get(path); T v = (T) deserialize(configValue.get(), value); if (!valueSpec.test(v)) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java index bac607b193..b76a588c1b 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigHelper.java @@ -22,10 +22,10 @@ import com.simibubi.create.foundation.utility.Pair; import com.simibubi.create.infrastructure.config.AllConfigs; -import io.github.fabricators_of_create.porting_lib.config.ConfigTracker; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; -import io.github.fabricators_of_create.porting_lib.config.ModConfig; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.config.ConfigTracker; +import net.minecraftforge.fml.config.IConfigSpec; +import net.minecraftforge.fml.config.ModConfig; public class ConfigHelper { @@ -33,19 +33,19 @@ public class ConfigHelper { public static final Pattern annotationPattern = Pattern.compile("\\[@cui:([^:]*)(?::(.*))?]"); public static final Map changes = new HashMap<>(); - private static final LoadingCache> configCache = + private static final LoadingCache> configCache = CacheBuilder.newBuilder() .expireAfterAccess(5, TimeUnit.MINUTES) - .build(new CacheLoader>() { + .build(new CacheLoader>() { @Override - public EnumMap load(@Nonnull String key) { + public EnumMap load(@Nonnull String key) { return findModConfigsUncached(key); } }); // FIXME compat with other config libs? - private static EnumMap findModConfigsUncached(String modID) { - EnumMap configs = new EnumMap<>(ConfigType.class); + private static EnumMap findModConfigsUncached(String modID) { + EnumMap configs = new EnumMap<>(ModConfig.Type.class); ConfigTracker.INSTANCE.configSets().forEach((type, modConfigs) -> { modConfigs.forEach(modConfig -> { if(modConfig.getModId().equals(modID)) @@ -55,7 +55,7 @@ private static EnumMap findModConfigsUncached(String modI return Objects.requireNonNull(configs); } - public static ModConfigSpec findConfigSpecFor(ConfigType type, String modID) { + public static IConfigSpec findConfigSpecFor(ModConfig.Type type, String modID) { if (!modID.equals(Create.ID)) return configCache.getUnchecked(modID) .get(type) @@ -64,8 +64,12 @@ public static ModConfigSpec findConfigSpecFor(ConfigType type, String modID) { } @Nullable - public static ModConfigSpec findModConfigSpecFor(ConfigType type, String modID) { - return findConfigSpecFor(type, modID); + public static ForgeConfigSpec findForgeConfigSpecFor(ModConfig.Type type, String modID) { + IConfigSpec spec = findConfigSpecFor(type, modID); + if (spec instanceof ForgeConfigSpec) { + return (ForgeConfigSpec) spec; + } + return null; } public static boolean hasAnyConfig(String modID) { @@ -80,19 +84,19 @@ public static boolean hasAnyForgeConfig(String modID) { return configCache.getUnchecked(modID) .values() .stream() - .anyMatch(config -> config.getSpec() instanceof ModConfigSpec); + .anyMatch(config -> config.getSpec() instanceof ForgeConfigSpec); return true; } // Directly set a value public static void setConfigValue(ConfigPath path, String value) throws InvalidValueException { - ModConfigSpec spec = findModConfigSpecFor(path.getType(), path.getModID()); + ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID()); if (spec == null) return; List pathList = Arrays.asList(path.getPath()); - ModConfigSpec.ValueSpec valueSpec = spec.getRaw(pathList); - ModConfigSpec.ConfigValue configValue = spec.getValues() + ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(pathList); + ForgeConfigSpec.ConfigValue configValue = spec.getValues() .get(pathList); T v = (T) CConfigureConfigPacket.deserialize(configValue.get(), value); if (!valueSpec.test(v)) @@ -102,7 +106,7 @@ public static void setConfigValue(ConfigPath path, String value) throws Inva } // Add a value to the current UI's changes list - public static void setValue(String path, ModConfigSpec.ConfigValue configValue, T value, + public static void setValue(String path, ForgeConfigSpec.ConfigValue configValue, T value, @Nullable Map annotations) { if (value.equals(configValue.get())) { changes.remove(path); @@ -113,7 +117,7 @@ public static void setValue(String path, ModConfigSpec.ConfigValue config // Get a value from the current UI's changes list or the config value, if its // unchanged - public static T getValue(String path, ModConfigSpec.ConfigValue configValue) { + public static T getValue(String path, ForgeConfigSpec.ConfigValue configValue) { ConfigChange configChange = changes.get(path); if (configChange != null) // noinspection unchecked @@ -154,7 +158,7 @@ public static Pair> readMetadataFromComment(List { - ModConfigSpec.ConfigValue configValue = values.get(path); + ForgeConfigSpec.ConfigValue configValue = values.get(path); configValue.set(change.value); - if (type == ConfigType.SERVER) { + if (type == ModConfig.Type.SERVER) { AllPackets.getChannel().sendToServer(new CConfigureConfigPacket<>(ConfigScreen.modID, path, change.value)); } @@ -149,9 +149,9 @@ protected void resetConfig(UnmodifiableConfig values) { values.valueMap().forEach((key, obj) -> { if (obj instanceof AbstractConfig) { resetConfig((UnmodifiableConfig) obj); - } else if (obj instanceof ModConfigSpec.ConfigValue) { - ModConfigSpec.ConfigValue configValue = (ModConfigSpec.ConfigValue) obj; - ModConfigSpec.ValueSpec valueSpec = spec.getRaw((List) configValue.getPath()); + } else if (obj instanceof ForgeConfigSpec.ConfigValue) { + ForgeConfigSpec.ConfigValue configValue = (ForgeConfigSpec.ConfigValue) obj; + ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw((List) configValue.getPath()); List comments = new ArrayList<>(); @@ -270,16 +270,16 @@ protected void init() { ScreenOpener.open( new SubMenuConfigScreen(parent, humanKey, type, spec, (UnmodifiableConfig) obj)); - } else if (obj instanceof ModConfigSpec.ConfigValue) { - ModConfigSpec.ConfigValue configValue = (ModConfigSpec.ConfigValue) obj; - ModConfigSpec.ValueSpec valueSpec = spec.getRaw(configValue.getPath()); + } else if (obj instanceof ForgeConfigSpec.ConfigValue) { + ForgeConfigSpec.ConfigValue configValue = (ForgeConfigSpec.ConfigValue) obj; + ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(configValue.getPath()); Object value = configValue.get(); ConfigScreenList.Entry entry = null; if (value instanceof Boolean) { - entry = new BooleanEntry(humanKey, (ModConfigSpec.ConfigValue) configValue, valueSpec); + entry = new BooleanEntry(humanKey, (ForgeConfigSpec.ConfigValue) configValue, valueSpec); } else if (value instanceof Enum) { - entry = new EnumEntry(humanKey, (ModConfigSpec.ConfigValue>) configValue, valueSpec); + entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue>) configValue, valueSpec); } else if (value instanceof Number) { entry = NumberEntry.create(value, humanKey, configValue, valueSpec); } @@ -311,7 +311,7 @@ protected void init() { list.search(highlights.stream().findFirst().orElse("")); //extras for server configs - if (type != ConfigType.SERVER) + if (type != ModConfig.Type.SERVER) return; if (minecraft.hasSingleplayerServer()) return; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwConfigScreen.java index f584e6559c..1155591920 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwConfigScreen.java @@ -2,8 +2,6 @@ import java.util.Locale; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; - import org.jetbrains.annotations.NotNull; import com.jozufozu.flywheel.config.FlwConfig; @@ -18,6 +16,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import net.minecraftforge.fml.config.ModConfig; public class FlwConfigScreen extends BaseConfigScreen { @@ -40,7 +39,7 @@ protected void init() { addRenderableWidget(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16).showingElement(clientText)); if (flwConfig != null) { - clientConfigWidget.withCallback(() -> linkTo(new FlwSubMenuConfigScreen(this, ConfigType.CLIENT, flwConfig))); + clientConfigWidget.withCallback(() -> linkTo(new FlwSubMenuConfigScreen(this, ModConfig.Type.CLIENT, flwConfig))); clientText.withElementRenderer(BoxWidget.gradientFactory.apply(clientConfigWidget)); } else { clientConfigWidget.active = false; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java index 9581efbcf0..0ff266b94e 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/compat/flywheel/FlwSubMenuConfigScreen.java @@ -21,23 +21,23 @@ import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.Couple; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractSelectionListAccessor; +import net.minecraftforge.fml.config.ModConfig; public class FlwSubMenuConfigScreen extends SubMenuConfigScreen { private final FlwConfig flwConfig; - public FlwSubMenuConfigScreen(Screen parent, String title, ConfigType type, FlwConfig flwConfig) { + public FlwSubMenuConfigScreen(Screen parent, String title, ModConfig.Type type, FlwConfig flwConfig) { super(parent, title, type, null, null); this.flwConfig = flwConfig; } - public FlwSubMenuConfigScreen(Screen parent, ConfigType type, FlwConfig flwConfig) { + public FlwSubMenuConfigScreen(Screen parent, ModConfig.Type type, FlwConfig flwConfig) { this(parent, "root", type, flwConfig); } @@ -179,7 +179,7 @@ protected void init() { list.search(highlights.stream().findFirst().orElse("")); //extras for server configs - if (type != ConfigType.SERVER) + if (type != ModConfig.Type.SERVER) return; if (minecraft.hasSingleplayerServer()) return; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java index 3af1ff2571..52b6f3b09d 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java @@ -6,9 +6,9 @@ import com.simibubi.create.foundation.gui.element.RenderElement; import com.simibubi.create.foundation.gui.widget.BoxWidget; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.client.gui.GuiGraphics; import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractWidgetAccessor; +import net.minecraftforge.common.ForgeConfigSpec; public class BooleanEntry extends ValueEntry { @@ -16,7 +16,7 @@ public class BooleanEntry extends ValueEntry { RenderElement disabled; BoxWidget button; - public BooleanEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public BooleanEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); enabled = AllIcons.I_CONFIRM.asStencil() diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java index 69d4977f74..3e8c59f79c 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java @@ -11,9 +11,9 @@ import com.simibubi.create.foundation.gui.element.TextStencilElement; import com.simibubi.create.foundation.gui.widget.BoxWidget; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraftforge.common.ForgeConfigSpec; public class EnumEntry extends ValueEntry> { @@ -23,7 +23,7 @@ public class EnumEntry extends ValueEntry> { protected BoxWidget cycleLeft; protected BoxWidget cycleRight; - public EnumEntry(String label, ModConfigSpec.ConfigValue> value, ModConfigSpec.ValueSpec spec) { + public EnumEntry(String label, ForgeConfigSpec.ConfigValue> value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); valueText = new TextStencilElement(Minecraft.getInstance().font, "YEP").centered(true, true); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java index 90c53acff4..a8f0040b74 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java @@ -12,13 +12,13 @@ import com.simibubi.create.foundation.gui.element.TextStencilElement; import com.simibubi.create.foundation.utility.Components; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.EditBox; import net.minecraft.network.chat.MutableComponent; import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractWidgetAccessor; +import net.minecraftforge.common.ForgeConfigSpec; public abstract class NumberEntry extends ValueEntry { @@ -27,19 +27,19 @@ public abstract class NumberEntry extends ValueEntry { protected EditBox textField; @Nullable - public static NumberEntry create(Object type, String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public static NumberEntry create(Object type, String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { if (type instanceof Integer) { - return new IntegerEntry(label, (ModConfigSpec.ConfigValue) value, spec); + return new IntegerEntry(label, (ForgeConfigSpec.ConfigValue) value, spec); } else if (type instanceof Float) { - return new FloatEntry(label, (ModConfigSpec.ConfigValue) value, spec); + return new FloatEntry(label, (ForgeConfigSpec.ConfigValue) value, spec); } else if (type instanceof Double) { - return new DoubleEntry(label, (ModConfigSpec.ConfigValue) value, spec); + return new DoubleEntry(label, (ForgeConfigSpec.ConfigValue) value, spec); } return null; } - public NumberEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public NumberEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); textField = new ConfigTextField(Minecraft.getInstance().font, 0, 0, 200, 20); if (this instanceof IntegerEntry && annotations.containsKey("IntDisplay")) { @@ -171,7 +171,7 @@ public void render(GuiGraphics graphics, int index, int y, int x, int width, int public static class IntegerEntry extends NumberEntry { - public IntegerEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public IntegerEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); } @@ -203,7 +203,7 @@ protected Function getParser() { public static class FloatEntry extends NumberEntry { - public FloatEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public FloatEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); } @@ -225,7 +225,7 @@ protected Function getParser() { public static class DoubleEntry extends NumberEntry { - public DoubleEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public DoubleEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label, value, spec); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java index d6f44c3552..b824d5ec7e 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java @@ -8,15 +8,15 @@ import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; import com.simibubi.create.foundation.gui.widget.BoxWidget; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.client.gui.GuiGraphics; import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractWidgetAccessor; +import net.minecraftforge.common.ForgeConfigSpec; public class SubMenuEntry extends ConfigScreenList.LabeledEntry { protected BoxWidget button; - public SubMenuEntry(SubMenuConfigScreen parent, String label, ModConfigSpec spec, UnmodifiableConfig config) { + public SubMenuEntry(SubMenuConfigScreen parent, String label, ForgeConfigSpec spec, UnmodifiableConfig config) { super(label); button = new BoxWidget(0, 0, 35, 16) diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java index 1e94161298..f147d35d10 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java @@ -21,22 +21,22 @@ import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Pair; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractSelectionList; import io.github.fabricators_of_create.porting_lib.mixin.accessors.client.accessor.AbstractSelectionList$EntryAccessor; +import net.minecraftforge.common.ForgeConfigSpec; public class ValueEntry extends ConfigScreenList.LabeledEntry { protected static final int resetWidth = 28;//including 6px offset on either side - protected ModConfigSpec.ConfigValue value; - protected ModConfigSpec.ValueSpec spec; + protected ForgeConfigSpec.ConfigValue value; + protected ForgeConfigSpec.ValueSpec spec; protected BoxWidget resetButton; protected boolean editable = true; - public ValueEntry(String label, ModConfigSpec.ConfigValue value, ModConfigSpec.ValueSpec spec) { + public ValueEntry(String label, ForgeConfigSpec.ConfigValue value, ForgeConfigSpec.ValueSpec spec) { super(label); this.value = value; this.spec = spec; diff --git a/src/main/java/com/simibubi/create/infrastructure/command/ConfigCommand.java b/src/main/java/com/simibubi/create/infrastructure/command/ConfigCommand.java index bdbe12d9a4..798f464710 100644 --- a/src/main/java/com/simibubi/create/infrastructure/command/ConfigCommand.java +++ b/src/main/java/com/simibubi/create/infrastructure/command/ConfigCommand.java @@ -8,10 +8,10 @@ import com.simibubi.create.foundation.config.ui.ConfigHelper; import com.simibubi.create.foundation.utility.Components; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.fml.config.ModConfig; /** * Examples: @@ -52,7 +52,7 @@ public class ConfigCommand { return 0; } - if (configPath.getType() == ConfigType.CLIENT) { + if (configPath.getType() == ModConfig.Type.CLIENT) { ServerPlayer player = ctx.getSource().getPlayerOrException(); AllPackets.getChannel().sendToClient(new SConfigureConfigPacket("SET" + path, value), player); diff --git a/src/main/java/com/simibubi/create/infrastructure/command/SConfigureConfigPacket.java b/src/main/java/com/simibubi/create/infrastructure/command/SConfigureConfigPacket.java index 26f3034ac3..bf7594386c 100644 --- a/src/main/java/com/simibubi/create/infrastructure/command/SConfigureConfigPacket.java +++ b/src/main/java/com/simibubi/create/infrastructure/command/SConfigureConfigPacket.java @@ -5,8 +5,6 @@ import com.simibubi.create.foundation.utility.CameraAngleAnimationService; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; - import org.slf4j.Logger; import com.mojang.logging.LogUtils; @@ -34,6 +32,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.fml.config.ModConfig; public class SConfigureConfigPacket extends SimplePacketBase { @@ -89,7 +88,7 @@ private static void trySetConfig(String option, String value) { return; } - if (configPath.getType() != ConfigType.CLIENT) { + if (configPath.getType() != ModConfig.Type.CLIENT) { Create.LOGGER.warn("Received type-mismatched config packet on client"); return; } diff --git a/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java b/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java index 0b5471a8ac..45af37c5bf 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java @@ -5,22 +5,21 @@ import java.util.Map.Entry; import java.util.function.Supplier; -import io.github.fabricators_of_create.porting_lib.config.ConfigEvents; -import io.github.fabricators_of_create.porting_lib.config.ConfigRegistry; -import io.github.fabricators_of_create.porting_lib.config.ConfigType; +import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry; +import fuzs.forgeconfigapiport.api.config.v2.ModConfigEvents; + +import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.Create; import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.foundation.config.ConfigBase; -import io.github.fabricators_of_create.porting_lib.config.ModConfig; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec; - -import org.apache.commons.lang3.tuple.Pair; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.config.ModConfig; public class AllConfigs { - private static final Map CONFIGS = new EnumMap<>(ConfigType.class); + private static final Map CONFIGS = new EnumMap<>(ModConfig.Type.class); private static CClient client; private static CCommon common; @@ -38,12 +37,12 @@ public static CServer server() { return server; } - public static ConfigBase byType(ConfigType type) { + public static ConfigBase byType(ModConfig.Type type) { return CONFIGS.get(type); } - private static T register(Supplier factory, ConfigType side) { - Pair specPair = new ModConfigSpec.Builder().configure(builder -> { + private static T register(Supplier factory, ModConfig.Type side) { + Pair specPair = new ForgeConfigSpec.Builder().configure(builder -> { T config = factory.get(); config.registerAll(builder); return config; @@ -56,17 +55,17 @@ private static T register(Supplier factory, ConfigType } public static void register() { - client = register(CClient::new, ConfigType.CLIENT); - common = register(CCommon::new, ConfigType.COMMON); - server = register(CServer::new, ConfigType.SERVER); + client = register(CClient::new, ModConfig.Type.CLIENT); + common = register(CCommon::new, ModConfig.Type.COMMON); + server = register(CServer::new, ModConfig.Type.SERVER); - for (Entry pair : CONFIGS.entrySet()) - ConfigRegistry.registerConfig(Create.ID, pair.getKey(), pair.getValue().specification); + for (Entry pair : CONFIGS.entrySet()) + ForgeConfigRegistry.INSTANCE.register(Create.ID, pair.getKey(), pair.getValue().specification); BlockStressValues.registerProvider(Create.ID, server().kinetics.stressValues); - ConfigEvents.LOADING.register(AllConfigs::onLoad); - ConfigEvents.RELOADING.register(AllConfigs::onReload); + ModConfigEvents.loading(Create.ID).register(AllConfigs::onLoad); + ModConfigEvents.reloading(Create.ID).register(AllConfigs::onReload); } public static void onLoad(ModConfig modConfig) { diff --git a/src/main/java/com/simibubi/create/infrastructure/config/CStress.java b/src/main/java/com/simibubi/create/infrastructure/config/CStress.java index 8444aff8ee..13e0b7b257 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/CStress.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/CStress.java @@ -11,10 +11,11 @@ import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.RegisteredObjects; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec.Builder; -import io.github.fabricators_of_create.porting_lib.config.ModConfigSpec.ConfigValue; +import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; +import net.minecraftforge.common.ForgeConfigSpec.Builder; +import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; public class CStress extends ConfigBase implements IStressValueProvider { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index aef58aaf48..da7bfdbbb3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -63,8 +63,8 @@ "porting_lib_transfer": ">=${port_lib_transfer_version}", "porting_lib_models": ">=${port_lib_models_version}", "porting_lib_client_events": ">=${port_lib_client_events_version}", - "porting_lib_config": ">=${port_lib_config_version}", + "forgeconfigapiport": ">=${forge_config_version}", "milk": ">=${milk_lib_version}", "reach-entity-attributes": ">=${reach_entity_attributes_version}" },