fix fabric tree injection issue

This commit is contained in:
dfsek
2021-07-15 14:45:26 -07:00
parent d94ddb3e76
commit 9d2ae0a828
6 changed files with 48 additions and 29 deletions

View File

@@ -48,6 +48,10 @@ public class ConfigurationLoadEvent implements PackEvent {
return type;
}
public boolean is(Class<?> clazz) {
return clazz.isAssignableFrom(type.getTypeClass());
}
@SuppressWarnings("unchecked")
public <T> T getLoadedObject(Class<T> clazz) {
if(!clazz.isAssignableFrom(type.getTypeClass()))

View File

@@ -9,14 +9,21 @@ public abstract class ConfigTypeLoadEvent implements PackEvent {
private final ConfigType<?, ?> type;
private final CheckedRegistry<?> registry;
public ConfigTypeLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry) {
private final ConfigPack pack;
public ConfigTypeLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
this.type = type;
this.registry = registry;
this.pack = pack;
}
@Override
public ConfigPack getPack() {
return null;
return pack;
}
public boolean is(Class<?> clazz) {
return clazz.isAssignableFrom(type.getTypeClass());
}
@SuppressWarnings("unchecked")

View File

@@ -1,10 +1,11 @@
package com.dfsek.terra.api.event.events.config.type;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.ConfigType;
import com.dfsek.terra.api.registry.CheckedRegistry;
public class ConfigTypePostLoadEvent extends ConfigTypeLoadEvent{
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry) {
super(type, registry);
public ConfigTypePostLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
super(type, registry, pack);
}
}

View File

@@ -1,10 +1,11 @@
package com.dfsek.terra.api.event.events.config.type;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.config.ConfigType;
import com.dfsek.terra.api.registry.CheckedRegistry;
public class ConfigTypePreLoadEvent extends ConfigTypeLoadEvent{
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry) {
super(type, registry);
public ConfigTypePreLoadEvent(ConfigType<?, ?> type, CheckedRegistry<?> registry, ConfigPack pack) {
super(type, registry, pack);
}
}

View File

@@ -246,7 +246,7 @@ public class ConfigPackImpl implements ConfigPack {
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) { // Load the configs
CheckedRegistry registry = getCheckedRegistry(configType.getTypeClass());
main.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry));
main.getEventManager().callEvent(new ConfigTypePreLoadEvent(configType, registry, this));
for(AbstractConfiguration config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()))) {
try {
Object loaded = ((ConfigFactory) configType.getFactory()).build(selfLoader.load(configType.getTemplate(this, main), config), main);
@@ -256,7 +256,7 @@ public class ConfigPackImpl implements ConfigPack {
throw new LoadException("Duplicate registry entry: ", e);
}
}
main.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry));
main.getEventManager().callEvent(new ConfigTypePostLoadEvent(configType, registry, this));
}
main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this, template -> selfLoader.load(template, configuration)));