Skip to content

Commit 2e0c80f

Browse files
committed
Forge cloth config integration
1 parent a387534 commit 2e0c80f

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
11
package org.infernalstudios.celesteconfig;
22

3+
import me.shedaniel.clothconfig2.api.ConfigBuilder;
4+
import me.shedaniel.clothconfig2.api.ConfigCategory;
5+
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
6+
import net.minecraft.client.gui.screens.Screen;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraftforge.client.ConfigScreenHandler;
9+
import net.minecraftforge.fml.ModLoadingContext;
310
import net.minecraftforge.fml.common.Mod;
4-
import net.minecraftforge.fml.event.config.ModConfigEvent;
5-
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
611
import org.infernalstudios.celesteconfig.config.CelestialConfigOptions;
712

813
@Mod(Constants.MOD_ID)
914
public class CelestialConfigration {
1015

1116
public CelestialConfigration() {
1217
CelestialConfigOptions.init();
13-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onConfigLoad);
1418
CommonClass.init(CelestialConfigOptions.getMoonWidthScalar(), CelestialConfigOptions.getMoonHeightScalar(), CelestialConfigOptions.getSunWidthScalar(), CelestialConfigOptions.getSunHeightScalar());
19+
20+
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
21+
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> buildConfigScreen(parent)));
1522
}
1623

17-
public void onConfigLoad(ModConfigEvent event) {
18-
CommonClass.init(CelestialConfigOptions.getMoonWidthScalar(), CelestialConfigOptions.getMoonHeightScalar(), CelestialConfigOptions.getSunWidthScalar(), CelestialConfigOptions.getSunHeightScalar());
24+
public Screen buildConfigScreen(Screen parent) {
25+
ConfigBuilder builder = ConfigBuilder.create()
26+
.setParentScreen(parent)
27+
.setTitle(Component.translatable("text.autoconfig.celesteconfig.title"));
28+
29+
ConfigCategory general = builder.getOrCreateCategory(Component.translatable("text.autoconfig.celesteconfig.title"));
30+
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
31+
32+
general.addEntry(entryBuilder.startDoubleField(Component.translatable("text.autoconfig.celesteconfig.option.moonWidth"), CelestialConfigOptions.getMoonWidthScalar())
33+
.setDefaultValue(1.0D)
34+
.setSaveConsumer(CelestialConfigOptions::setMoonWidthScalar)
35+
.build());
36+
37+
general.addEntry(entryBuilder.startDoubleField(Component.translatable("text.autoconfig.celesteconfig.option.moonHeight"), CelestialConfigOptions.getMoonHeightScalar())
38+
.setDefaultValue(1.0D)
39+
.setSaveConsumer(CelestialConfigOptions::setMoonHeightScalar)
40+
.build());
41+
42+
general.addEntry(entryBuilder.startDoubleField(Component.translatable("text.autoconfig.celesteconfig.option.sunWidth"), CelestialConfigOptions.getSunWidthScalar())
43+
.setDefaultValue(1.0D)
44+
.setSaveConsumer(CelestialConfigOptions::setSunWidthScalar)
45+
.build());
46+
47+
general.addEntry(entryBuilder.startDoubleField(Component.translatable("text.autoconfig.celesteconfig.option.sunHeight"), CelestialConfigOptions.getSunHeightScalar())
48+
.setDefaultValue(1.0D)
49+
.setSaveConsumer(CelestialConfigOptions::setSunHeightScalar)
50+
.build());
51+
52+
builder.setSavingRunnable(() -> CommonClass.init(CelestialConfigOptions.getMoonWidthScalar(), CelestialConfigOptions.getMoonHeightScalar(), CelestialConfigOptions.getSunWidthScalar(), CelestialConfigOptions.getSunHeightScalar()));
53+
54+
return builder.build();
1955
}
2056
}

forge/src/main/java/org/infernalstudios/celesteconfig/config/CelestialConfigOptions.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void init() {
2323
moonWidthScalar = client_builder.comment("Moon Width Scalar").defineInRange("celesteconfig.moon.width", 1.0D, 0.0D, 100.0D);
2424
moonHeightScalar = client_builder.comment("Moon Height Scalar").defineInRange("celesteconfig.moon.height", 1.0D, 0.0D, 100.0D);
2525
sunWidthScalar = client_builder.comment("Sun Width Scalar").defineInRange("celesteconfig.sun.width", 1.0D, 0.0D, 100.0D);
26-
sunHeightScalar = client_builder.comment("Moon Height Scalar").defineInRange("celesteconfig.sun.height", 1.0D, 0.0D, 100.0D);
26+
sunHeightScalar = client_builder.comment("Sun Height Scalar").defineInRange("celesteconfig.sun.height", 1.0D, 0.0D, 100.0D);
2727
client_config = client_builder.build();
2828

2929
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CelestialConfigOptions.client_config);
@@ -37,16 +37,36 @@ public static double getMoonWidthScalar() {
3737
return moonWidthScalar.get();
3838
}
3939

40+
public static void setMoonWidthScalar(double value) {
41+
moonWidthScalar.set(value);
42+
client_config.save();
43+
}
44+
4045
public static double getMoonHeightScalar() {
4146
return moonHeightScalar.get();
4247
}
4348

49+
public static void setMoonHeightScalar(double value) {
50+
moonHeightScalar.set(value);
51+
client_config.save();
52+
}
53+
4454
public static double getSunWidthScalar() {
4555
return sunWidthScalar.get();
4656
}
4757

58+
public static void setSunWidthScalar(double value) {
59+
sunWidthScalar.set(value);
60+
client_config.save();
61+
}
62+
4863
public static double getSunHeightScalar() {
4964
return sunHeightScalar.get();
5065
}
5166

67+
public static void setSunHeightScalar(double value) {
68+
sunHeightScalar.set(value);
69+
client_config.save();
70+
}
71+
5272
}

0 commit comments

Comments
 (0)