Skip to content

Commit

Permalink
sync from sakura-ryoko/malilib 1.21-0.21.5-sakura.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Dec 11, 2024
1 parent dc6ebd0 commit ad6ef5a
Show file tree
Hide file tree
Showing 65 changed files with 5,825 additions and 1,689 deletions.
31 changes: 24 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
## Change
- sync from `sakura-ryoko/malilib` 1.21-0.21.5-sakura.3
- fix Visibility of renderInventoryBackgroundSlots
- fix: Missing Textures from Horse Armor, etc
- fix: add support for other Generic Entity Types, such as Armor Stands using Inventory Overlay
- add printTranslationKeys Debug from Post Rewrite
- Adds Korean & Mod Menu 'Config Switcher' for MaLiLib config screens
- fix: when prettyName, comment, or translatedName entries are outdated, or not being applied with apply(), such as if the mod wasn't updated to use apply().
- sync from `sakura-ryoko/malilib` 1.21-0.21.5-sakura.4

details:

**Lots of changes, please read carefully, especially for Downstream mods.**

Merged a handful of useful utility functions from Post-Rewrite MaLiLib 1.12.2-ornithe including:

* BlockUtils (Deprecated things, and split between util/game/BlockUtils and util/nbt/NbtBlockUtils)
* util/game/BlockUtils has been also merged with Post-ReWrite.
* EntityUtils (Deprecated things, and moved most functions to util/nbt/NbtEntityUtils)
* NbtKeys (Deprecated, and moved to util/nbt/NbtKeys)
* Added FileNameUtils, and Merged FileUtils from Post-Rewrite.
* Added as a WIP JsonUtils from Post-ReWrite under util/data/json, which will have JSON Deserializers for every Config Type (Coming soon)
* Deprecated util/NBTUtils for a merged Post-ReWrite copy under util/nbt/NbtUtils with added functionality
* Deprecated PayloadUtils
* Added a handful of other items under util/data, util/game, util/nbt, and util/position from Post-ReWrite.
* Added Config Menu Registry from Post-Re-Write. Your Mods should Register with MaLiLib for each of your `GuiConfigBase` screens as follows using the new `ModInfo` class During your Mod Init():
```
Registry.CONFIG_SCREEN.registerConfigScreenFactory(
new ModInfo(MaLiLibReference.MOD_ID, MaLiLibReference.MOD_NAME, MaLiLibConfigGui::new)
);
```
MaFgLib will attempt to automatically Register any non-compliant Downstream mods; and this feature can be disabled using `enableConfigSwitcher` under MaFgLib's config menu.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mappings_patch="1.21+build.4"
neoforge="21.1.85"

# Mod properties
version="0.1.26"
version="0.2.1"
maven-group="org.thinkingstudio.mafglib"
archives-name="MaFgLib"

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fi/dy/masa/malilib/MaLiLib.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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 fi.dy.masa.malilib.event.InitializationHandler;
Expand All @@ -11,6 +13,8 @@ public class MaLiLib
public static void onInitialize()
{
InitializationHandler.getInstance().registerInitializationHandler(new MaLiLibInitHandler());
Registry.CONFIG_SCREEN.registerConfigScreenFactory(
new ModInfo(MaLiLibReference.MOD_ID, MaLiLibReference.MOD_NAME, MaLiLibConfigGui::new));
}

public static void debugLog(String key, Object... args)
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/fi/dy/masa/malilib/MaLiLibConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ public class MaLiLibConfigs implements IConfigHandler
private static final String GENERIC_KEY = MaLiLibReference.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 Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package fi.dy.masa.malilib.config.value;

import java.util.List;
import javax.annotation.Nullable;

import org.jetbrains.annotations.ApiStatus;

import fi.dy.masa.malilib.util.StringUtils;

/**
* Post-ReWrite code
*/
@ApiStatus.Experimental
public class BaseOptionListConfigValue implements OptionListConfigValue
{
protected final String name;
protected final String translationKey;

public BaseOptionListConfigValue(String name, String translationKey)
{
this.name = name;
this.translationKey = translationKey;
}

@Override
public String getName()
{
return this.name;
}

@Override
public String getDisplayName()
{
return StringUtils.translate(this.translationKey);
}

@Override
public String toString()
{
return this.name;
}

/**
* Finds the value by the given name from the provided list.
* If none of the entries match, then the first entry is returned as a fallback.
*/
public static <T extends OptionListConfigValue> T findValueByName(String name, List<T> values)
{
return findValueByName(name, values, values.get(0));
}

/**
* Finds the value by the given name from the provided list.
* If none of the entries match, then the fallback value is returned.
*/
public static <T extends OptionListConfigValue> T findValueByName(String name, List<T> values, @Nullable T fallback)
{
for (T val : values)
{
if (val.getName().equalsIgnoreCase(name))
{
return val;
}
}

return fallback;
}
}
21 changes: 21 additions & 0 deletions src/main/java/fi/dy/masa/malilib/config/value/FileWriteType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fi.dy.masa.malilib.config.value;

import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.ApiStatus;

/**
* Post-ReWrite code
*/
@ApiStatus.Experimental
public class FileWriteType extends BaseOptionListConfigValue
{
public static final FileWriteType NORMAL_WRITE = new FileWriteType("normal_write", "malilib.name.file_write_type.normal_write");
public static final FileWriteType TEMP_AND_RENAME = new FileWriteType("temp_and_rename", "malilib.name.file_write_type.temp_and_rename");

public static final ImmutableList<FileWriteType> VALUES = ImmutableList.of(NORMAL_WRITE, TEMP_AND_RENAME);

private FileWriteType(String name, String translationKey)
{
super(name, translationKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fi.dy.masa.malilib.config.value;

import org.jetbrains.annotations.ApiStatus;

/**
* Post-ReWrite code
*/
@ApiStatus.Experimental
public interface OptionListConfigValue
{
String getName();

String getDisplayName();
}
79 changes: 39 additions & 40 deletions src/main/java/fi/dy/masa/malilib/gui/GuiConfigsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
import fi.dy.masa.malilib.MaLiLibReference;
import fi.dy.masa.malilib.gui.widgets.WidgetDropDownList;

import net.minecraft.client.gui.screen.Screen;

import fi.dy.masa.malilib.MaLiLib;
import fi.dy.masa.malilib.MaLiLibConfigs;
import fi.dy.masa.malilib.config.ConfigManager;
import fi.dy.masa.malilib.config.IConfigBase;
import fi.dy.masa.malilib.config.gui.ButtonPressDirtyListenerSimple;
Expand All @@ -18,20 +20,17 @@
import fi.dy.masa.malilib.gui.interfaces.IDialogHandler;
import fi.dy.masa.malilib.gui.interfaces.IKeybindConfigGui;
import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption;
import fi.dy.masa.malilib.gui.widgets.WidgetDropDownList;
import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions;
import fi.dy.masa.malilib.registry.Registry;
import fi.dy.masa.malilib.util.GuiUtils;
import fi.dy.masa.malilib.util.KeyCodes;
import fi.dy.masa.malilib.util.StringUtils;
import org.thinkingstudio.mafglib.loader.FoxifiedLoader;
import org.thinkingstudio.mafglib.loader.entrypoints.EntrypointContainer;
import org.thinkingstudio.mafglib.loader.entrypoints.EntrypointHandler;
import org.thinkingstudio.mafglib.loader.gui.ModConfigScreenInitializer;
import org.thinkingstudio.mafglib.special.MaFgLibSpecial;
import org.thinkingstudio.mafglib.util.NeoUtils;
import fi.dy.masa.malilib.util.data.ModInfo;

public abstract class GuiConfigsBase extends GuiListBase<ConfigOptionWrapper, WidgetConfigOption, WidgetListConfigOptions> implements IKeybindConfigGui
{
protected WidgetDropDownList<EntrypointContainer<ModConfigScreenInitializer>> modSwitchWidget;
protected WidgetDropDownList<ModInfo> modSwitchWidget;
protected final List<Runnable> hotkeyChangeListeners = new ArrayList<>();
protected final ButtonPressDirtyListenerSimple dirtyListener = new ButtonPressDirtyListenerSimple();
protected final String modId;
Expand All @@ -52,46 +51,46 @@ public GuiConfigsBase(int listX, int listY, String modId, @Nullable Screen paren
public void initGui() {
super.initGui();

EntrypointHandler.loadAll();

var modContainer = FoxifiedLoader.getModContainers();

if (MaFgLibSpecial.getConfig().fastSwitchConfigGui.isTrue()) {
List<EntrypointContainer<ModConfigScreenInitializer>> entrypointContainers = FoxifiedLoader.getEntrypointContainers(MaLiLibReference.MODMENU_ID, ModConfigScreenInitializer.class)
// This will stack overflow if called in <init>()
.stream().filter(mod -> {
try {
return mod.getEntrypoint().getModConfigScreenFactory().createScreen(modContainer, null) instanceof GuiConfigsBase;
}
catch (Exception e)
{
return false;
}
}
)
.toList();
EntrypointContainer<ModConfigScreenInitializer> thisContainer = entrypointContainers.stream().filter(mod -> {
GuiConfigsBase gui = (GuiConfigsBase) mod.getEntrypoint().getModConfigScreenFactory().createScreen(modContainer, null);
if (gui == null) return false;
return gui.getClass() == this.getClass();
}).findFirst().orElse(null);
modSwitchWidget = new WidgetDropDownList<>(GuiUtils.getScaledWindowWidth() - 155, 13, 130, 18, 200, 10, entrypointContainers) {
ModInfo thisMod = Registry.CONFIG_SCREEN.getModInfoFromConfigScreen(this.getClass());

if (thisMod == null)
{
// Attempt to Register this screen.
try
{
MaLiLib.debugLog("GuiConfigsBase#initGui(): Attempting to register [{}] ...", this.getModId());
Registry.CONFIG_SCREEN.registerConfigScreenFactory(
new ModInfo(this.getModId(), StringUtils.splitCamelCase(this.getModId()), () -> this)
);
}
catch (Exception ignored)
{
MaLiLib.LOGGER.warn("GuiConfigsBase#initGui(): Failed to automatically register [{}]", this.getModId());
return;
}
}
if (thisMod != null && MaLiLibConfigs.Generic.ENABLE_CONFIG_SWITCHER.getBooleanValue())
{
modSwitchWidget = new WidgetDropDownList<>(GuiUtils.getScaledWindowWidth() - 155, 13, 130, 18, 200, 10, Registry.CONFIG_SCREEN.getAllModsWithConfigScreens())
{
{
selectedEntry = thisContainer;
selectedEntry = thisMod;
}

@Override
protected void setSelectedEntry(int index) {
protected void setSelectedEntry(int index)
{
super.setSelectedEntry(index);
if (selectedEntry != null) {
client.setScreen(selectedEntry.getEntrypoint().getModConfigScreenFactory().createScreen(modContainer, null));
if (selectedEntry != null && selectedEntry.getConfigScreenSupplier() != null)
{
client.setScreen(selectedEntry.getConfigScreenSupplier().get());
}
}

@Override
protected String getDisplayString(EntrypointContainer<ModConfigScreenInitializer> entry) {
if (entry == null) return "";
return NeoUtils.getModInfo(entry.getModFile()).getDisplayName();
protected String getDisplayString(ModInfo entry)
{
return entry.getModName();
}
};
addWidget(modSwitchWidget);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package fi.dy.masa.malilib.gui.config.registry;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;

import fi.dy.masa.malilib.gui.GuiBase;
import fi.dy.masa.malilib.util.data.ModInfo;

/**
* Post-ReWrite code
*/
public class ConfigScreenRegistry
{
protected final Map<String, ModInfo> modsMap = new HashMap<>();
protected ImmutableList<ModInfo> mods = ImmutableList.of();

public ConfigScreenRegistry()
{
}

public void registerConfigScreenFactory(ModInfo modInfo)
{
this.modsMap.put(modInfo.getModId(), modInfo);
ArrayList<ModInfo> list = new ArrayList<>(this.modsMap.values());
list.sort(Comparator.comparing(ModInfo::getModName));
this.mods = ImmutableList.copyOf(list);
}

@Nullable
public Supplier<GuiBase> getConfigScreenFactoryFor(ModInfo modInfo)
{
return this.modsMap.get(modInfo.getModId()).getConfigScreenSupplier();
}

public ImmutableList<ModInfo> getAllModsWithConfigScreens()
{
return this.mods;
}

public @Nullable ModInfo getModInfoFromConfigScreen(Class<? extends GuiBase> clazz)
{
return this.modsMap.values().stream()
.filter(mod -> mod.getConfigScreenSupplier() != null)
.filter(mod -> mod.getConfigScreenSupplier().get().getClass() == clazz)
.findFirst()
.orElse(null);
}
}
Empty file.
10 changes: 7 additions & 3 deletions src/main/java/fi/dy/masa/malilib/registry/Registry.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package fi.dy.masa.malilib.registry;

import org.apache.http.annotation.Experimental;

import fi.dy.masa.malilib.gui.config.registry.ConfigScreenRegistry;
import fi.dy.masa.malilib.interoperation.BlockPlacementPositionHandler;

/**
* Post-ReWrite code
*/
@Experimental
public class Registry
{
// Registries
//public static final ConfigTabRegistry CONFIG_TAB = new ConfigTabRegistryImpl();
//public static final ConfigTabExtensionRegistry CONFIG_TAB_EXTENSION = new ConfigTabExtensionRegistry();

// Event dispatchers and handlers
public static final BlockPlacementPositionHandler BLOCK_PLACEMENT_POSITION_HANDLER = new BlockPlacementPositionHandler();
public static final ConfigScreenRegistry CONFIG_SCREEN = new ConfigScreenRegistry();
}
Loading

0 comments on commit ad6ef5a

Please sign in to comment.