mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 06:16:10 +00:00
create and register mutated structure config
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.addons.structure.mutator;
|
||||
|
||||
import com.dfsek.terra.addons.structure.mutator.config.MutatedStructureTemplate;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public class MutatedStructureConfigType implements ConfigType<MutatedStructureTemplate, MutatedStructure> {
|
||||
private final BaseAddon addon;
|
||||
|
||||
public MutatedStructureConfigType(BaseAddon addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutatedStructureTemplate getTemplate(ConfigPack pack, Platform platform) {
|
||||
return new MutatedStructureTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<MutatedStructureTemplate, MutatedStructure> getFactory() {
|
||||
return new MutatedStructureFactory(addon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<MutatedStructure> getTypeKey() {
|
||||
return TypeKey.of(MutatedStructure.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.addons.structure.mutator;
|
||||
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.addons.structure.mutator.config.MutatedStructureTemplate;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
|
||||
|
||||
public class MutatedStructureFactory implements ConfigFactory<MutatedStructureTemplate, MutatedStructure> {
|
||||
private final BaseAddon addon;
|
||||
|
||||
public MutatedStructureFactory(BaseAddon addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutatedStructure build(MutatedStructureTemplate config, Platform platform) throws LoadException {
|
||||
return new MutatedStructure(addon.key(config.getID()),
|
||||
config.getDelegate(),
|
||||
config.getReadInterceptor(),
|
||||
config.getWriteInterceptor());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.dfsek.terra.addons.structure.mutator;
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
|
||||
|
||||
@@ -16,6 +18,12 @@ public class StructureMutatorAddon implements AddonInitializer {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new MutatedStructureConfigType(addon), addon.key("MUTATED_STRUCTURE"), 499);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.dfsek.terra.addons.structure.mutator.config;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.world.util.ReadInterceptor;
|
||||
import com.dfsek.terra.api.world.util.WriteInterceptor;
|
||||
|
||||
|
||||
public class MutatedStructureTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("mutate.read")
|
||||
private ReadInterceptor readInterceptor;
|
||||
|
||||
@Value("mutate.write")
|
||||
private WriteInterceptor writeInterceptor;
|
||||
|
||||
@Value("structure")
|
||||
private Structure delegate;
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ReadInterceptor getReadInterceptor() {
|
||||
return readInterceptor;
|
||||
}
|
||||
|
||||
public WriteInterceptor getWriteInterceptor() {
|
||||
return writeInterceptor;
|
||||
}
|
||||
|
||||
public Structure getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user