finish feature stage impl

This commit is contained in:
dfsek
2021-12-12 21:42:25 -07:00
parent c804947923
commit 56214bf03f
3 changed files with 35 additions and 22 deletions

View File

@@ -7,18 +7,19 @@
package com.dfsek.terra.addons.generation.feature;
import java.util.Collections;
import java.util.Random;
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
import com.dfsek.terra.api.Platform;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.util.Rotation;
import com.dfsek.terra.api.util.StringIdentifiable;
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.stage.GenerationStage;
import java.util.Random;
public class FeatureGenerationStage implements GenerationStage, StringIdentifiable {
private final Platform platform;
@@ -42,21 +43,30 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
int tx = cx + x;
int tz = cz + z;
ColumnImpl<ProtoWorld> column = new ColumnImpl<>(tx, tz, world);
world.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> {
try(ProfileFrame ignored = platform.getProfiler().profile(feature.getID())) {
if(feature.getDistributor().matches(tx, tz, seed)) {
feature.getLocator()
.getSuitableCoordinates(column)
.forEach(y ->
feature.getStructure(world, tx, y, tz)
.generate(new Vector3(tx, y, tz), world, new Random(
PopulationUtil.getCarverChunkSeed(world.centerChunkX(),
world.centerChunkZ(), seed)),
Rotation.NONE)
);
}
}
});
world.getBiomeProvider()
.getBiome(tx, tz, seed)
.getContext()
.get(BiomeFeatures.class)
.getFeatures()
.getOrDefault(id, Collections.emptyList())
.forEach(feature -> {
try(ProfileFrame ignored = platform.getProfiler().profile(feature.getID())) {
if(feature.getDistributor().matches(tx, tz, seed)) {
feature.getLocator()
.getSuitableCoordinates(column)
.forEach(y ->
feature.getStructure(world, tx, y, tz)
.generate(new Vector3(tx, y, tz),
world,
new Random(PopulationUtil.getCarverChunkSeed(
world.centerChunkX(),
world.centerChunkZ(),
seed)),
Rotation.NONE)
);
}
}
});
}
}
}

View File

@@ -8,19 +8,20 @@
package com.dfsek.terra.addons.generation.feature.config;
import java.util.List;
import java.util.Map;
import com.dfsek.terra.api.properties.Properties;
import com.dfsek.terra.api.structure.feature.Feature;
public class BiomeFeatures implements Properties {
private final List<Feature> features;
private final Map<String, List<Feature>> features;
public BiomeFeatures(List<Feature> features) {
public BiomeFeatures(Map<String, List<Feature>> features) {
this.features = features;
}
public List<Feature> getFeatures() {
public Map<String, List<Feature>> getFeatures() {
return features;
}
}

View File

@@ -13,6 +13,8 @@ import com.dfsek.tectonic.loading.object.ObjectTemplate;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Feature;
@@ -22,7 +24,7 @@ import com.dfsek.terra.api.structure.feature.Feature;
public class BiomeFeaturesTemplate implements ObjectTemplate<BiomeFeatures> {
@Value("features")
@Default
private @Meta List<@Meta Feature> features = Collections.emptyList();
private @Meta Map<@Meta String, @Meta List<@Meta Feature>> features = Collections.emptyMap();
@Override
public BiomeFeatures get() {