bug fixing for major config refactoring

This commit is contained in:
James Seibel
2025-10-12 21:11:16 -05:00
parent 71bb151e61
commit 0086f40053
6 changed files with 167 additions and 170 deletions
@@ -10,7 +10,7 @@ import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapp
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.ConfigHandler;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
@@ -170,7 +170,7 @@ public abstract class AbstractModInitializer
private void initConfig()
{
ConfigBase.RunFirstTimeSetup();
ConfigHandler.tryRunFirstTimeSetup();
Config.completeDelayedSetup();
}
@@ -192,6 +192,12 @@ public abstract class AbstractModInitializer
{
LOGGER.info("Running Delayed setup...");
this.runDelayedSetup();
if (ConfigHandler.INSTANCE == null)
{
throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method.");
}
LOGGER.info("Delayed setup complete, firing DhApiAfterDhInitEvent event...");
// should be fired after all delayed setup so singletons and config can be accessed
@@ -3,8 +3,8 @@ package com.seibel.distanthorizons.common.commands;
import com.mojang.brigadier.arguments.*;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
import com.seibel.distanthorizons.core.config.ConfigHandler;
import com.seibel.distanthorizons.core.config.types.AbstractConfigBase;
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import net.minecraft.commands.CommandSourceStack;
@@ -43,7 +43,7 @@ public class ConfigCommand extends AbstractCommand
LiteralArgumentBuilder<CommandSourceStack> builder = literal("config");
HashSet<String> addedCommands = new HashSet<>();
for (AbstractConfigType<?, ?> type : ConfigBase.INSTANCE.entries)
for (AbstractConfigBase<?> type : ConfigHandler.INSTANCE.configBaseList)
{
// Skip non-config entries
if (!(type instanceof ConfigEntry))
@@ -12,26 +12,17 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
// Logger (for debug stuff)
import com.seibel.distanthorizons.api.enums.config.DisallowSelectingViaConfigGui;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.ConfigHandler;
import com.seibel.distanthorizons.core.config.types.*;
import com.seibel.distanthorizons.common.wrappers.gui.updater.ChangelogScreen;
// Uses https://github.com/TheElectronWill/night-config for toml (only for Fabric since Forge already includes this)
// Gets info from our own mod
// Minecraft imports
import com.seibel.distanthorizons.core.config.types.enums.EConfigCommentTextPosition;
import com.seibel.distanthorizons.core.config.types.enums.EConfigValidity;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
import com.seibel.distanthorizons.core.logging.SpamReducedLogger;
import com.seibel.distanthorizons.core.render.renderer.LodRenderer;
import com.seibel.distanthorizons.core.util.AnnotationUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui;
import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper;
@@ -50,6 +41,7 @@ import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
#if MC_VER < MC_1_20_1
@@ -128,8 +120,8 @@ public class ClassicConfigGUI
//==============//
/** if you want to get this config gui's screen call this */
public static Screen getScreen(ConfigBase configBase, Screen parent, String category)
{ return new ConfigScreen(configBase, parent, category); }
public static Screen getScreen(Screen parent, String category)
{ return new ConfigScreen(parent, category); }
/** Pain */
private static class ConfigScreen extends DhScreen
@@ -139,8 +131,6 @@ public class ClassicConfigGUI
private static final String TRANSLATION_PREFIX = ModInfo.ID + ".config.";
private final ConfigBase configBase;
private final Screen parent;
private final String category;
private ConfigListWidget configListWidget;
@@ -154,14 +144,13 @@ public class ClassicConfigGUI
// constructor //
//=============//
protected ConfigScreen(ConfigBase configBase, Screen parent, String category)
protected ConfigScreen(Screen parent, String category)
{
super(Translatable(
LANG_WRAPPER.langExists(ModInfo.ID + ".config" + (category.isEmpty() ? "." + category : "") + ".title") ?
ModInfo.ID + ".config.title" :
ModInfo.ID + ".config" + (category.isEmpty() ? "" : "." + category) + ".title")
);
this.configBase = configBase;
this.parent = parent;
this.category = category;
}
@@ -182,7 +171,7 @@ public class ClassicConfigGUI
super.init();
if (!this.reload)
{
ConfigBase.INSTANCE.configFileHandler.loadFromFile();
ConfigHandler.INSTANCE.configFileHandler.loadFromFile();
}
// Changelog button
@@ -229,7 +218,7 @@ public class ClassicConfigGUI
ConfigScreenConfigs.OPTION_FIELD_WIDTH, ConfigScreenConfigs.OPTION_FIELD_HEIGHT,
(button) ->
{
ConfigBase.INSTANCE.configFileHandler.loadFromFile();
ConfigHandler.INSTANCE.configFileHandler.loadFromFile();
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
}));
@@ -240,7 +229,7 @@ public class ClassicConfigGUI
ConfigScreenConfigs.OPTION_FIELD_WIDTH, ConfigScreenConfigs.OPTION_FIELD_HEIGHT,
(button) ->
{
ConfigBase.INSTANCE.configFileHandler.saveToFile();
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
}));
@@ -255,22 +244,22 @@ public class ClassicConfigGUI
this.addWidget(this.configListWidget);
for (AbstractConfigType info : ConfigBase.INSTANCE.entries)
for (AbstractConfigBase<?> configEntry : ConfigHandler.INSTANCE.configBaseList)
{
try
{
if (info.getCategory().matches(this.category)
&& info.getAppearance().showInGui)
if (configEntry.getCategory().matches(this.category)
&& configEntry.getAppearance().showInGui)
{
this.addMenuItem(info);
this.addMenuItem(configEntry);
}
}
catch (Exception e)
{
String message = "ERROR: Failed to show [" + info.getNameWCategory() + "], error: ["+e.getMessage()+"]";
if (info.get() != null)
String message = "ERROR: Failed to show [" + configEntry.getNameAndCategory() + "], error: ["+e.getMessage()+"]";
if (configEntry.get() != null)
{
message += " with the value [" + info.get() + "] with type [" + info.getType() + "]";
message += " with the value [" + configEntry.get() + "] with type [" + configEntry.getType() + "]";
}
LOGGER.error(message, e);
@@ -279,115 +268,61 @@ public class ClassicConfigGUI
CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run());
}
private void addMenuItem(AbstractConfigType configType)
private void addMenuItem(AbstractConfigBase<?> configEntry)
{
trySetupConfigEntry(configType);
trySetupConfigEntry(configEntry);
if (this.tryCreateInputField(configType)) return;
if (this.tryCreateCategoryButton(configType)) return;
if (this.tryCreateButton(configType)) return;
if (this.tryCreateComment(configType)) return;
if (this.tryCreateSpacer(configType)) return;
if (this.tryCreateLinkedEntry(configType)) return;
if (this.tryCreateInputField(configEntry)) return;
if (this.tryCreateCategoryButton(configEntry)) return;
if (this.tryCreateButton(configEntry)) return;
if (this.tryCreateComment(configEntry)) return;
if (this.tryCreateSpacer(configEntry)) return;
if (this.tryCreateLinkedEntry(configEntry)) return;
LOGGER.warn("Config [" + configType.getNameWCategory() + "] failed to show. Please try something like changing its type.");
LOGGER.warn("Config [" + configEntry.getNameAndCategory() + "] failed to show. Please try something like changing its type.");
}
private static void trySetupConfigEntry(AbstractConfigType configType)
private static void trySetupConfigEntry(AbstractConfigBase<?> configMenuOption)
{
configType.guiValue = new EntryInfo();
Class<?> fieldClass = configType.getType();
configMenuOption.guiValue = new EntryInfo();
Class<?> configValueClass = configMenuOption.getType();
if (configType instanceof ConfigEntry)
if (configMenuOption instanceof ConfigEntry)
{
ConfigEntry configEntry = (ConfigEntry) configType;
ConfigEntry<?> configEntry = (ConfigEntry<?>) configMenuOption;
if (fieldClass == Integer.class)
if (configValueClass == Integer.class)
{
// For int
setupEntryInfoTextField(configEntry, Integer::parseInt, INTEGER_ONLY_REGEX, true);
setupTextMenuOption(configEntry, Integer::parseInt, INTEGER_ONLY_REGEX, true);
}
else if (fieldClass == Double.class)
else if (configValueClass == Double.class)
{
// For double
setupEntryInfoTextField(configEntry, Double::parseDouble, DECIMAL_ONLY_REGEX, false);
setupTextMenuOption(configEntry, Double::parseDouble, DECIMAL_ONLY_REGEX, false);
}
else if (fieldClass == String.class || fieldClass == List.class)
else if (configValueClass == String.class || configValueClass == List.class)
{
// For string or list
setupEntryInfoTextField(configEntry, String::length, null, true);
setupTextMenuOption(configEntry, String::length, null, true);
}
else if (fieldClass == Boolean.class)
else if (configValueClass == Boolean.class)
{
// For boolean
Function<Object, Component> func = value -> Translatable("distanthorizons.general."+((Boolean) value ? "true" : "false")).withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
((EntryInfo) configEntry.guiValue).widget =
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
(button) ->
{
button.active = !configEntry.apiIsOverriding();
configEntry.uiSetWithoutSaving(!(Boolean) configEntry.get());
button.setMessage(func.apply(configEntry.get()));
}, func);
ConfigEntry<Boolean> booleanConfigEntry = (ConfigEntry<Boolean>) configEntry;
setupBooleanMenuOption(booleanConfigEntry);
}
else if (fieldClass.isEnum())
else if (configValueClass.isEnum())
{
// For enum
List<?> values = Arrays.asList(configEntry.getType().getEnumConstants());
Function<Object, Component> func = (value) -> Translatable(TRANSLATION_PREFIX + "enum." + fieldClass.getSimpleName() + "." + configEntry.get().toString());
((EntryInfo) configEntry.guiValue).widget = new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>((button) ->
{
// get the currently selected enum and enum index
int startingIndex = values.indexOf(configEntry.get());
Enum<?> enumValue = (Enum<?>) values.get(startingIndex);
// search for the next enum that is selectable
int index = startingIndex + 1;
index = (index >= values.size()) ? 0 : index;
while (index != startingIndex)
{
enumValue = (Enum<?>) values.get(index);
if (!AnnotationUtil.doesEnumHaveAnnotation(enumValue, DisallowSelectingViaConfigGui.class))
{
// this enum shouldn't be selectable via the UI,
// skip it
break;
}
index++;
index = (index >= values.size()) ? 0 : index;
}
if (index == startingIndex)
{
// none of the enums should be selectable, this is a programmer error
enumValue = (Enum<?>) values.get(startingIndex);
LOGGER.warn("Enum [" + enumValue.getClass() + "] doesn't contain any values that should be selectable via the UI, sticking to the currently selected value [" + enumValue + "].");
}
((ConfigEntry<Enum<?>>) configEntry).uiSetWithoutSaving(enumValue);
if (configEntry.getApiValue() != null)
{
button.active = false;
}
else
{
button.active = true;
}
button.setMessage(func.apply(configEntry.get()));
}, func);
ConfigEntry<Enum<?>> enumConfigEntry = (ConfigEntry<Enum<?>>) configEntry;
Class<? extends Enum<?>> configEnumClass = (Class<? extends Enum<?>>) configValueClass;
setupEnumMenuOption(enumConfigEntry, configEnumClass);
}
}
}
private static void setupEntryInfoTextField(AbstractConfigType info, Function<String, Number> func, Pattern pattern, boolean cast)
private static void setupTextMenuOption(AbstractConfigBase<?> configMenuOption, Function<String, Number> parsingFunc, @Nullable Pattern pattern, boolean cast)
{
((EntryInfo) info.guiValue).widget = (BiFunction<EditBox, Button, Predicate<String>>) (editBox, button) -> stringValue ->
((EntryInfo) configMenuOption.guiValue).widget = (BiFunction<EditBox, Button, Predicate<String>>)
(editBox, button) ->
(stringValue) ->
{
boolean isNumber = (pattern != null);
@@ -398,63 +333,128 @@ public class ClassicConfigGUI
}
Number value = info.typeIsFloatingPointNumber() ? 0.0 : 0; // different default values are needed so implicit casting works correctly (if not done casting from 0 (an int) to a double will cause an exception)
((EntryInfo) info.guiValue).error = null;
if (isNumber && !stringValue.isEmpty() && !stringValue.equals("-") && !stringValue.equals("."))
Number numberValue = configMenuOption.typeIsFloatingPointNumber() ? 0.0 : 0; // different default values are needed so implicit casting works correctly (if not done casting from 0 (an int) to a double will cause an exception)
((EntryInfo) configMenuOption.guiValue).error = null;
if (isNumber
&& !stringValue.isEmpty()
&& !stringValue.equals("-")
&& !stringValue.equals("."))
{
ConfigEntry<Number> numberConfigEntry = (ConfigEntry<Number>) configMenuOption;
try
{
value = func.apply(stringValue);
numberValue = parsingFunc.apply(stringValue);
}
catch (Exception e)
{
value = null;
numberValue = null;
}
byte isValid = ((ConfigEntry) info).isValid(value);
switch (isValid)
EConfigValidity validity = numberConfigEntry.getValidity(numberValue);
switch (validity)
{
case 0:
((EntryInfo) info.guiValue).error = null;
case VALID:
((EntryInfo) numberConfigEntry.guiValue).error = null;
break;
case -1:
((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMinimum length is " + ((ConfigEntry) info).getMin()));
case NUMBER_TOO_LOW:
((EntryInfo) numberConfigEntry.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMinimum length is " + ((ConfigEntry) configMenuOption).getMin()));
break;
case 1:
((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMaximum length is " + ((ConfigEntry) info).getMax()));
case NUMBER_TOO_HIGH:
((EntryInfo) numberConfigEntry.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cMaximum length is " + ((ConfigEntry) configMenuOption).getMax()));
break;
case 2:
((EntryInfo) info.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cValue is invalid"));
case INVALID:
((EntryInfo) numberConfigEntry.guiValue).error = new AbstractMap.SimpleEntry<>(editBox, TextOrTranslatable("§cValue is invalid"));
break;
}
}
((EntryInfo) info.guiValue).tempValue = stringValue;
editBox.setTextColor(((ConfigEntry) info).isValid(value) == 0 ? 0xFFFFFFFF : 0xFFFF7777); // white and red
((EntryInfo) configMenuOption.guiValue).tempValue = stringValue;
editBox.setTextColor(((ConfigEntry<Number>) configMenuOption).getValidity(numberValue) == EConfigValidity.VALID ? 0xFFFFFFFF : 0xFFFF7777); // white and red
if (info.getType() == String.class
|| info.getType() == List.class)
if (configMenuOption.getType() == String.class
|| configMenuOption.getType() == List.class)
{
((ConfigEntry) info).uiSetWithoutSaving(stringValue);
((ConfigEntry<String>) configMenuOption).uiSetWithoutSaving(stringValue);
}
else if (((ConfigEntry) info).isValid(value) == 0)
else if (((ConfigEntry<Number>) configMenuOption).getValidity(numberValue) == EConfigValidity.VALID)
{
if (!cast)
{
((ConfigEntry) info).uiSetWithoutSaving(value);
((ConfigEntry<Number>) configMenuOption).uiSetWithoutSaving(numberValue);
}
else
{
((ConfigEntry) info).uiSetWithoutSaving(value != null ? value.intValue() : 0);
((ConfigEntry<Number>) configMenuOption).uiSetWithoutSaving(numberValue != null ? numberValue.intValue() : 0);
}
}
return true;
};
}
private static void setupBooleanMenuOption(ConfigEntry<Boolean> booleanConfigEntry)
{
// For boolean
Function<Object, Component> func = value -> Translatable("distanthorizons.general."+((Boolean) value ? "true" : "false")).withStyle((Boolean) value ? ChatFormatting.GREEN : ChatFormatting.RED);
((EntryInfo) booleanConfigEntry.guiValue).widget =
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
(button) ->
{
button.active = !booleanConfigEntry.apiIsOverriding();
booleanConfigEntry.uiSetWithoutSaving(!booleanConfigEntry.get());
button.setMessage(func.apply(booleanConfigEntry.get()));
}, func);
}
private static void setupEnumMenuOption(ConfigEntry<Enum<?>> enumConfigEntry, Class<? extends Enum<?>> enumClass)
{
List<Enum<?>> enumList = Arrays.asList(enumClass.getEnumConstants());
Function<Object, Component> getEnumTranslatableFunc = (value) -> Translatable(TRANSLATION_PREFIX + "enum." + enumClass.getSimpleName() + "." + enumConfigEntry.get().toString());
((EntryInfo) enumConfigEntry.guiValue).widget =
new AbstractMap.SimpleEntry<Button.OnPress, Function<Object, Component>>(
(button) ->
{
// get the currently selected enum and enum index
int startingIndex = enumList.indexOf(enumConfigEntry.get());
Enum<?> enumValue = enumList.get(startingIndex);
// search for the next enum that is selectable
int index = startingIndex + 1;
index = (index >= enumList.size()) ? 0 : index;
while (index != startingIndex)
{
enumValue = enumList.get(index);
if (!AnnotationUtil.doesEnumHaveAnnotation(enumValue, DisallowSelectingViaConfigGui.class))
{
// this enum shouldn't be selectable via the UI,
// skip it
break;
}
index++;
index = (index >= enumList.size()) ? 0 : index;
}
if (index == startingIndex)
{
// none of the enums should be selectable, this is a programmer error
enumValue = enumList.get(startingIndex);
LOGGER.warn("Enum [" + enumValue.getClass() + "] doesn't contain any values that should be selectable via the UI, sticking to the currently selected value [" + enumValue + "].");
}
enumConfigEntry.uiSetWithoutSaving(enumValue);
button.active = !enumConfigEntry.apiIsOverriding();
button.setMessage(getEnumTranslatableFunc.apply(enumConfigEntry.get()));
}, getEnumTranslatableFunc);
}
private boolean tryCreateInputField(AbstractConfigType configType)
private boolean tryCreateInputField(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigEntry)
{
@@ -559,7 +559,7 @@ public class ClassicConfigGUI
return false;
}
private boolean tryCreateCategoryButton(AbstractConfigType configType)
private boolean tryCreateCategoryButton(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigCategory)
{
@@ -575,8 +575,8 @@ public class ClassicConfigGUI
ConfigScreenConfigs.CATEGORY_BUTTON_WIDTH, ConfigScreenConfigs.CATEGORY_BUTTON_HEIGHT,
((button) ->
{
ConfigBase.INSTANCE.configFileHandler.saveToFile();
Objects.requireNonNull(this.minecraft).setScreen(ClassicConfigGUI.getScreen(this.configBase, this, configCategory.getDestination()));
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
Objects.requireNonNull(this.minecraft).setScreen(ClassicConfigGUI.getScreen(this, configCategory.getDestination()));
}));
this.configListWidget.addButton(this, configType, widget, null, null, null);
@@ -585,7 +585,7 @@ public class ClassicConfigGUI
return false;
}
private boolean tryCreateButton(AbstractConfigType configType)
private boolean tryCreateButton(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigUIButton)
{
@@ -606,7 +606,7 @@ public class ClassicConfigGUI
return false;
}
private boolean tryCreateComment(AbstractConfigType configType)
private boolean tryCreateComment(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigUIComment)
{
@@ -625,7 +625,7 @@ public class ClassicConfigGUI
return false;
}
private boolean tryCreateSpacer(AbstractConfigType configType)
private boolean tryCreateSpacer(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigUISpacer)
{
@@ -642,7 +642,7 @@ public class ClassicConfigGUI
return false;
}
private boolean tryCreateLinkedEntry(AbstractConfigType configType)
private boolean tryCreateLinkedEntry(AbstractConfigBase<?> configType)
{
if (configType instanceof ConfigUiLinkedEntry)
{
@@ -654,8 +654,8 @@ public class ClassicConfigGUI
return false;
}
private Component GetTranslatableTextComponentForConfig(AbstractConfigType configType)
{ return Translatable(TRANSLATION_PREFIX + configType.getNameWCategory());}
private Component GetTranslatableTextComponentForConfig(AbstractConfigBase<?> configType)
{ return Translatable(TRANSLATION_PREFIX + configType.getNameAndCategory());}
@@ -734,7 +734,7 @@ public class ClassicConfigGUI
// A quick fix for tooltips on linked entries
AbstractConfigType dhConfigType = ConfigUiLinkedEntry.class.isAssignableFrom(button.dhConfigType.getClass()) ?
AbstractConfigBase dhConfigType = ConfigUiLinkedEntry.class.isAssignableFrom(button.dhConfigType.getClass()) ?
((ConfigUiLinkedEntry) button.dhConfigType).get() :
button.dhConfigType;
@@ -781,7 +781,7 @@ public class ClassicConfigGUI
@Override
public void onClose()
{
ConfigBase.INSTANCE.configFileHandler.saveToFile();
ConfigHandler.INSTANCE.configFileHandler.saveToFile();
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
CONFIG_CORE_INTERFACE.onScreenChangeListenerList.forEach((listener) -> listener.run());
@@ -812,7 +812,7 @@ public class ClassicConfigGUI
this.textRenderer = minecraftClient.font;
}
public void addButton(ConfigScreen gui, AbstractConfigType dhConfigType, AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text)
public void addButton(ConfigScreen gui, AbstractConfigBase dhConfigType, AbstractWidget button, AbstractWidget resetButton, AbstractWidget indexButton, Component text)
{ this.addEntry(new ButtonEntry(gui, dhConfigType, button, text, resetButton, indexButton)); }
@Override
@@ -858,7 +858,7 @@ public class ClassicConfigGUI
private final AbstractWidget button;
private final ConfigScreen gui;
private final AbstractConfigType dhConfigType;
private final AbstractConfigBase dhConfigType;
private final AbstractWidget resetButton;
private final AbstractWidget indexButton;
@@ -869,12 +869,12 @@ public class ClassicConfigGUI
private final EConfigCommentTextPosition textPosition;
public static final Map<AbstractWidget, Component> TEXT_BY_WIDGET = new HashMap<>();
// TODO we should just use a wrapper or something
/// TODO we should just use a wrapper or something
public static final Map<AbstractWidget, ButtonEntry> BUTTON_BY_WIDGET = new HashMap<>();
public ButtonEntry(ConfigScreen gui, AbstractConfigType dhConfigType,
public ButtonEntry(ConfigScreen gui, AbstractConfigBase dhConfigType,
AbstractWidget button, Component text, AbstractWidget resetButton, AbstractWidget indexButton)
{
TEXT_BY_WIDGET.put(button, text);
@@ -930,7 +930,7 @@ public class ClassicConfigGUI
{
#if MC_VER < MC_1_21_9
#else
int y = this.getY(); // TODO why is the Y value being set during render?
int y = this.getY(); /// TODO why is the Y value being set during render?
#endif
if (this.button != null)
@@ -1,14 +1,12 @@
package com.seibel.distanthorizons.common.wrappers.gui;
import com.seibel.distanthorizons.core.config.ConfigHandler;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.config.gui.JavaScreenHandlerScreen;
import net.minecraft.client.gui.screens.Screen;
import org.apache.logging.log4j.Logger;
import java.lang.invoke.MethodHandles;
public class GetConfigScreen
{
protected static final Logger LOGGER = DhLoggerBuilder.getLogger();
@@ -28,7 +26,7 @@ public class GetConfigScreen
// which won't be for sure added until we request a GUI
if (ModInfo.IS_DEV_BUILD)
{
String missingLangEntries = ConfigBase.INSTANCE.generateLang(true, true);
String missingLangEntries = ConfigHandler.INSTANCE.generateLang(true, true);
// trim to remove any newlines/spaces
// that may be present when no lang entries need changing
@@ -45,7 +43,7 @@ public class GetConfigScreen
switch (useScreen)
{
case Classic:
return ClassicConfigGUI.getScreen(ConfigBase.INSTANCE, parent, "client");
return ClassicConfigGUI.getScreen(parent, "client");
case JavaSwing:
//return MinecraftScreen.getScreen(parent, new JavaScreenHandlerScreen(new ConfigScreen()), ModInfo.ID + ".title");
return MinecraftScreen.getScreen(parent, new JavaScreenHandlerScreen(new JavaScreenHandlerScreen.ExampleScreen()), ModInfo.ID + ".title");
@@ -20,10 +20,8 @@
package com.seibel.distanthorizons.fabric;
import com.mojang.brigadier.CommandDispatcher;
import com.seibel.distanthorizons.api.enums.config.EDhApiMcRenderingFadeMode;
import com.seibel.distanthorizons.common.AbstractModInitializer;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.ConfigBase;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
@@ -156,11 +154,6 @@ public class FabricMain extends AbstractModInitializer implements ClientModIniti
ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class).setFogOcclusion(false);
}
#endif
if (ConfigBase.INSTANCE == null)
{
throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method.");
}
}
}