9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-25 18:09:17 +00:00

Add config post load & Fix

This commit is contained in:
Dreeam
2025-03-17 23:07:42 -04:00
parent 7d6a28c96e
commit e77896f346
6 changed files with 31 additions and 15 deletions

View File

@@ -42,6 +42,12 @@ public abstract class ConfigModules extends LeafConfig {
}
}
public static void loadAfterBootstrap() {
for (ConfigModules module : MODULES) {
module.onPostLoaded();
}
}
private static List<Field> getAnnotatedStaticFields(Class<?> clazz, Class<? extends Annotation> annotation) {
List<Field> fields = new ArrayList<>();
@@ -60,4 +66,7 @@ public abstract class ConfigModules extends LeafConfig {
}
public abstract void onLoaded();
public void onPostLoaded() {
}
}

View File

@@ -65,6 +65,7 @@ public class LeafConfig {
ConfigModules.clearModules();
loadConfig(false);
ConfigModules.loadAfterBootstrap();
final String success = String.format("Successfully reloaded config in %sms.", (System.nanoTime() - begin) / 1_000_000);
Command.broadcastCommandMessage(sender, Component.text(success, NamedTextColor.GREEN));

View File

@@ -23,6 +23,7 @@ public class HideItemComponent extends ConfigModules {
}
public static boolean enabled = false;
public static List<String> hiddenTypeStrings = new ArrayList<>();
public static List<DataComponentType<?>> hiddenTypes = List.of();
@Override
@@ -37,7 +38,7 @@ public class HideItemComponent extends ConfigModules {
可能会导致依赖物品组件的资源包/模组无法正常工作.
可以避免一些客户端动画效果.
注意: 此项与 Paper 的 item-obfuscation 不同, 我们只从玩家背包中隐藏物品指定的组件信息.""");
List<String> list = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
hiddenTypeStrings = config.getList(getBasePath() + ".hidden-types", new ArrayList<>(), config.pickStringRegionBased("""
Which type of components will be hidden from clients.
It needs a component type list, incorrect things will not work.""",
"""
@@ -47,10 +48,13 @@ public class HideItemComponent extends ConfigModules {
"If enabled, specified item component information from player's inventory will be hided.",
"启用后, 玩家背包内物品的指定组件信息会被隐藏."
));
}
final List<DataComponentType<?>> types = new ArrayList<>(list.size());
@Override
public void onPostLoaded() {
final List<DataComponentType<?>> types = new ArrayList<>(hiddenTypeStrings.size());
for (String componentType : list) {
for (String componentType : hiddenTypeStrings) {
BuiltInRegistries.DATA_COMPONENT_TYPE.get(ResourceLocation.parse(componentType)).ifPresentOrElse(
optional -> types.add(optional.value()),
() -> LeafConfig.LOGGER.warn("Unknown component type: {}", componentType)

View File

@@ -60,7 +60,10 @@ public class DynamicActivationofBrain extends ConfigModules {
"不会被 DAB 影响的实体列表"));
startDistanceSquared = startDistance * startDistance;
}
@Override
public void onPostLoaded() {
for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
entityType.dabEnabled = true; // reset all, before setting the ones to true
}