Skip to content

Commit

Permalink
Revert "switch to porting lib config"
Browse files Browse the repository at this point in the history
This reverts commit 6e0c7d9.
  • Loading branch information
IThundxr committed Aug 30, 2024
1 parent 2efe1cd commit a5a818f
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 122 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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
]
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions run/config/fabric_loader_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 1,
"overrides": {
"forgeconfigapiport": {
"-depends": {
"com_electronwill_night-config_core": "",
"com_electronwill_night-config_toml": ""
}
}
}
}
11 changes: 11 additions & 0 deletions run/gametest/config/fabric_loader_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 1,
"overrides": {
"forgeconfigapiport": {
"-depends": {
"com_electronwill_night-config_core": "",
"com_electronwill_night-config_toml": ""
}
}
}
}
11 changes: 11 additions & 0 deletions run/server/config/fabric_loader_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 1,
"overrides": {
"forgeconfigapiport": {
"-depends": {
"com_electronwill_night-config_core": "",
"com_electronwill_night-config_toml": ""
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<CValue<?, ?>> allValues;
protected List<ConfigBase> children;

public void registerAll(final Builder builder) {
public void registerAll(final ForgeConfigSpec.Builder builder) {
for (CValue<?, ?> cValue : allValues)
cValue.register(builder);
}
Expand All @@ -37,7 +40,7 @@ public void onReload() {

@FunctionalInterface
protected static interface IValueProvider<V, T extends ConfigValue<V>>
extends Function<Builder, T> {
extends Function<ForgeConfigSpec.Builder, T> {
}

protected ConfigBool b(boolean current, String name, String... comment) {
Expand Down Expand Up @@ -75,7 +78,7 @@ protected ConfigGroup group(int depth, String name, String... comment) {
protected <T extends ConfigBase> T nested(int depth, Supplier<T> constructor, String... comment) {
T config = constructor.get();
new ConfigGroup(config.getName(), depth, comment);
new CValue<Boolean, BooleanValue>(config.getName(), builder -> {
new CValue<Boolean, ForgeConfigSpec.BooleanValue>(config.getName(), builder -> {
config.depth = depth;
config.registerAll(builder);
if (config.depth > depth)
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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
Expand All @@ -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";
Expand All @@ -94,35 +93,35 @@ 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)){
return this;
}

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);
}

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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends SimplePacketBase {

Expand Down Expand Up @@ -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<T> configValue = spec.getValues().get(path);
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))
Expand Down
Loading

0 comments on commit a5a818f

Please sign in to comment.