mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
dependencies {
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package com.dfsek.terra.addons.feature;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||||
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Feature;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Locator;
|
||||||
|
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
|
||||||
|
|
||||||
|
public class ConfiguredFeature implements Feature {
|
||||||
|
private final ProbabilityCollection<Structure> structures;
|
||||||
|
|
||||||
|
private final NoiseSampler structureSelector;
|
||||||
|
private final Distributor distributor;
|
||||||
|
private final Locator locator;
|
||||||
|
|
||||||
|
public ConfiguredFeature(ProbabilityCollection<Structure> structures, NoiseSampler structureSelector, Distributor distributor,
|
||||||
|
Locator locator) {
|
||||||
|
this.structures = structures;
|
||||||
|
this.structureSelector = structureSelector;
|
||||||
|
this.distributor = distributor;
|
||||||
|
this.locator = locator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Structure getStructure(World world, int x, int y, int z) {
|
||||||
|
return structures.get(structureSelector, x, y, z, world.getSeed());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distributor getDistributor() {
|
||||||
|
return distributor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Locator getLocator() {
|
||||||
|
return locator;
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package com.dfsek.terra.addons.feature;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
|
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||||
|
import com.dfsek.terra.api.addon.annotations.Author;
|
||||||
|
import com.dfsek.terra.api.addon.annotations.Version;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
@Addon("config-feature")
|
||||||
|
@Version("1.0.0")
|
||||||
|
@Author("Terra")
|
||||||
|
public class FeatureAddon extends TerraAddon {
|
||||||
|
@Inject
|
||||||
|
private Platform platform;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
platform.getEventManager()
|
||||||
|
.getHandler(FunctionalEventHandler.class)
|
||||||
|
.register(this, ConfigPackPreLoadEvent.class)
|
||||||
|
.then(event -> event.getPack().registerConfigType(new FeatureConfigType(), "FEATURE", 3))
|
||||||
|
.failThrough();
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package com.dfsek.terra.addons.feature;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
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.registry.OpenRegistry;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Feature;
|
||||||
|
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureConfigType implements ConfigType<FeatureTemplate, Feature> {
|
||||||
|
public static final TypeKey<Feature> FEATURE_TYPE_KEY = new TypeKey<>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
private final FeatureFactory factory = new FeatureFactory();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<OpenRegistry<Feature>> registrySupplier(ConfigPack pack) {
|
||||||
|
return pack.getRegistryFactory()::create;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureTemplate getTemplate(ConfigPack pack, Platform platform) {
|
||||||
|
return new FeatureTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigFactory<FeatureTemplate, Feature> getFactory() {
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypeKey<Feature> getTypeKey() {
|
||||||
|
return FEATURE_TYPE_KEY;
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.dfsek.terra.addons.feature;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.config.ConfigFactory;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Feature;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureFactory implements ConfigFactory<FeatureTemplate, Feature> {
|
||||||
|
@Override
|
||||||
|
public Feature build(FeatureTemplate config, Platform platform) throws LoadException {
|
||||||
|
return new ConfiguredFeature(config.getStructures(), config.getStructureNoise(), config.getDistributor(), config.getLocator());
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package com.dfsek.terra.addons.feature;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.annotations.Final;
|
||||||
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||||
|
import com.dfsek.terra.api.config.meta.Meta;
|
||||||
|
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||||
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||||
|
import com.dfsek.terra.api.structure.feature.Locator;
|
||||||
|
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureTemplate implements AbstractableTemplate {
|
||||||
|
@Value("id")
|
||||||
|
@Final
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Value("distributor")
|
||||||
|
private @Meta Distributor distributor;
|
||||||
|
|
||||||
|
@Value("locator")
|
||||||
|
private @Meta Locator locator;
|
||||||
|
|
||||||
|
@Value("structures.distribution")
|
||||||
|
private @Meta NoiseSampler structureNoise;
|
||||||
|
|
||||||
|
@Value("structures.structures")
|
||||||
|
private @Meta ProbabilityCollection<Structure> structures;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Distributor getDistributor() {
|
||||||
|
return distributor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Locator getLocator() {
|
||||||
|
return locator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoiseSampler getStructureNoise() {
|
||||||
|
return structureNoise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProbabilityCollection<Structure> getStructures() {
|
||||||
|
return structures;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user