mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
implement feature stage resolution
This commit is contained in:
parent
e5f0e64cf3
commit
c9221ca64c
@ -28,10 +28,13 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
|
|||||||
|
|
||||||
private final String profile;
|
private final String profile;
|
||||||
|
|
||||||
public FeatureGenerationStage(Platform platform, String id) {
|
private final int resolution;
|
||||||
|
|
||||||
|
public FeatureGenerationStage(Platform platform, String id, int resolution) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.profile = "feature_stage:" + id;
|
this.profile = "feature_stage:" + id;
|
||||||
|
this.resolution = resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -41,34 +44,40 @@ public class FeatureGenerationStage implements GenerationStage, StringIdentifiab
|
|||||||
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();
|
||||||
for(int x = 0; x < 16; x++) {
|
for(int chunkX = 0; chunkX < 16; chunkX += resolution) {
|
||||||
for(int z = 0; z < 16; z++) {
|
for(int chunkZ = 0; chunkZ < 16; chunkZ += resolution) {
|
||||||
int tx = cx + x;
|
int tx = cx + chunkX;
|
||||||
int tz = cz + z;
|
int tz = cz + chunkZ;
|
||||||
Column<WritableWorld> column = world.column(tx, tz);
|
|
||||||
long coordinateSeed = (seed * 31 + tx) * 31 + tz;
|
|
||||||
|
|
||||||
world.getBiomeProvider()
|
world.getBiomeProvider()
|
||||||
.getColumn(tx, tz, world)
|
.getColumn(tx, tz, world)
|
||||||
.forRanges((min, max, biome) ->
|
.forRanges((min, max, biome) -> {
|
||||||
|
for(int subChunkX = 0; subChunkX < resolution; subChunkX++) {
|
||||||
|
for(int subChunkZ = 0; subChunkZ < resolution; subChunkZ++) {
|
||||||
|
int x = subChunkX + tx;
|
||||||
|
int z = subChunkZ + tz;
|
||||||
|
long coordinateSeed = (seed * 31 + x) * 31 + z;
|
||||||
|
Column<WritableWorld> column = world.column(x, z);
|
||||||
biome.getContext()
|
biome.getContext()
|
||||||
.get(BiomeFeatures.class)
|
.get(BiomeFeatures.class)
|
||||||
.getFeatures()
|
.getFeatures()
|
||||||
.getOrDefault(this, Collections.emptyList())
|
.getOrDefault(this, Collections.emptyList())
|
||||||
.forEach(feature -> {
|
.forEach(feature -> {
|
||||||
platform.getProfiler().push(feature.getID());
|
platform.getProfiler().push(feature.getID());
|
||||||
if(feature.getDistributor().matches(tx, tz, seed)) {
|
if(feature.getDistributor().matches(x, z, seed)) {
|
||||||
feature.getLocator()
|
feature.getLocator()
|
||||||
.getSuitableCoordinates(column.clamp(min, max))
|
.getSuitableCoordinates(column.clamp(min, max))
|
||||||
.forEach(y -> feature.getStructure(world, tx, y, tz)
|
.forEach(y -> feature.getStructure(world, x, y, z)
|
||||||
.generate(Vector3Int.of(tx, y, tz),
|
.generate(Vector3Int.of(x, y, z),
|
||||||
world,
|
world,
|
||||||
new Random(coordinateSeed * 31 + y),
|
new Random(coordinateSeed * 31 + y),
|
||||||
Rotation.NONE)
|
Rotation.NONE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
platform.getProfiler().pop(feature.getID());
|
platform.getProfiler().pop(feature.getID());
|
||||||
}));
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
platform.getProfiler().pop(profile);
|
platform.getProfiler().pop(profile);
|
||||||
|
@ -1,23 +1,41 @@
|
|||||||
package com.dfsek.terra.addons.generation.feature.config;
|
package com.dfsek.terra.addons.generation.feature.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.api.config.template.ValidatedConfigTemplate;
|
||||||
|
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||||
|
import com.dfsek.tectonic.api.exception.ValidationException;
|
||||||
|
|
||||||
import com.dfsek.terra.addons.generation.feature.FeatureGenerationStage;
|
import com.dfsek.terra.addons.generation.feature.FeatureGenerationStage;
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||||
|
|
||||||
|
|
||||||
public class FeatureStageTemplate implements ObjectTemplate<GenerationStage> {
|
public class FeatureStageTemplate implements ObjectTemplate<GenerationStage>, ValidatedConfigTemplate {
|
||||||
private final Platform platform;
|
private final Platform platform;
|
||||||
@Value("id")
|
@Value("id")
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@Value("resolution")
|
||||||
|
@Default
|
||||||
|
private int resolution = 4;
|
||||||
|
|
||||||
public FeatureStageTemplate(Platform platform) { this.platform = platform; }
|
public FeatureStageTemplate(Platform platform) { this.platform = platform; }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FeatureGenerationStage get() {
|
public FeatureGenerationStage get() {
|
||||||
return new FeatureGenerationStage(platform, id);
|
return new FeatureGenerationStage(platform, id, resolution);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate() throws ValidationException {
|
||||||
|
if(!(resolution == 1
|
||||||
|
|| resolution == 2
|
||||||
|
|| resolution == 4
|
||||||
|
|| resolution == 8
|
||||||
|
|| resolution == 16)) throw new ValidationException(
|
||||||
|
"Resolution must be power of 2 less than or equal to 16 (1, 2, 4, 8, 16), got: " + resolution);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user