mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
feature addon registry configuration
This commit is contained in:
parent
480bb84d9c
commit
c804947923
@ -23,12 +23,15 @@ public class ConfiguredFeature implements Feature {
|
|||||||
private final Distributor distributor;
|
private final Distributor distributor;
|
||||||
private final Locator locator;
|
private final Locator locator;
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
|
||||||
public ConfiguredFeature(ProbabilityCollection<Structure> structures, NoiseSampler structureSelector, Distributor distributor,
|
public ConfiguredFeature(ProbabilityCollection<Structure> structures, NoiseSampler structureSelector, Distributor distributor,
|
||||||
Locator locator) {
|
Locator locator, String id) {
|
||||||
this.structures = structures;
|
this.structures = structures;
|
||||||
this.structureSelector = structureSelector;
|
this.structureSelector = structureSelector;
|
||||||
this.distributor = distributor;
|
this.distributor = distributor;
|
||||||
this.locator = locator;
|
this.locator = locator;
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,4 +48,9 @@ public class ConfiguredFeature implements Feature {
|
|||||||
public Locator getLocator() {
|
public Locator getLocator() {
|
||||||
return locator;
|
return locator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import com.dfsek.terra.api.structure.feature.Feature;
|
|||||||
public class FeatureFactory implements ConfigFactory<FeatureTemplate, Feature> {
|
public class FeatureFactory implements ConfigFactory<FeatureTemplate, Feature> {
|
||||||
@Override
|
@Override
|
||||||
public Feature build(FeatureTemplate config, Platform platform) throws LoadException {
|
public Feature build(FeatureTemplate config, Platform platform) throws LoadException {
|
||||||
return new ConfiguredFeature(config.getStructures(), config.getStructureNoise(), config.getDistributor(), config.getLocator());
|
return new ConfiguredFeature(config.getStructures(), config.getStructureNoise(), config.getDistributor(), config.getLocator(),
|
||||||
|
config.getID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.generation.feature;
|
package com.dfsek.terra.addons.generation.feature;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
|
|
||||||
import com.dfsek.terra.addons.generation.feature.config.BiomeFeaturesTemplate;
|
import com.dfsek.terra.addons.generation.feature.config.BiomeFeaturesTemplate;
|
||||||
|
import com.dfsek.terra.addons.generation.feature.config.FeatureStageTemplate;
|
||||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.addon.BaseAddon;
|
import com.dfsek.terra.api.addon.BaseAddon;
|
||||||
@ -15,11 +18,14 @@ import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
|||||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||||
import com.dfsek.terra.api.inject.annotations.Inject;
|
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||||
|
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.provider.GenerationStageProvider;
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
public class FeatureGenerationAddon implements AddonInitializer {
|
public class FeatureGenerationAddon implements AddonInitializer {
|
||||||
|
public static final TypeKey<Supplier<ObjectTemplate<FeatureGenerationStage>>> STAGE_TYPE_KEY = new TypeKey<>() {};
|
||||||
@Inject
|
@Inject
|
||||||
private Platform platform;
|
private Platform platform;
|
||||||
|
|
||||||
@ -32,8 +38,8 @@ public class FeatureGenerationAddon implements AddonInitializer {
|
|||||||
.getHandler(FunctionalEventHandler.class)
|
.getHandler(FunctionalEventHandler.class)
|
||||||
.register(addon, ConfigPackPreLoadEvent.class)
|
.register(addon, ConfigPackPreLoadEvent.class)
|
||||||
.then(event -> event.getPack()
|
.then(event -> event.getPack()
|
||||||
.getOrCreateRegistry(GenerationStageProvider.class)
|
.getOrCreateRegistry(STAGE_TYPE_KEY)
|
||||||
.register("FEATURE", pack -> new FeatureGenerationStage(platform)))
|
.register("FEATURE", () -> new FeatureStageTemplate(platform)))
|
||||||
.failThrough();
|
.failThrough();
|
||||||
|
|
||||||
platform.getEventManager()
|
platform.getEventManager()
|
||||||
|
@ -12,6 +12,7 @@ import com.dfsek.terra.api.Platform;
|
|||||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||||
import com.dfsek.terra.api.util.Rotation;
|
import com.dfsek.terra.api.util.Rotation;
|
||||||
import com.dfsek.terra.api.util.PopulationUtil;
|
import com.dfsek.terra.api.util.PopulationUtil;
|
||||||
|
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||||
import com.dfsek.terra.api.util.vector.Vector3;
|
import com.dfsek.terra.api.util.vector.Vector3;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||||
@ -19,17 +20,20 @@ import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
public class FeatureGenerationStage implements GenerationStage {
|
public class FeatureGenerationStage implements GenerationStage, StringIdentifiable {
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
|
|
||||||
public FeatureGenerationStage(Platform platform) {
|
private final String id;
|
||||||
|
|
||||||
|
public FeatureGenerationStage(Platform platform, String id) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("try")
|
@SuppressWarnings("try")
|
||||||
public void populate(ProtoWorld world) {
|
public void populate(ProtoWorld world) {
|
||||||
try(ProfileFrame ignore = platform.getProfiler().profile("feature")) {
|
try(ProfileFrame ignore = platform.getProfiler().profile("feature_stage:" + id)) {
|
||||||
int cx = world.centerChunkX() << 4;
|
int cx = world.centerChunkX() << 4;
|
||||||
int cz = world.centerChunkZ() << 4;
|
int cz = world.centerChunkZ() << 4;
|
||||||
long seed = world.getSeed();
|
long seed = world.getSeed();
|
||||||
@ -39,18 +43,27 @@ public class FeatureGenerationStage implements GenerationStage {
|
|||||||
int tz = cz + z;
|
int tz = cz + z;
|
||||||
ColumnImpl<ProtoWorld> column = new ColumnImpl<>(tx, tz, world);
|
ColumnImpl<ProtoWorld> column = new ColumnImpl<>(tx, tz, world);
|
||||||
world.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> {
|
world.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> {
|
||||||
if(feature.getDistributor().matches(tx, tz, seed)) {
|
try(ProfileFrame ignored = platform.getProfiler().profile(feature.getID())) {
|
||||||
feature.getLocator()
|
if(feature.getDistributor().matches(tx, tz, seed)) {
|
||||||
.getSuitableCoordinates(column)
|
feature.getLocator()
|
||||||
.forEach(y ->
|
.getSuitableCoordinates(column)
|
||||||
feature.getStructure(world, tx, y, tz)
|
.forEach(y ->
|
||||||
.generate(new Vector3(tx, y, tz), world, new Random(PopulationUtil.getCarverChunkSeed(world.centerChunkX(), world.centerChunkZ(), seed)),
|
feature.getStructure(world, tx, y, tz)
|
||||||
Rotation.NONE)
|
.generate(new Vector3(tx, y, tz), world, new Random(
|
||||||
);
|
PopulationUtil.getCarverChunkSeed(world.centerChunkX(),
|
||||||
|
world.centerChunkZ(), seed)),
|
||||||
|
Rotation.NONE)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.dfsek.terra.addons.generation.feature.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.generation.feature.FeatureGenerationStage;
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
|
||||||
|
|
||||||
|
public class FeatureStageTemplate implements ObjectTemplate<FeatureGenerationStage> {
|
||||||
|
@Value("id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private final Platform platform;
|
||||||
|
|
||||||
|
public FeatureStageTemplate(Platform platform) { this.platform = platform; }
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeatureGenerationStage get() {
|
||||||
|
return new FeatureGenerationStage(platform, id);
|
||||||
|
}
|
||||||
|
}
|
@ -8,10 +8,11 @@
|
|||||||
package com.dfsek.terra.api.structure.feature;
|
package com.dfsek.terra.api.structure.feature;
|
||||||
|
|
||||||
import com.dfsek.terra.api.structure.Structure;
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
|
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||||
import com.dfsek.terra.api.world.WritableWorld;
|
import com.dfsek.terra.api.world.WritableWorld;
|
||||||
|
|
||||||
|
|
||||||
public interface Feature {
|
public interface Feature extends StringIdentifiable {
|
||||||
Structure getStructure(WritableWorld world, int x, int y, int z);
|
Structure getStructure(WritableWorld world, int x, int y, int z);
|
||||||
|
|
||||||
Distributor getDistributor();
|
Distributor getDistributor();
|
||||||
|
@ -118,12 +118,6 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
private final Map<Type, Pair<OpenRegistry<?>, CheckedRegistry<?>>> registryMap = new HashMap<>();
|
private final Map<Type, Pair<OpenRegistry<?>, CheckedRegistry<?>>> registryMap = new HashMap<>();
|
||||||
|
|
||||||
private final ConfigTypeRegistry configTypeRegistry;
|
private final ConfigTypeRegistry configTypeRegistry;
|
||||||
|
|
||||||
private final Lazy<List<GenerationStage>> stages = Lazy.lazy(() -> template
|
|
||||||
.getStages()
|
|
||||||
.stream()
|
|
||||||
.map(stage -> stage.newInstance(this))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
private final TreeMap<Integer, List<Pair<String, ConfigType<?, ?>>>> configTypes = new TreeMap<>();
|
private final TreeMap<Integer, List<Pair<String, ConfigType<?, ?>>>> configTypes = new TreeMap<>();
|
||||||
|
|
||||||
public ConfigPackImpl(File folder, Platform platform) throws ConfigException {
|
public ConfigPackImpl(File folder, Platform platform) throws ConfigException {
|
||||||
@ -352,7 +346,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GenerationStage> getStages() {
|
public List<GenerationStage> getStages() {
|
||||||
return stages.value();
|
return template.getStages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,6 +26,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.dfsek.terra.api.config.meta.Meta;
|
import com.dfsek.terra.api.config.meta.Meta;
|
||||||
|
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorProvider;
|
import com.dfsek.terra.api.world.chunk.generation.util.provider.ChunkGeneratorProvider;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.provider.GenerationStageProvider;
|
import com.dfsek.terra.api.world.chunk.generation.util.provider.GenerationStageProvider;
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
|||||||
private @Meta boolean disableSaplings = false;
|
private @Meta boolean disableSaplings = false;
|
||||||
|
|
||||||
@Value("stages")
|
@Value("stages")
|
||||||
private @Meta List<@Meta GenerationStageProvider> stages;
|
private @Meta List<@Meta GenerationStage> stages;
|
||||||
|
|
||||||
@Value("version")
|
@Value("version")
|
||||||
@Default
|
@Default
|
||||||
@ -149,7 +150,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
|||||||
return generatorProvider;
|
return generatorProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GenerationStageProvider> getStages() {
|
public List<GenerationStage> getStages() {
|
||||||
return stages;
|
return stages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user