mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 22:31:52 +00:00
create RegistrationEvent
This commit is contained in:
@@ -29,7 +29,7 @@ import com.dfsek.terra.api.world.chunk.generation.util.provider.GenerationStageP
|
|||||||
|
|
||||||
public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolder, StringIdentifiable {
|
public interface ConfigPack extends LoaderRegistrar, LoaderHolder, RegistryHolder, StringIdentifiable {
|
||||||
|
|
||||||
void registerConfigType(ConfigType<?, ?> type, String id, int priority);
|
ConfigPack registerConfigType(ConfigType<?, ?> type, String id, int priority);
|
||||||
|
|
||||||
Map<BaseAddon, VersionRange> addons();
|
Map<BaseAddon, VersionRange> addons();
|
||||||
|
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.dfsek.terra.api.event.events.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.config.ConfigType;
|
||||||
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
|
public class RegistrationEvent implements PackEvent {
|
||||||
|
private final ConfigPack pack;
|
||||||
|
|
||||||
|
public RegistrationEvent(ConfigPack pack) {
|
||||||
|
this.pack = pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigPack getPack() {
|
||||||
|
return pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistrationEvent registerConfigType(ConfigType<?, ?> type, String id, int priority) {
|
||||||
|
pack.registerConfigType(type, id, priority);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> RegistrationEvent applyLoader(Type type, Supplier<ObjectTemplate<T>> loader) {
|
||||||
|
pack.applyLoader(type, loader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> RegistrationEvent applyLoader(Type type, TypeLoader<T> loader) {
|
||||||
|
pack.applyLoader(type, loader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -31,6 +31,7 @@ import com.dfsek.tectonic.loading.TypeRegistry;
|
|||||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.event.events.config.RegistrationEvent;
|
||||||
import com.dfsek.terra.api.util.generic.Construct;
|
import com.dfsek.terra.api.util.generic.Construct;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -164,6 +165,8 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
register(abstractConfigLoader);
|
register(abstractConfigLoader);
|
||||||
platform.register(abstractConfigLoader);
|
platform.register(abstractConfigLoader);
|
||||||
|
|
||||||
|
platform.getEventManager().callEvent(new RegistrationEvent(this));
|
||||||
|
|
||||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||||
selfLoader.load(addonsTemplate, packManifest);
|
selfLoader.load(addonsTemplate, packManifest);
|
||||||
this.addons = addonsTemplate.getAddons();
|
this.addons = addonsTemplate.getAddons();
|
||||||
@@ -263,13 +266,14 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerConfigType(ConfigType<?, ?> type, String id, int priority) {
|
public ConfigPack registerConfigType(ConfigType<?, ?> type, String id, int priority) {
|
||||||
Set<String> contained = new HashSet<>();
|
Set<String> contained = new HashSet<>();
|
||||||
configTypes.forEach((p, configs) -> configs.forEach(pair -> {
|
configTypes.forEach((p, configs) -> configs.forEach(pair -> {
|
||||||
if(contained.contains(pair.getLeft())) throw new IllegalArgumentException("Duplicate config ID: " + id);
|
if(contained.contains(pair.getLeft())) throw new IllegalArgumentException("Duplicate config ID: " + id);
|
||||||
contained.add(id);
|
contained.add(id);
|
||||||
}));
|
}));
|
||||||
configTypes.computeIfAbsent(priority, p -> new ArrayList<>()).add(Pair.of(id, type));
|
configTypes.computeIfAbsent(priority, p -> new ArrayList<>()).add(Pair.of(id, type));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user