Skip to content

Commit

Permalink
Merge branch 'pre-rewrite/fabric/1.21.3' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
notlin4 authored Dec 21, 2024
2 parents 2a42d81 + 651ec77 commit 51e111f
Show file tree
Hide file tree
Showing 97 changed files with 9,591 additions and 1,733 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = malilib-fabric

# Current mod version
mod_version = 0.22.3
mod_version = 0.22.3-sakura.6

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21.3
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/fi/dy/masa/malilib/MaLiLib.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package fi.dy.masa.malilib;

import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.data.ModInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.fabricmc.api.ModInitializer;
import fi.dy.masa.malilib.event.InitializationHandler;

public class MaLiLib implements ModInitializer
{
public static final Logger logger = LogManager.getLogger(MaLiLibReference.MOD_ID);
public static final Logger LOGGER = LogManager.getLogger(MaLiLibReference.MOD_ID);

@Override
public void onInitialize()
{
public void onInitialize() {
InitializationHandler.getInstance().registerInitializationHandler(new MaLiLibInitHandler());
Registry.CONFIG_SCREEN.registerConfigScreenFactory(
new ModInfo(MaLiLibReference.MOD_ID, MaLiLibReference.MOD_NAME, MaLiLibConfigGui::new));
}

public static void printDebug(String key, Object... args)
public static void debugLog(String key, Object... args)
{
if (MaLiLibReference.DEBUG_MODE || MaLiLibConfigs.Debug.DEBUG_MESSAGES.getBooleanValue())
{
logger.info(key, args);
LOGGER.info(key, args);
}
}
}
21 changes: 17 additions & 4 deletions src/main/java/fi/dy/masa/malilib/MaLiLibConfigGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public void initGui()
}
}

if (!MaLiLibReference.EXPERIMENTAL_MODE)
{
if (tab == ConfigGuiTab.EXPERIMENTAL)
{
continue;
}
}

x += this.createButton(x, y, -1, tab) + 2;
}
}
Expand Down Expand Up @@ -91,6 +99,10 @@ else if (tab == ConfigGuiTab.TEST_ENUM && MaLiLibReference.DEBUG_MODE)
{
return ConfigOptionWrapper.createFor(TEST_ENUM_LIST.stream().map(this::wrapConfig).toList());
}
else if (tab == ConfigGuiTab.EXPERIMENTAL && MaLiLibReference.EXPERIMENTAL_MODE)
{
configs = MaLiLibConfigs.Experimental.OPTIONS;
}
else
{
return Collections.emptyList();
Expand Down Expand Up @@ -128,10 +140,11 @@ public void actionPerformedWithButton(ButtonBase button, int mouseButton)

public enum ConfigGuiTab
{
GENERIC ("malilib.gui.title.generic"),
DEBUG ("malilib.gui.title.debug"),
TEST ("malilib.gui.title.test"),
TEST_ENUM ("malilib.gui.title.test_enum");
GENERIC ("malilib.gui.title.generic"),
DEBUG ("malilib.gui.title.debug"),
TEST ("malilib.gui.title.test"),
TEST_ENUM ("malilib.gui.title.test_enum"),
EXPERIMENTAL ("malilib.gui.title.experimental");

private final String translationKey;

Expand Down
48 changes: 42 additions & 6 deletions src/main/java/fi/dy/masa/malilib/MaLiLibConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import fi.dy.masa.malilib.test.ConfigTestLockedList;
import fi.dy.masa.malilib.test.ConfigTestOptList;
import fi.dy.masa.malilib.test.TestEnumConfig;
import fi.dy.masa.malilib.util.Color4f;
import fi.dy.masa.malilib.util.FileUtils;
import fi.dy.masa.malilib.util.JsonUtils;
import fi.dy.masa.malilib.util.Color4f;

public class MaLiLibConfigs implements IConfigHandler
{
Expand All @@ -27,20 +27,24 @@ public class MaLiLibConfigs implements IConfigHandler
private static final String GENERIC_KEY = MaLiLibReference.MOD_ID+".config.generic";
public static class Generic
{
public static final ConfigHotkey IGNORED_KEYS = new ConfigHotkey("ignoredKeys", "").apply(GENERIC_KEY);
public static final ConfigHotkey OPEN_GUI_CONFIGS = new ConfigHotkey("openGuiConfigs", "A,C").apply(GENERIC_KEY);
public static final ConfigBoolean REALMS_COMMON_CONFIG = new ConfigBoolean("realmsCommonConfig", true).apply(GENERIC_KEY);
public static final ConfigBoolean ENABLE_ACTIONBAR_MESSAGES = new ConfigBoolean("enableActionbarMessages", true).apply(GENERIC_KEY);
public static final ConfigHotkey IGNORED_KEYS = new ConfigHotkey ("ignoredKeys", "").apply(GENERIC_KEY);
public static final ConfigHotkey OPEN_GUI_CONFIGS = new ConfigHotkey ("openGuiConfigs", "A,C").apply(GENERIC_KEY);
public static final ConfigBooleanHotkeyed ENABLE_CONFIG_SWITCHER = new ConfigBooleanHotkeyed ("enableConfigSwitcher", true, "").apply(GENERIC_KEY);
public static final ConfigBoolean REALMS_COMMON_CONFIG = new ConfigBoolean ("realmsCommonConfig", true).apply(GENERIC_KEY);
public static final ConfigBooleanHotkeyed ENABLE_ACTIONBAR_MESSAGES = new ConfigBooleanHotkeyed ("enableActionbarMessages", true, "").apply(GENERIC_KEY);

public static final ImmutableList<IConfigValue> OPTIONS = ImmutableList.of(
IGNORED_KEYS,
OPEN_GUI_CONFIGS,
ENABLE_CONFIG_SWITCHER,
REALMS_COMMON_CONFIG,
ENABLE_ACTIONBAR_MESSAGES
);

// Can't add OPEN_GUI_CONFIGS here, because things will break
public static final List<IHotkey> HOTKEY_LIST = ImmutableList.of(
ENABLE_CONFIG_SWITCHER,
ENABLE_ACTIONBAR_MESSAGES
);
}

Expand All @@ -53,14 +57,16 @@ public static class Debug
public static final ConfigBoolean KEYBIND_DEBUG = new ConfigBoolean("keybindDebugging", false).apply(DEBUG_KEY);
public static final ConfigBoolean KEYBIND_DEBUG_ACTIONBAR = new ConfigBoolean("keybindDebuggingIngame", false).apply(DEBUG_KEY);
public static final ConfigBoolean MOUSE_SCROLL_DEBUG = new ConfigBoolean("mouseScrollDebug", false).apply(DEBUG_KEY);
public static final ConfigBoolean PRINT_TRANSLATION_KEYS = new ConfigBoolean("printTranslationKeys", false).apply(DEBUG_KEY);

public static final ImmutableList<IConfigValue> OPTIONS = ImmutableList.of(
DEBUG_MESSAGES,
CONFIG_ELEMENT_DEBUG,
INPUT_CANCELLATION_DEBUG,
KEYBIND_DEBUG,
KEYBIND_DEBUG_ACTIONBAR,
MOUSE_SCROLL_DEBUG
MOUSE_SCROLL_DEBUG,
PRINT_TRANSLATION_KEYS
);

public static final List<IHotkey> HOTKEY_LIST = ImmutableList.of(
Expand Down Expand Up @@ -103,6 +109,26 @@ public static class Test
);
}

// Stuff used by any Post-Rewrite Code
private static final String EXPERIMENTAL_KEY = MaLiLibReference.MOD_ID+".config.experimental";
public static class Experimental
{
// Generic
public static final ConfigBoolean SORT_CONFIGS_BY_NAME = new ConfigBoolean("sortConfigsByName", false).apply(EXPERIMENTAL_KEY);
public static final ConfigBoolean SORT_EXTENSION_MOD_OPTIONS = new ConfigBoolean("sortExtensionModOptions", false).apply(EXPERIMENTAL_KEY);

// Internal
public static final ConfigString ACTIVE_CONFIG_PROFILE = new ConfigString("activeConfigProfile", "").apply(EXPERIMENTAL_KEY);

public static final ImmutableList<IConfigBase> OPTIONS = ImmutableList.of(
// Generic
SORT_CONFIGS_BY_NAME,
SORT_EXTENSION_MOD_OPTIONS,

// Internal
ACTIVE_CONFIG_PROFILE
);
}

public static void loadFromFile()
{
Expand All @@ -124,6 +150,11 @@ public static void loadFromFile()
ConfigUtils.readConfigBase(root, "Test", Test.OPTIONS);
ConfigUtils.readHotkeyToggleOptions(root, "TestEnumHotkeys", "TestEnumToggles", TestEnumConfig.VALUES);
}

if (MaLiLibReference.EXPERIMENTAL_MODE)
{
ConfigUtils.readConfigBase(root, "Experimental", Experimental.OPTIONS);
}
}
}
}
Expand All @@ -145,6 +176,11 @@ public static void saveToFile()
ConfigUtils.writeHotkeyToggleOptions(root, "TestEnumHotkeys", "TestEnumToggles", TestEnumConfig.VALUES);
}

if (MaLiLibReference.EXPERIMENTAL_MODE)
{
ConfigUtils.writeConfigBase(root, "Experimental", Experimental.OPTIONS);
}

JsonUtils.writeJsonToFile(root, new File(dir, CONFIG_FILE_NAME));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/dy/masa/malilib/MaLiLibReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MaLiLibReference
{
public static final String MOD_ID = "malilib";
public static final String MOD_NAME = "MaLiLib";
public static final String MODMENU_ID = "modmenu";
public static final String MOD_VERSION = StringUtils.getModVersionString(MOD_ID);
public static final boolean DEBUG_MODE = false;
public static final boolean EXPERIMENTAL_MODE = false;
}
5 changes: 2 additions & 3 deletions src/main/java/fi/dy/masa/malilib/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;

import fi.dy.masa.malilib.MaLiLib;

Expand Down Expand Up @@ -39,7 +38,7 @@ public void onConfigsChanged(String modId)
@ApiStatus.Internal
public void loadAllConfigs()
{
MaLiLib.printDebug("loadAllConfigs()");
MaLiLib.debugLog("loadAllConfigs()");
for (IConfigHandler handler : this.configHandlers.values())
{
handler.load();
Expand All @@ -49,7 +48,7 @@ public void loadAllConfigs()
@ApiStatus.Internal
public void saveAllConfigs()
{
MaLiLib.printDebug("saveAllConfigs()");
MaLiLib.debugLog("saveAllConfigs()");
for (IConfigHandler handler : this.configHandlers.values())
{
handler.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ConfigBase(ConfigType type, String name, String comment, String prettyNam

if (CONFIG_TYPE_DEBUG)
{
MaLiLib.logger.info("NEW CONFIG: [{}]", this.toString());
MaLiLib.LOGGER.info("NEW CONFIG: [{}]", this.toString());
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public T apply(String translationPrefix)
else
{
this.translationPrefix = "";
MaLiLib.logger.error("ConfigBase: Failed to apply Translations Prefix for config named [{}].", this.getName());
MaLiLib.LOGGER.error("ConfigBase: Failed to apply Translations Prefix for config named [{}].", this.getName());
}

this.printConfigElementDebug(this.type, "apply", "", this.translationPrefix);
Expand Down Expand Up @@ -220,7 +220,7 @@ protected void printConfigElementDebug(ConfigType type, String element, String o
{
if (CONFIG_TYPE_DEBUG || (MaLiLibConfigs.Debug.CONFIG_ELEMENT_DEBUG != null && MaLiLibConfigs.Debug.CONFIG_ELEMENT_DEBUG.getBooleanValue()))
{
MaLiLib.logger.info("CONFIG: type [{}], element [{}], oldStr [{}], newStr [{}]", type.name(), element, oldStr, newStr);
MaLiLib.LOGGER.info("CONFIG: type [{}], element [{}], oldStr [{}], newStr [{}]", type.name(), element, oldStr, newStr);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ public void setValueFromJsonElement(JsonElement element)
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void setValueFromJsonElement(JsonElement element)
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean isModified(String newValue)
{
return StringUtils.getColor(newValue, 0) != this.getDefaultIntegerValue();
}
catch (Exception e)
catch (Exception ignored)
{
}

Expand All @@ -108,12 +108,12 @@ public void setValueFromJsonElement(JsonElement element)
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public void setValueFromJsonElement(JsonElement element)
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
} catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void setValueFromString(String value)
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for {} from the string '{}'", this.getName(), value, e);
MaLiLib.LOGGER.warn("Failed to set config value for {} from the string '{}'", this.getName(), value, e);
}
}

Expand All @@ -197,12 +197,12 @@ public void setValueFromJsonElement(JsonElement element)
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void setValueFromString(String value)
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for {} from the string '{}'", this.getName(), value, e);
MaLiLib.LOGGER.warn("Failed to set config value for {} from the string '{}'", this.getName(), value, e);
}
}

Expand All @@ -194,12 +194,12 @@ public void setValueFromJsonElement(JsonElement element)
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ else if (element.isJsonPrimitive())
}
else
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element);
}
}
catch (Exception e)
{
MaLiLib.logger.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
MaLiLib.LOGGER.warn("Failed to set config value for '{}' from the JSON element '{}'", this.getName(), element, e);
}
}

Expand Down
Loading

0 comments on commit 51e111f

Please sign in to comment.