33import com .google .gson .GsonBuilder ;
44import dev .imb11 .fog .client .FogClient ;
55import dev .imb11 .fog .client .FogManager ;
6- import dev .imb11 .fog .client .util .math .EnvironmentCalculations ;
6+ import dev .imb11 .mru .yacl .ConfigHelper ;
7+ import dev .imb11 .mru .yacl .EntryType ;
78import dev .isxander .yacl3 .api .*;
89import dev .isxander .yacl3 .api .controller .BooleanControllerBuilder ;
9- import dev .isxander .yacl3 .api .controller .FloatSliderControllerBuilder ;
1010import dev .isxander .yacl3 .config .v2 .api .ConfigClassHandler ;
1111import dev .isxander .yacl3 .config .v2 .api .SerialEntry ;
1212import dev .isxander .yacl3 .config .v2 .api .serializer .GsonConfigSerializerBuilder ;
1313import net .minecraft .text .Text ;
1414import net .minecraft .util .Identifier ;
1515import org .jetbrains .annotations .NotNull ;
16- import java .util .Map ;
17- import java .util .TreeMap ;
1816
1917import static dev .imb11 .fog .client .FogClient .MOD_ID ;
2018
2119public class FogConfig {
2220 private static final String CONFIG_FILE_NAME = "config" ;
2321 private static final String CONFIG_FILE_EXTENSION = "json" ;
24- private static final String CONFIG_TRANSLATION_KEY = "config" ;
2522 private static final ConfigClassHandler <FogConfig > HANDLER = ConfigClassHandler
2623 .createBuilder (FogConfig .class )
2724 .id (Identifier .of (MOD_ID , CONFIG_FILE_NAME ))
@@ -31,6 +28,7 @@ public class FogConfig {
3128 .appendGsonBuilder (GsonBuilder ::setPrettyPrinting )
3229 .build ())
3330 .build ();
31+ private static final ConfigHelper HELPER = new ConfigHelper (MOD_ID , "config" );
3432 @ SerialEntry
3533 public float initialFogStart = 0.1f ;
3634 @ SerialEntry
@@ -51,13 +49,6 @@ public class FogConfig {
5149 @ SerialEntry
5250 public boolean disableMod = false ;
5351
54- private enum EntryType {
55- CATEGORY_NAME ,
56- GROUP_NAME ,
57- OPTION_NAME ,
58- OPTION_DESCRIPTION ,
59- }
60-
6152 public static @ NotNull FogConfig getInstance () {
6253 return HANDLER .instance ();
6354 }
@@ -79,78 +70,48 @@ public static void save() {
7970 FogManager .INSTANCE = new FogManager ();
8071 })
8172 .category (ConfigCategory .createBuilder ()
82- .name (getText (EntryType .CATEGORY_NAME , "fog_calculations" ))
83- .option (LabelOption .create (getText (EntryType .OPTION_NAME , "fog_calculations.warning" )))
84- .option (Option .<Float >createBuilder ().name (
85- getText (EntryType .OPTION_NAME , "initial_fog_start" )).description (
86- initialFogStart -> OptionDescription .createBuilder ().text (
87- getText (EntryType .OPTION_DESCRIPTION , "initial_fog_start" )).build ()).binding (
88- defaults .initialFogStart , () -> initialFogStart ,
89- newInitialFogStart -> initialFogStart = newInitialFogStart
90- ).controller (option -> FloatSliderControllerBuilder .create (option ).range (0.0F , 1.0F ).step (
91- 0.0001F ).formatValue (value -> Text .of (String .format ("%.2f%%" , value * 100.0F )))).build ())
92- .option (Option .<Float >createBuilder ().name (
93- getText (EntryType .OPTION_NAME , "initial_fog_end" )).description (
94- initialFogStart -> OptionDescription .createBuilder ().text (
95- getText (EntryType .OPTION_DESCRIPTION , "initial_fog_end" )).build ()).binding (
96- defaults .initialFogEnd , () -> initialFogEnd ,
97- newInitialFogEnd -> initialFogEnd = newInitialFogEnd
98- ).controller (option -> FloatSliderControllerBuilder .create (option ).range (0.0F , 1.0F ).step (
99- 0.0001F ).formatValue (value -> Text .of (String .format ("%.2f%%" , value * 100.0F )))).build ())
73+ .name (HELPER .getText (EntryType .CATEGORY_NAME , "fog_calculations" ))
74+ .option (LabelOption .create (HELPER .getText (EntryType .OPTION_NAME , "fog_calculations.warning" )))
75+ .option (HELPER .getSlider (
76+ "initial_fog_start" , 0f , 1f , 0.05f , defaults .initialFogStart , () -> config .initialFogStart ,
77+ val -> config .initialFogStart = val
78+ ))
79+ .option (HELPER .getSlider (
80+ "initial_fog_end" , 0f , 1f , 0.05f , defaults .initialFogEnd , () -> config .initialFogEnd ,
81+ val -> config .initialFogEnd = val
82+ ))
83+ .option (HELPER .get (
84+ "disable_raininess_effect" , defaults .disableRaininessEffect ,
85+ () -> config .disableRaininessEffect , val -> config .disableRaininessEffect = val
86+ ))
87+ .option (HELPER .get (
88+ "disable_underground_fog_multiplier" , defaults .disableUndergroundFogMultiplier ,
89+ () -> config .disableUndergroundFogMultiplier ,
90+ val -> config .disableUndergroundFogMultiplier = val
91+ ))
92+ .option (HELPER .get (
93+ "disable_biome_fog_colour" , defaults .disableBiomeFogColour ,
94+ () -> config .disableBiomeFogColour , val -> config .disableBiomeFogColour = val
95+ ))
10096 .option (Option .<Boolean >createBuilder ().name (
101- getText (EntryType .OPTION_NAME , "disable_raininess_effect " )).description (
97+ HELPER . getText (EntryType .OPTION_NAME , "disable_cloud_whitening " )).description (
10298 initialFogStart -> OptionDescription .createBuilder ().text (
103- getText (
104- EntryType .OPTION_DESCRIPTION ,
105- "disable_raininess_effect"
106- )).build ()).binding (
107- defaults .disableRaininessEffect , () -> disableRaininessEffect ,
108- newDisableRaininessEffect -> disableRaininessEffect = newDisableRaininessEffect
109- ).controller (BooleanControllerBuilder ::create ).build ())
110- .option (Option .<Boolean >createBuilder ().name (
111- getText (EntryType .OPTION_NAME , "disable_underground_fog_multiplier" )).description (
112- initialFogStart -> OptionDescription .createBuilder ().text (
113- getText (
114- EntryType .OPTION_DESCRIPTION ,
115- "disable_underground_fog_multiplier"
116- )).build ()).binding (
117- defaults .disableRaininessEffect , () -> disableRaininessEffect ,
118- newDisableRaininessEffect -> disableRaininessEffect = newDisableRaininessEffect
119- ).controller (BooleanControllerBuilder ::create ).build ())
120- .option (Option .<Boolean >createBuilder ().name (
121- getText (EntryType .OPTION_NAME , "disable_biome_fog_colour" )).description (
122- initialFogStart -> OptionDescription .createBuilder ().text (
123- getText (
124- EntryType .OPTION_DESCRIPTION ,
125- "disable_biome_fog_colour"
126- )).build ()).binding (
127- defaults .disableBiomeFogColour , () -> disableBiomeFogColour ,
128- newDisableBiomeFogColour -> disableBiomeFogColour = newDisableBiomeFogColour
129- ).controller (BooleanControllerBuilder ::create ).build ())
130- .option (Option .<Boolean >createBuilder ().name (
131- getText (EntryType .OPTION_NAME , "disable_cloud_whitening" )).description (
132- initialFogStart -> OptionDescription .createBuilder ().text (
133- getText (
99+ HELPER .getText (
134100 EntryType .OPTION_DESCRIPTION ,
135101 "disable_cloud_whitening"
136102 )).build ()).binding (
137103 defaults .disableCloudWhitening , () -> disableCloudWhitening ,
138104 newDisableCloudWhitening -> disableCloudWhitening = newDisableCloudWhitening
139- ).controller (BooleanControllerBuilder ::create ).available (!FogClient .isModInstalled ("sodium" )).build ())
140- .option (Option .<Boolean >createBuilder ().name (
141- getText (EntryType .OPTION_NAME , "disable_nether" )).description (
142- initialFogStart -> OptionDescription .createBuilder ().text (
143- getText (
144- EntryType .OPTION_DESCRIPTION ,
145- "disable_nether"
146- )).build ()).binding (
147- defaults .disableNether , () -> disableNether ,
148- newDisableNether -> disableNether = newDisableNether
149- ).controller (BooleanControllerBuilder ::create ).build ())
105+ ).controller (BooleanControllerBuilder ::create ).available (
106+ !FogClient .isModInstalled ("sodium" )).build ())
107+ .option (HELPER .get (
108+ "disable_nether" , defaults .disableNether , () -> config .disableNether ,
109+ val -> config .disableNether = val
110+ ))
150111 .option (Option .<Boolean >createBuilder ().name (
151- getText (EntryType .OPTION_NAME , "disable_mod" )).description (
112+ HELPER . getText (EntryType .OPTION_NAME , "disable_mod" )).description (
152113 initialFogStart -> OptionDescription .createBuilder ().text (
153- getText (
114+ HELPER . getText (
154115 EntryType .OPTION_DESCRIPTION ,
155116 "disable_mod"
156117 )).build ()).binding (
@@ -160,22 +121,4 @@ public static void save() {
160121 .build ())
161122 ));
162123 }
163-
164- /**
165- * @param entryType The type of the entry that requires a translation key,
166- * @param configOptionName The name of the entry that requires a translation key,
167- * @return The {@link Text} with substituted values in the translation key.
168- */
169- private static @ NotNull Text getText (@ NotNull FogConfig .EntryType entryType , @ NotNull String configOptionName ) {
170- @ NotNull String entryText ;
171- switch (entryType ) {
172- case CATEGORY_NAME -> entryText = "category" ;
173- case GROUP_NAME -> entryText = "group" ;
174- case OPTION_NAME -> entryText = "option" ;
175- case OPTION_DESCRIPTION -> entryText = "option.description" ;
176- default -> throw new IllegalArgumentException ("TextType is invalid." );
177- }
178-
179- return Text .translatable (String .format ("%s.%s.%s.%s" , MOD_ID , CONFIG_TRANSLATION_KEY , entryText , configOptionName ));
180- }
181124}
0 commit comments