mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-20 23:30:29 +00:00
Reformat all code
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# Core Addons
|
||||
|
||||
This directory contains the modularized "core addons" that implement Terra's default behavior.
|
||||
This directory contains the modularized "core addons" that implement Terra's
|
||||
default behavior.
|
||||
@@ -1,8 +1,10 @@
|
||||
# api-features
|
||||
|
||||
Contains the API for feature generation.
|
||||
|
||||
This API implemented in:
|
||||
* `config-feature`
|
||||
* `generation-stage-feature`
|
||||
* `config-locators`
|
||||
* `config-distributors`
|
||||
|
||||
* `config-feature`
|
||||
* `generation-stage-feature`
|
||||
* `config-locators`
|
||||
* `config-distributors`
|
||||
@@ -1,6 +1,6 @@
|
||||
# biome-provider-image
|
||||
|
||||
Implements and registers the `IMAGE` biome provider, a biome provider which generates
|
||||
biomes from an image, using the `color` attribute of biomes.
|
||||
Implements and registers the `IMAGE` biome provider, a biome provider which
|
||||
generates biomes from an image, using the `color` attribute of biomes.
|
||||
|
||||
This addon registers the provider type, and all associated config options.
|
||||
@@ -1,57 +1,64 @@
|
||||
package com.dfsek.terra.addons.biome.image;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class ImageBiomeProvider implements BiomeProvider {
|
||||
private final Map<Color, TerraBiome> colorBiomeMap = new HashMap<>();
|
||||
private final BufferedImage image;
|
||||
private final int resolution;
|
||||
private final Align align;
|
||||
|
||||
|
||||
public ImageBiomeProvider(Set<TerraBiome> registry, BufferedImage image, int resolution, Align align) {
|
||||
this.image = image;
|
||||
this.resolution = resolution;
|
||||
this.align = align;
|
||||
registry.forEach(biome -> colorBiomeMap.put(new Color(biome.getColor()), biome));
|
||||
}
|
||||
|
||||
|
||||
private static int distance(Color a, Color b) {
|
||||
return FastMath.abs(a.getRed() - b.getRed()) + FastMath.abs(a.getGreen() - b.getGreen()) + FastMath.abs(a.getBlue() - b.getBlue());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(int x, int z, long seed) {
|
||||
x /= resolution;
|
||||
z /= resolution;
|
||||
Color color = align.getColor(image, x, z);
|
||||
return colorBiomeMap.get(colorBiomeMap.keySet().stream().reduce(colorBiomeMap.keySet().stream().findAny().orElseThrow(IllegalStateException::new), (running, element) -> {
|
||||
int d1 = distance(color, running);
|
||||
int d2 = distance(color, element);
|
||||
return d1 < d2 ? running : element;
|
||||
}));
|
||||
return colorBiomeMap.get(colorBiomeMap.keySet()
|
||||
.stream()
|
||||
.reduce(colorBiomeMap.keySet().stream().findAny().orElseThrow(IllegalStateException::new),
|
||||
(running, element) -> {
|
||||
int d1 = distance(color, running);
|
||||
int d2 = distance(color, element);
|
||||
return d1 < d2 ? running : element;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
public enum Align {
|
||||
CENTER {
|
||||
@Override
|
||||
public Color getColor(BufferedImage image, int x, int z) {
|
||||
return new Color(image.getRGB(FastMath.floorMod(x - image.getWidth() / 2, image.getWidth()), FastMath.floorMod(z - image.getHeight() / 2, image.getHeight())));
|
||||
return new Color(image.getRGB(FastMath.floorMod(x - image.getWidth() / 2, image.getWidth()),
|
||||
FastMath.floorMod(z - image.getHeight() / 2, image.getHeight())));
|
||||
}
|
||||
}, NONE {
|
||||
},
|
||||
NONE {
|
||||
@Override
|
||||
public Color getColor(BufferedImage image, int x, int z) {
|
||||
return new Color(image.getRGB(FastMath.floorMod(x, image.getWidth()), FastMath.floorMod(z, image.getHeight())));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract Color getColor(BufferedImage image, int x, int z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.image;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
@@ -14,26 +17,27 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Addon("biome-provider-image")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class ImageBiomeProviderAddon extends TerraAddon {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {};
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {
|
||||
};
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("IMAGE", () -> new ImageProviderTemplate(event.getPack().getRegistry(TerraBiome.class)));
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(
|
||||
PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("IMAGE", () -> new ImageProviderTemplate(event.getPack().getRegistry(TerraBiome.class)));
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,29 +3,29 @@ package com.dfsek.terra.addons.biome.image;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class ImageProviderTemplate implements ObjectTemplate<BiomeProvider> {
|
||||
private final Registry<TerraBiome> biomes;
|
||||
@Value("image.name")
|
||||
private BufferedImage image;
|
||||
|
||||
@Value("image.align")
|
||||
private ImageBiomeProvider.Align align;
|
||||
|
||||
@Value("resolution")
|
||||
@Default
|
||||
private int resolution = 1;
|
||||
|
||||
private final int resolution = 1;
|
||||
@Value("image.name")
|
||||
private BufferedImage image;
|
||||
@Value("image.align")
|
||||
private ImageBiomeProvider.Align align;
|
||||
|
||||
public ImageProviderTemplate(Registry<TerraBiome> set) {
|
||||
this.biomes = set;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeProvider get() {
|
||||
return new ImageBiomeProvider(new HashSet<>(biomes.entries()), image, resolution, align);
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
Implements the Biome Pipeline, a procedural biome provider that uses a series
|
||||
of "stages" to apply "mutations" to a 2D grid of biomes.
|
||||
|
||||
|
||||
This addon registers the `PIPELINE` biome provider type, and all associated configurations.
|
||||
This addon registers the `PIPELINE` biome provider type, and all associated
|
||||
configurations.
|
||||
@@ -3,16 +3,17 @@ package com.dfsek.terra.addons.biome.pipeline;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeExpander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
|
||||
public class BiomeHolderImpl implements BiomeHolder {
|
||||
private final Vector2 origin;
|
||||
private final int width;
|
||||
private final int offset;
|
||||
private TerraBiome[][] biomes;
|
||||
|
||||
|
||||
public BiomeHolderImpl(int width, Vector2 origin) {
|
||||
width += 4;
|
||||
this.width = width;
|
||||
@@ -20,35 +21,38 @@ public class BiomeHolderImpl implements BiomeHolder {
|
||||
this.origin = origin;
|
||||
this.offset = 2;
|
||||
}
|
||||
|
||||
|
||||
private BiomeHolderImpl(TerraBiome[][] biomes, Vector2 origin, int width, int offset) {
|
||||
this.biomes = biomes;
|
||||
this.origin = origin;
|
||||
this.width = width;
|
||||
this.offset = 2 * offset;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeHolder expand(BiomeExpander expander, long seed) {
|
||||
TerraBiome[][] old = biomes;
|
||||
int newWidth = width * 2 - 1;
|
||||
|
||||
|
||||
biomes = new TerraBiome[newWidth][newWidth];
|
||||
|
||||
|
||||
for(int x = 0; x < width; x++) {
|
||||
for(int z = 0; z < width; z++) {
|
||||
biomes[x * 2][z * 2] = old[x][z];
|
||||
if(z != width - 1)
|
||||
biomes[x * 2][z * 2 + 1] = expander.getBetween(x + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z], old[x][z + 1]);
|
||||
biomes[x * 2][z * 2 + 1] = expander.getBetween(x + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z],
|
||||
old[x][z + 1]);
|
||||
if(x != width - 1)
|
||||
biomes[x * 2 + 1][z * 2] = expander.getBetween(x + 1 + origin.getX(), z + origin.getZ(), seed, old[x][z], old[x + 1][z]);
|
||||
biomes[x * 2 + 1][z * 2] = expander.getBetween(x + 1 + origin.getX(), z + origin.getZ(), seed, old[x][z],
|
||||
old[x + 1][z]);
|
||||
if(x != width - 1 && z != width - 1)
|
||||
biomes[x * 2 + 1][z * 2 + 1] = expander.getBetween(x + 1 + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z], old[x + 1][z + 1], old[x][z + 1], old[x + 1][z]);
|
||||
biomes[x * 2 + 1][z * 2 + 1] = expander.getBetween(x + 1 + origin.getX(), z + 1 + origin.getZ(), seed, old[x][z],
|
||||
old[x + 1][z + 1], old[x][z + 1], old[x + 1][z]);
|
||||
}
|
||||
}
|
||||
return new BiomeHolderImpl(biomes, origin.setX(origin.getX() * 2 - 1).setZ(origin.getZ() * 2 - 1), newWidth, offset);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mutate(BiomeMutator mutator, long seed) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
@@ -58,7 +62,7 @@ public class BiomeHolderImpl implements BiomeHolder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fill(BiomeSource source, long seed) {
|
||||
for(int x = 0; x < width; x++) {
|
||||
@@ -67,14 +71,14 @@ public class BiomeHolderImpl implements BiomeHolder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
x += offset;
|
||||
z += offset;
|
||||
return getBiomeRaw(x, z);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiomeRaw(int x, int z) {
|
||||
if(x >= width || z >= width || x < 0 || z < 0) return null;
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
|
||||
|
||||
public class BiomePipeline {
|
||||
private final BiomeSource source;
|
||||
private final List<Stage> stages;
|
||||
private final int size;
|
||||
private final int init;
|
||||
|
||||
|
||||
private BiomePipeline(BiomeSource source, List<Stage> stages, int size, int init) {
|
||||
this.source = source;
|
||||
this.stages = stages;
|
||||
this.size = size;
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get biomes in a chunk
|
||||
*
|
||||
* @param x Chunk X coord
|
||||
* @param z Chunk Z coord
|
||||
*
|
||||
* @return BiomeHolder containing biomes.
|
||||
*/
|
||||
public BiomeHolder getBiomes(int x, int z, long seed) {
|
||||
@@ -34,29 +36,29 @@ public class BiomePipeline {
|
||||
for(Stage stage : stages) holder = stage.apply(holder, seed);
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
public static final class BiomePipelineBuilder {
|
||||
private final int init;
|
||||
List<Stage> stages = new ArrayList<>();
|
||||
private int expand;
|
||||
|
||||
|
||||
public BiomePipelineBuilder(int init) {
|
||||
this.init = init;
|
||||
expand = init;
|
||||
}
|
||||
|
||||
|
||||
public BiomePipeline build(BiomeSource source) {
|
||||
for(Stage stage : stages) {
|
||||
if(stage.isExpansion()) expand = expand * 2 - 1;
|
||||
}
|
||||
|
||||
|
||||
return new BiomePipeline(source, stages, expand, init);
|
||||
}
|
||||
|
||||
|
||||
public BiomePipelineBuilder addStage(Stage stage) {
|
||||
stages.add(stage);
|
||||
return this;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.BiomePipelineTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.BiomeProviderLoader;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.NoiseSourceTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.expander.ExpanderStageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.mutator.BorderListMutatorTemplate;
|
||||
@@ -11,6 +13,7 @@ import com.dfsek.terra.addons.biome.pipeline.config.stage.mutator.BorderMutatorT
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.mutator.ReplaceListMutatorTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.mutator.ReplaceMutatorTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.mutator.SmoothMutatorTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
@@ -22,44 +25,47 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Addon("biome-provider-pipeline")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class BiomePipelineAddon extends TerraAddon {
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeSource>>> SOURCE_REGISTRY_KEY = new TypeKey<>() {};
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<Stage>>> STAGE_REGISTRY_KEY = new TypeKey<>() {};
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {};
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeSource>>> SOURCE_REGISTRY_KEY = new TypeKey<>() {
|
||||
};
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<Stage>>> STAGE_REGISTRY_KEY = new TypeKey<>() {
|
||||
};
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {
|
||||
};
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("PIPELINE", () -> new BiomePipelineTemplate(main));
|
||||
})
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeSource>>> sourceRegistry = event.getPack().getOrCreateRegistry(SOURCE_REGISTRY_KEY);
|
||||
sourceRegistry.register("NOISE", NoiseSourceTemplate::new);
|
||||
})
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Stage>>> stageRegistry = event.getPack().getOrCreateRegistry(STAGE_REGISTRY_KEY);
|
||||
stageRegistry.register("FRACTAL_EXPAND", ExpanderStageTemplate::new);
|
||||
stageRegistry.register("SMOOTH", SmoothMutatorTemplate::new);
|
||||
stageRegistry.register("REPLACE", ReplaceMutatorTemplate::new);
|
||||
stageRegistry.register("REPLACE_LIST", ReplaceListMutatorTemplate::new);
|
||||
stageRegistry.register("BORDER", BorderMutatorTemplate::new);
|
||||
stageRegistry.register("BORDER_LIST", BorderListMutatorTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(
|
||||
PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("PIPELINE", () -> new BiomePipelineTemplate(main));
|
||||
})
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeSource>>> sourceRegistry = event.getPack().getOrCreateRegistry(
|
||||
SOURCE_REGISTRY_KEY);
|
||||
sourceRegistry.register("NOISE", NoiseSourceTemplate::new);
|
||||
})
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Stage>>> stageRegistry = event.getPack().getOrCreateRegistry(STAGE_REGISTRY_KEY);
|
||||
stageRegistry.register("FRACTAL_EXPAND", ExpanderStageTemplate::new);
|
||||
stageRegistry.register("SMOOTH", SmoothMutatorTemplate::new);
|
||||
stageRegistry.register("REPLACE", ReplaceMutatorTemplate::new);
|
||||
stageRegistry.register("REPLACE_LIST", ReplaceListMutatorTemplate::new);
|
||||
stageRegistry.register("BORDER", BorderMutatorTemplate::new);
|
||||
stageRegistry.register("BORDER_LIST", BorderListMutatorTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class BiomePipelineProvider implements BiomeProvider {
|
||||
private final LoadingCache<SeededVector, BiomeHolder> holderCache;
|
||||
@@ -17,50 +19,51 @@ public class BiomePipelineProvider implements BiomeProvider {
|
||||
private final int resolution;
|
||||
private final NoiseSampler mutator;
|
||||
private final double noiseAmp;
|
||||
|
||||
|
||||
public BiomePipelineProvider(BiomePipeline pipeline, TerraPlugin main, int resolution, NoiseSampler mutator, double noiseAmp) {
|
||||
this.resolution = resolution;
|
||||
this.mutator = mutator;
|
||||
this.noiseAmp = noiseAmp;
|
||||
holderCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(main == null ? 32 : main.getTerraConfig().getProviderCache())
|
||||
.build(
|
||||
new CacheLoader<SeededVector, BiomeHolder>() {
|
||||
@Override
|
||||
public BiomeHolder load(@NotNull SeededVector key) {
|
||||
return pipeline.getBiomes(key.x, key.z, key.seed);
|
||||
}
|
||||
}
|
||||
);
|
||||
.maximumSize(main == null ? 32 : main.getTerraConfig().getProviderCache())
|
||||
.build(
|
||||
new CacheLoader<SeededVector, BiomeHolder>() {
|
||||
@Override
|
||||
public BiomeHolder load(@NotNull SeededVector key) {
|
||||
return pipeline.getBiomes(key.x, key.z, key.seed);
|
||||
}
|
||||
}
|
||||
);
|
||||
this.pipeline = pipeline;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(int x, int z, long seed) {
|
||||
x += mutator.getNoiseSeeded(seed + 1, x, z) * noiseAmp;
|
||||
z += mutator.getNoiseSeeded(seed + 2, x, z) * noiseAmp;
|
||||
|
||||
|
||||
|
||||
|
||||
x = FastMath.floorToInt(FastMath.floorDiv(x, resolution));
|
||||
|
||||
|
||||
z = FastMath.floorToInt(FastMath.floorDiv(z, resolution));
|
||||
|
||||
|
||||
int fdX = FastMath.floorDiv(x, pipeline.getSize());
|
||||
int fdZ = FastMath.floorDiv(z, pipeline.getSize());
|
||||
return holderCache.getUnchecked(new SeededVector(fdX, fdZ, seed)).getBiome(x - fdX * pipeline.getSize(), z - fdZ * pipeline.getSize());
|
||||
return holderCache.getUnchecked(new SeededVector(fdX, fdZ, seed)).getBiome(x - fdX * pipeline.getSize(),
|
||||
z - fdZ * pipeline.getSize());
|
||||
}
|
||||
|
||||
|
||||
private static final class SeededVector {
|
||||
private final int x;
|
||||
private final int z;
|
||||
private final long seed;
|
||||
|
||||
|
||||
private SeededVector(int x, int z, long seed) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 0;
|
||||
@@ -69,12 +72,12 @@ public class BiomePipelineProvider implements BiomeProvider {
|
||||
result = 31 * result + z;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof SeededVector)) return false;
|
||||
SeededVector that = (SeededVector) obj;
|
||||
|
||||
|
||||
return this.seed == that.seed && this.x == that.x && this.z == that.z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.addons.biome.pipeline.api;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public interface BiomeExpander {
|
||||
TerraBiome getBetween(double x, double z, long seed, TerraBiome... others);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.api;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public interface BiomeHolder {
|
||||
BiomeHolder expand(BiomeExpander expander, long seed);
|
||||
|
||||
|
||||
void mutate(BiomeMutator mutator, long seed);
|
||||
|
||||
|
||||
void fill(BiomeSource source, long seed);
|
||||
|
||||
|
||||
TerraBiome getBiome(int x, int z);
|
||||
|
||||
|
||||
TerraBiome getBiomeRaw(int x, int z);
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@ package com.dfsek.terra.addons.biome.pipeline.api;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public interface BiomeMutator {
|
||||
TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed);
|
||||
|
||||
|
||||
class ViewPoint {
|
||||
private final BiomeHolder biomes;
|
||||
private final int offX;
|
||||
private final int offZ;
|
||||
|
||||
|
||||
public ViewPoint(BiomeHolder biomes, int offX, int offZ) {
|
||||
this.biomes = biomes;
|
||||
this.offX = offX;
|
||||
this.offZ = offZ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public TerraBiome getBiome(int x, int z) {
|
||||
return biomes.getBiomeRaw(x + offX, z + offZ);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.api;
|
||||
|
||||
public interface Stage {
|
||||
boolean isExpansion();
|
||||
|
||||
BiomeHolder apply(BiomeHolder in, long seed);
|
||||
|
||||
|
||||
boolean isExpansion();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,33 +2,35 @@ package com.dfsek.terra.addons.biome.pipeline.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.addons.biome.pipeline.BiomePipeline;
|
||||
import com.dfsek.terra.addons.biome.pipeline.BiomePipelineProvider;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
import com.dfsek.terra.addons.biome.pipeline.BiomePipeline;
|
||||
import com.dfsek.terra.addons.biome.pipeline.BiomePipelineProvider;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
public class BiomePipelineTemplate extends BiomeProviderTemplate {
|
||||
private final TerraPlugin main;
|
||||
@Value("pipeline.initial-size")
|
||||
@Default
|
||||
private @Meta int initialSize = 2;
|
||||
|
||||
|
||||
@Value("pipeline.stages")
|
||||
private @Meta List<@Meta Stage> stages;
|
||||
|
||||
|
||||
@Value("pipeline.source")
|
||||
private @Meta BiomeSource source;
|
||||
|
||||
|
||||
public BiomePipelineTemplate(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeProvider get() {
|
||||
BiomePipeline.BiomePipelineBuilder biomePipelineBuilder = new BiomePipeline.BiomePipelineBuilder(initialSize);
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.dfsek.terra.addons.biome.pipeline.config;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.BiomePipelineProvider;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
|
||||
public class BiomeProviderLoader implements TypeLoader<BiomeProvider> {
|
||||
@Override
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.dfsek.terra.addons.biome.pipeline.config;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public abstract class BiomeProviderTemplate implements ObjectTemplate<BiomeProvider> {
|
||||
@Value("resolution")
|
||||
@Default
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.NoiseSource;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
|
||||
public class NoiseSourceTemplate extends SourceTemplate {
|
||||
@Value("noise")
|
||||
private @Meta NoiseSampler noise;
|
||||
|
||||
|
||||
@Value("biomes")
|
||||
private @Meta ProbabilityCollection<@Meta TerraBiome> biomes;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeSource get() {
|
||||
return new NoiseSource(biomes, noise);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.source.BiomeSource;
|
||||
|
||||
public abstract class SourceTemplate implements ObjectTemplate<BiomeSource>{
|
||||
|
||||
public abstract class SourceTemplate implements ObjectTemplate<BiomeSource> {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package com.dfsek.terra.addons.biome.pipeline.config.stage;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.stages.MutatorStage;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public abstract class StageTemplate implements ObjectTemplate<Stage> {
|
||||
@Value("noise")
|
||||
protected @Meta NoiseSampler noise;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.expand.FractalExpander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.stages.ExpanderStage;
|
||||
|
||||
|
||||
public class ExpanderStageTemplate extends StageTemplate {
|
||||
@Override
|
||||
public Stage get() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.mutator.BorderListMutator;
|
||||
@@ -9,23 +12,22 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BorderListMutatorTemplate extends StageTemplate {
|
||||
@Value("from")
|
||||
private @Meta String from;
|
||||
|
||||
|
||||
@Value("default-replace")
|
||||
private @Meta String defaultReplace;
|
||||
|
||||
|
||||
@Value("default-to")
|
||||
private @Meta ProbabilityCollection<@Meta TerraBiome> defaultTo;
|
||||
|
||||
|
||||
@Value("replace")
|
||||
private @Meta Map<@Meta TerraBiome, @Meta ProbabilityCollection<@Meta TerraBiome>> replace;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Stage get() {
|
||||
return new MutatorStage(new BorderListMutator(replace, from, defaultReplace, noise, defaultTo));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.mutator.BorderMutator;
|
||||
@@ -10,17 +10,18 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class BorderMutatorTemplate extends StageTemplate {
|
||||
@Value("from")
|
||||
private @Meta String from;
|
||||
|
||||
|
||||
@Value("replace")
|
||||
private @Meta String replace;
|
||||
|
||||
|
||||
@Value("to")
|
||||
private @Meta ProbabilityCollection<@Meta TerraBiome> to;
|
||||
|
||||
|
||||
@Override
|
||||
public Stage get() {
|
||||
return new MutatorStage(new BorderMutator(from, replace, noise, to));
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.mutator.ReplaceListMutator;
|
||||
@@ -10,19 +12,18 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ReplaceListMutatorTemplate extends StageTemplate {
|
||||
@Value("default-from")
|
||||
private @Meta String defaultFrom;
|
||||
|
||||
|
||||
@Value("default-to")
|
||||
private @Meta ProbabilityCollection<@Meta TerraBiome> defaultTo;
|
||||
|
||||
|
||||
@Value("to")
|
||||
private @Meta Map<@Meta TerraBiome, @Meta ProbabilityCollection<@Meta TerraBiome>> replace;
|
||||
|
||||
|
||||
@Override
|
||||
public Stage get() {
|
||||
return new MutatorStage(new ReplaceListMutator(replace, defaultFrom, defaultTo, noise));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config.stage.mutator;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.mutator.ReplaceMutator;
|
||||
@@ -10,14 +10,15 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ReplaceMutatorTemplate extends StageTemplate {
|
||||
@Value("from")
|
||||
private @Meta String from;
|
||||
|
||||
|
||||
@Value("to")
|
||||
private @Meta ProbabilityCollection<@Meta TerraBiome> to;
|
||||
|
||||
|
||||
@Override
|
||||
public Stage get() {
|
||||
return new MutatorStage(new ReplaceMutator(from, to, noise));
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.config.stage.mutator;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
import com.dfsek.terra.addons.biome.pipeline.config.stage.StageTemplate;
|
||||
import com.dfsek.terra.addons.biome.pipeline.mutator.SmoothMutator;
|
||||
import com.dfsek.terra.addons.biome.pipeline.stages.MutatorStage;
|
||||
|
||||
|
||||
public class SmoothMutatorTemplate extends StageTemplate {
|
||||
@Override
|
||||
public Stage get() {
|
||||
|
||||
@@ -5,13 +5,14 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class FractalExpander implements BiomeExpander {
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
public FractalExpander(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBetween(double x, double z, long seed, TerraBiome... others) {
|
||||
return others[MathUtil.normalizeIndex(sampler.getNoiseSeeded(seed, x, z), others.length)];
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.mutator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BorderListMutator implements BiomeMutator {
|
||||
private final String border;
|
||||
@@ -13,15 +14,16 @@ public class BorderListMutator implements BiomeMutator {
|
||||
private final ProbabilityCollection<TerraBiome> replaceDefault;
|
||||
private final String defaultReplace;
|
||||
private final Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace;
|
||||
|
||||
public BorderListMutator(Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace, String border, String defaultReplace, NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replaceDefault) {
|
||||
|
||||
public BorderListMutator(Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace, String border, String defaultReplace,
|
||||
NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replaceDefault) {
|
||||
this.border = border;
|
||||
this.noiseSampler = noiseSampler;
|
||||
this.replaceDefault = replaceDefault;
|
||||
this.defaultReplace = defaultReplace;
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed) {
|
||||
TerraBiome origin = viewPoint.getBiome(0, 0);
|
||||
|
||||
@@ -5,19 +5,20 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class BorderMutator implements BiomeMutator {
|
||||
private final String border;
|
||||
private final NoiseSampler noiseSampler;
|
||||
private final ProbabilityCollection<TerraBiome> replace;
|
||||
private final String replaceTag;
|
||||
|
||||
|
||||
public BorderMutator(String border, String replaceTag, NoiseSampler noiseSampler, ProbabilityCollection<TerraBiome> replace) {
|
||||
this.border = border;
|
||||
this.noiseSampler = noiseSampler;
|
||||
this.replace = replace;
|
||||
this.replaceTag = replaceTag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed) {
|
||||
TerraBiome origin = viewPoint.getBiome(0, 0);
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.mutator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ReplaceListMutator implements BiomeMutator {
|
||||
private final Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace;
|
||||
private final NoiseSampler sampler;
|
||||
private final ProbabilityCollection<TerraBiome> replaceDefault;
|
||||
private final String defaultTag;
|
||||
|
||||
public ReplaceListMutator(Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace, String defaultTag, ProbabilityCollection<TerraBiome> replaceDefault, NoiseSampler sampler) {
|
||||
|
||||
public ReplaceListMutator(Map<TerraBiome, ProbabilityCollection<TerraBiome>> replace, String defaultTag,
|
||||
ProbabilityCollection<TerraBiome> replaceDefault, NoiseSampler sampler) {
|
||||
this.replace = replace;
|
||||
this.sampler = sampler;
|
||||
this.defaultTag = defaultTag;
|
||||
this.replaceDefault = replaceDefault;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed) {
|
||||
TerraBiome center = viewPoint.getBiome(0, 0);
|
||||
|
||||
@@ -5,17 +5,18 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class ReplaceMutator implements BiomeMutator {
|
||||
private final String replaceableTag;
|
||||
private final ProbabilityCollection<TerraBiome> replace;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
public ReplaceMutator(String replaceable, ProbabilityCollection<TerraBiome> replace, NoiseSampler sampler) {
|
||||
this.replaceableTag = replaceable;
|
||||
this.replace = replace;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed) {
|
||||
if(viewPoint.getBiome(0, 0).getTags().contains(replaceableTag)) {
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.mutator;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SmoothMutator implements BiomeMutator {
|
||||
|
||||
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
public SmoothMutator(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome mutate(ViewPoint viewPoint, double x, double z, long seed) {
|
||||
TerraBiome top = viewPoint.getBiome(1, 0);
|
||||
TerraBiome bottom = viewPoint.getBiome(-1, 0);
|
||||
TerraBiome left = viewPoint.getBiome(0, 1);
|
||||
TerraBiome right = viewPoint.getBiome(0, -1);
|
||||
|
||||
|
||||
|
||||
|
||||
boolean vert = Objects.equals(top, bottom) && top != null;
|
||||
boolean horiz = Objects.equals(left, right) && left != null;
|
||||
|
||||
|
||||
if(vert && horiz) {
|
||||
return MathUtil.normalizeIndex(sampler.getNoiseSeeded(seed, x, z), 2) == 0 ? left : top;
|
||||
}
|
||||
|
||||
|
||||
if(vert) return top;
|
||||
if(horiz) return left;
|
||||
|
||||
|
||||
return viewPoint.getBiome(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.addons.biome.pipeline.source;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public interface BiomeSource {
|
||||
TerraBiome getBiome(double x, double z, long seed);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class NoiseSource implements BiomeSource {
|
||||
private final ProbabilityCollection<TerraBiome> biomes;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
public NoiseSource(ProbabilityCollection<TerraBiome> biomes, NoiseSampler sampler) {
|
||||
this.biomes = biomes;
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(double x, double z, long seed) {
|
||||
return biomes.get(sampler, x, z, seed);
|
||||
|
||||
@@ -4,23 +4,24 @@ import com.dfsek.terra.addons.biome.pipeline.api.BiomeExpander;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
|
||||
|
||||
public class ExpanderStage implements Stage {
|
||||
private final BiomeExpander expander;
|
||||
|
||||
|
||||
public ExpanderStage(BiomeExpander expander) {
|
||||
this.expander = expander;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in, long seed) {
|
||||
return in.expand(expander, seed);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
FRACTAL
|
||||
}
|
||||
|
||||
@@ -4,25 +4,30 @@ import com.dfsek.terra.addons.biome.pipeline.api.BiomeHolder;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.BiomeMutator;
|
||||
import com.dfsek.terra.addons.biome.pipeline.api.Stage;
|
||||
|
||||
|
||||
public class MutatorStage implements Stage {
|
||||
private final BiomeMutator mutator;
|
||||
|
||||
|
||||
public MutatorStage(BiomeMutator mutator) {
|
||||
this.mutator = mutator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeHolder apply(BiomeHolder in, long seed) {
|
||||
in.mutate(mutator, seed);
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isExpansion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
REPLACE, REPLACE_LIST, BORDER, BORDER_LIST, SMOOTH
|
||||
REPLACE,
|
||||
REPLACE_LIST,
|
||||
BORDER,
|
||||
BORDER_LIST,
|
||||
SMOOTH
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@ package com.dfsek.terra.addons.biome.single;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class SingleBiomeProvider implements BiomeProvider {
|
||||
private final TerraBiome biome;
|
||||
|
||||
|
||||
public SingleBiomeProvider(TerraBiome biome) {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome getBiome(int x, int z, long seed) {
|
||||
return biome;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.single;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
@@ -13,26 +16,27 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Addon("biome-provider-single")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class SingleBiomeProviderAddon extends TerraAddon {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {};
|
||||
|
||||
public static final TypeKey<Supplier<ObjectTemplate<BiomeProvider>>> PROVIDER_REGISTRY_KEY = new TypeKey<>() {
|
||||
};
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("SINGLE", SingleBiomeProviderTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<BiomeProvider>>> providerRegistry = event.getPack().getOrCreateRegistry(
|
||||
PROVIDER_REGISTRY_KEY);
|
||||
providerRegistry.register("SINGLE", SingleBiomeProviderTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ package com.dfsek.terra.addons.biome.single;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class SingleBiomeProviderTemplate implements ObjectTemplate<BiomeProvider> {
|
||||
@Value("biome")
|
||||
private @Meta TerraBiome biome;
|
||||
|
||||
|
||||
@Override
|
||||
public BiomeProvider get() {
|
||||
return new SingleBiomeProvider(biome);
|
||||
|
||||
@@ -3,26 +3,26 @@ package com.dfsek.terra.addons.chunkgenerator;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteInfo;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.SlantHolder;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
public class BiomePaletteTemplate implements ObjectTemplate<PaletteInfo> {
|
||||
@Value("palette")
|
||||
private @Meta PaletteHolder palette;
|
||||
|
||||
public class BiomePaletteTemplate implements ObjectTemplate<PaletteInfo> {
|
||||
@Value("slant")
|
||||
@Default
|
||||
private @Meta SlantHolder slant = null;
|
||||
|
||||
private final @Meta SlantHolder slant;
|
||||
@Value("palette")
|
||||
private @Meta PaletteHolder palette;
|
||||
@Value("ocean.level")
|
||||
private @Meta int seaLevel;
|
||||
|
||||
|
||||
@Value("ocean.palette")
|
||||
private @Meta Palette oceanPalette;
|
||||
|
||||
|
||||
@Override
|
||||
public PaletteInfo get() {
|
||||
return new PaletteInfo(palette, slant, oceanPalette, seaLevel);
|
||||
|
||||
@@ -17,34 +17,36 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGeneratorProvider;
|
||||
|
||||
|
||||
@Addon("chunk-generator-noise-3d")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class NoiseChunkGenerator3DAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D", pack -> new NoiseChunkGenerator3D(pack, main));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.class, new SlantHolderLoader())
|
||||
.applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D",
|
||||
pack -> new NoiseChunkGenerator3D(pack, main));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.class, new SlantHolderLoader())
|
||||
.applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(TerraBiome.class)) {
|
||||
event.getLoadedObject(TerraBiome.class).getContext().put(event.load(new BiomePaletteTemplate()).get());
|
||||
}
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigurationLoadEvent.class)
|
||||
.then(event -> {
|
||||
if(event.is(TerraBiome.class)) {
|
||||
event.getLoadedObject(TerraBiome.class).getContext().put(event.load(new BiomePaletteTemplate()).get());
|
||||
}
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import com.dfsek.terra.api.world.generator.Sampler;
|
||||
|
||||
|
||||
public final class PaletteUtil {
|
||||
public static Palette getPalette(int x, int y, int z, GenerationSettings c, Sampler sampler, PaletteInfo paletteInfo) {
|
||||
SlantHolder slant = paletteInfo.getSlantHolder();
|
||||
@@ -16,7 +17,7 @@ public final class PaletteUtil {
|
||||
return slant.getPalette(slope).getPalette(y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return paletteInfo.getPaletteHolder().getPalette(y);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.generators;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.PaletteUtil;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.samplers.Sampler3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteInfo;
|
||||
@@ -16,32 +23,27 @@ import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import com.dfsek.terra.api.world.generator.Sampler;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.generator.GenerationStage;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import com.dfsek.terra.api.world.generator.Sampler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private final ConfigPack configPack;
|
||||
private final TerraPlugin main;
|
||||
private final List<GenerationStage> generationStages = new ArrayList<>();
|
||||
|
||||
|
||||
private final BlockState air;
|
||||
|
||||
|
||||
public NoiseChunkGenerator3D(ConfigPack c, TerraPlugin main) {
|
||||
this.configPack = c;
|
||||
this.main = main;
|
||||
this.air = main.getWorldHandle().air();
|
||||
c.getStages().forEach(stage -> generationStages.add(stage.newInstance(c)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"try"})
|
||||
|
||||
@SuppressWarnings("try")
|
||||
static void biomes(@NotNull World world, int chunkX, int chunkZ, @NotNull BiomeGrid biome, TerraPlugin main) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("biomes")) {
|
||||
int xOrig = (chunkX << 4);
|
||||
@@ -53,73 +55,64 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
int cx = xOrig + (x << 2);
|
||||
int cz = zOrig + (z << 2);
|
||||
TerraBiome b = grid.getBiome(cx, cz, seed);
|
||||
|
||||
|
||||
biome.setBiome(cx, cz, b.getVanillaBiomes().get(b.getGenerator().getBiomeNoise(), cx, 0, cz, world.getSeed()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getConfigPack() {
|
||||
return configPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraPlugin getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"try"})
|
||||
@SuppressWarnings("try")
|
||||
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) {
|
||||
BiomeProvider grid = world.getBiomeProvider();
|
||||
|
||||
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(chunkX, chunkZ);
|
||||
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
int paletteLevel = 0;
|
||||
|
||||
|
||||
int cx = xOrig + x;
|
||||
int cz = zOrig + z;
|
||||
|
||||
|
||||
TerraBiome biome = grid.getBiome(cx, cz, seed);
|
||||
|
||||
|
||||
PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class);
|
||||
|
||||
|
||||
if(paletteInfo == null) {
|
||||
main.logger().info("null palette: " + biome.getID());
|
||||
}
|
||||
|
||||
|
||||
GenerationSettings generationSettings = biome.getGenerator();
|
||||
|
||||
|
||||
int sea = paletteInfo.getSeaLevel();
|
||||
Palette seaPalette = paletteInfo.getOcean();
|
||||
|
||||
|
||||
boolean justSet = false;
|
||||
BlockState data = null;
|
||||
for(int y = world.getMaxHeight() - 1; y >= world.getMinHeight(); y--) {
|
||||
if(sampler.sample(x, y, z) > 0) {
|
||||
justSet = true;
|
||||
|
||||
data = PaletteUtil.getPalette(x, y, z, generationSettings, sampler, paletteInfo).get(paletteLevel, cx, y, cz, seed);
|
||||
|
||||
data = PaletteUtil.getPalette(x, y, z, generationSettings, sampler, paletteInfo).get(paletteLevel, cx, y, cz,
|
||||
seed);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
|
||||
|
||||
paletteLevel++;
|
||||
} else if(y <= sea) {
|
||||
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, y, z + zOrig, seed));
|
||||
|
||||
|
||||
justSet = false;
|
||||
paletteLevel = 0;
|
||||
} else {
|
||||
|
||||
} else {
|
||||
|
||||
justSet = false;
|
||||
paletteLevel = 0;
|
||||
}
|
||||
@@ -129,47 +122,38 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean placeStair(BlockState orig, ChunkData chunk, Vector3 block, double thresh, Sampler sampler, BlockState stairNew) {
|
||||
|
||||
if(sampler.sample(block.getBlockX() - 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.WEST);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() - 0.55) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.NORTH);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() + 0.55) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.SOUTH);
|
||||
} else if(sampler.sample(block.getX() + 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
stairNew.setIfPresent(Properties.WATERLOGGED, orig.getBlockType().isWater());
|
||||
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) {
|
||||
biomes(world, chunkX, chunkZ, biome, main);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) {
|
||||
return new Sampler3D(chunkX, chunkZ, provider, world, elevationSmooth);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigPack getConfigPack() {
|
||||
return configPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraPlugin getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GenerationStage> getGenerationStages() {
|
||||
return generationStages;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(World world, int x, int y, int z) {
|
||||
BiomeProvider provider = world.getBiomeProvider();
|
||||
TerraBiome biome = provider.getBiome(x, z, world.getSeed());
|
||||
Sampler sampler = world.getConfig().getSamplerCache().get(x, z);
|
||||
|
||||
|
||||
PaletteInfo paletteInfo = biome.getContext().get(PaletteInfo.class);
|
||||
Palette palette = PaletteUtil.getPalette(x, y, z, biome.getGenerator(), sampler, paletteInfo);
|
||||
int fdX = FastMath.floorMod(x, 16);
|
||||
@@ -186,4 +170,23 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
return paletteInfo.getOcean().get(paletteInfo.getSeaLevel() - y, x, y, z, world.getSeed());
|
||||
} else return air;
|
||||
}
|
||||
|
||||
private boolean placeStair(BlockState orig, ChunkData chunk, Vector3 block, double thresh, Sampler sampler, BlockState stairNew) {
|
||||
|
||||
if(sampler.sample(block.getBlockX() - 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.WEST);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() - 0.55) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.NORTH);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getY(), block.getZ() + 0.55) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.SOUTH);
|
||||
} else if(sampler.sample(block.getX() + 0.55, block.getY(), block.getZ()) > thresh) {
|
||||
stairNew.set(Properties.DIRECTION, Direction.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
stairNew.setIfPresent(Properties.WATERLOGGED, orig.getBlockType().isWater());
|
||||
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.ChunkInterpolator;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Class to abstract away the Interpolators needed to generate a chunk.<br>
|
||||
@@ -19,7 +21,7 @@ import java.util.function.BiFunction;
|
||||
public class ChunkInterpolator2D implements ChunkInterpolator {
|
||||
private final Interpolator[][] interpGrid = new Interpolator[4][4];
|
||||
private final BiFunction<GenerationSettings, Vector3, Double> noiseGetter;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates.
|
||||
*
|
||||
@@ -27,33 +29,36 @@ public class ChunkInterpolator2D implements ChunkInterpolator {
|
||||
* @param chunkZ Z coordinate of the chunk.
|
||||
* @param provider Biome Provider to use for biome fetching.
|
||||
*/
|
||||
public ChunkInterpolator2D(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction<GenerationSettings, Vector3, Double> noiseGetter) {
|
||||
public ChunkInterpolator2D(World w, int chunkX, int chunkZ, BiomeProvider provider,
|
||||
BiFunction<GenerationSettings, Vector3, Double> noiseGetter) {
|
||||
this.noiseGetter = noiseGetter;
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
|
||||
|
||||
long seed = w.getSeed();
|
||||
|
||||
|
||||
double[][] noiseStorage = new double[5][5];
|
||||
|
||||
|
||||
for(int x = 0; x < 5; x++) {
|
||||
for(int z = 0; z < 5; z++) {
|
||||
GenerationSettings generationSettings = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2), seed).getGenerator();
|
||||
Map<GenerationSettings, MutableInteger> genMap = new HashMap<>();
|
||||
|
||||
|
||||
int step = generationSettings.getBlendStep();
|
||||
int blend = generationSettings.getBlendDistance();
|
||||
|
||||
|
||||
for(int xi = -blend; xi <= blend; xi++) {
|
||||
for(int zi = -blend; zi <= blend; zi++) {
|
||||
genMap.computeIfAbsent(provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step), seed).getGenerator(), g -> new MutableInteger(0)).increment(); // Increment by 1
|
||||
genMap.computeIfAbsent(
|
||||
provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step), seed).getGenerator(),
|
||||
g -> new MutableInteger(0)).increment(); // Increment by 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
noiseStorage[x][z] = computeNoise(genMap, (x << 2) + xOrigin, 0, (z << 2) + zOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int z = 0; z < 4; z++) {
|
||||
interpGrid[x][z] = new Interpolator(
|
||||
@@ -64,27 +69,28 @@ public class ChunkInterpolator2D implements ChunkInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int reRange(int value, int high) {
|
||||
return FastMath.max(FastMath.min(value, high), 0);
|
||||
}
|
||||
|
||||
|
||||
public double computeNoise(GenerationSettings generationSettings, double x, double y, double z) {
|
||||
return noiseGetter.apply(generationSettings, new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the noise at a pair of internal chunk coordinates.
|
||||
*
|
||||
* @param x The internal X coordinate (0-15).
|
||||
* @param z The internal Z coordinate (0-15).
|
||||
*
|
||||
* @return double - The interpolated noise at the coordinates.
|
||||
*/
|
||||
@Override
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) z) / 4, 3)].bilerp((x % 4) / 4, (z % 4) / 4);
|
||||
}
|
||||
|
||||
|
||||
public double getNoise(int x, int y, int z) {
|
||||
return interpGrid[x / 4][z / 4].bilerp((double) (x % 4) / 4, (double) (z % 4) / 4);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.ChunkInterpolator;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Class to abstract away the Interpolators needed to generate a chunk.<br>
|
||||
@@ -19,10 +21,10 @@ import java.util.function.BiFunction;
|
||||
public class ChunkInterpolator3D implements ChunkInterpolator {
|
||||
private final Interpolator3[][][] interpGrid;
|
||||
private final BiFunction<GenerationSettings, Vector3, Double> noiseGetter;
|
||||
|
||||
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates.
|
||||
*
|
||||
@@ -30,43 +32,46 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
|
||||
* @param chunkZ Z coordinate of the chunk.
|
||||
* @param provider Biome Provider to use for biome fetching.
|
||||
*/
|
||||
public ChunkInterpolator3D(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction<GenerationSettings, Vector3, Double> noiseGetter) {
|
||||
public ChunkInterpolator3D(World w, int chunkX, int chunkZ, BiomeProvider provider,
|
||||
BiFunction<GenerationSettings, Vector3, Double> noiseGetter) {
|
||||
this.noiseGetter = noiseGetter;
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
|
||||
|
||||
this.max = w.getMaxHeight();
|
||||
this.min = w.getMinHeight();
|
||||
int range = max - min + 1;
|
||||
|
||||
|
||||
int size = range >> 2;
|
||||
|
||||
|
||||
interpGrid = new Interpolator3[4][size][4];
|
||||
|
||||
|
||||
double[][][] noiseStorage = new double[5][5][size + 1];
|
||||
|
||||
|
||||
long seed = w.getSeed();
|
||||
|
||||
|
||||
for(int x = 0; x < 5; x++) {
|
||||
for(int z = 0; z < 5; z++) {
|
||||
GenerationSettings generationSettings = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2), seed).getGenerator();
|
||||
Map<GenerationSettings, MutableInteger> genMap = new HashMap<>();
|
||||
|
||||
|
||||
int step = generationSettings.getBlendStep();
|
||||
int blend = generationSettings.getBlendDistance();
|
||||
|
||||
|
||||
for(int xi = -blend; xi <= blend; xi++) {
|
||||
for(int zi = -blend; zi <= blend; zi++) {
|
||||
genMap.computeIfAbsent(provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step), seed).getGenerator(), g -> new MutableInteger(0)).increment(); // Increment by 1
|
||||
genMap.computeIfAbsent(
|
||||
provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step), seed).getGenerator(),
|
||||
g -> new MutableInteger(0)).increment(); // Increment by 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int y = 0; y < size + 1; y++) {
|
||||
noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, (y << 2) + min, (z << 2) + zOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int z = 0; z < 4; z++) {
|
||||
for(int y = 0; y < size; y++) {
|
||||
@@ -83,27 +88,30 @@ public class ChunkInterpolator3D implements ChunkInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int reRange(int value, int high) {
|
||||
return FastMath.max(FastMath.min(value, high), 0);
|
||||
}
|
||||
|
||||
|
||||
public double computeNoise(GenerationSettings generationSettings, double x, double y, double z) {
|
||||
return noiseGetter.apply(generationSettings, new Vector3(x, y, z));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the noise at a pair of internal chunk coordinates.
|
||||
*
|
||||
* @param x The internal X coordinate (0-15).
|
||||
* @param z The internal Z coordinate (0-15).
|
||||
*
|
||||
* @return double - The interpolated noise at the coordinates.
|
||||
*/
|
||||
@Override
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(FastMath.max(FastMath.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
return interpGrid[reRange(((int) x) / 4, 3)][(FastMath.max(FastMath.min(((int) y), max), min) - min) / 4][reRange(((int) z) / 4,
|
||||
3)].trilerp(
|
||||
(x % 4) / 4, (y % 4) / 4, (z % 4) / 4);
|
||||
}
|
||||
|
||||
|
||||
public double getNoise(int x, int y, int z) {
|
||||
return interpGrid[x / 4][(y - min) / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4);
|
||||
}
|
||||
|
||||
@@ -4,24 +4,25 @@ import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class ElevationInterpolator {
|
||||
private final double[][] values = new double[18][18];
|
||||
|
||||
|
||||
public ElevationInterpolator(World world, int chunkX, int chunkZ, BiomeProvider provider, int smooth) {
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
|
||||
GenerationSettings[][] gens = new GenerationSettings[18 + 2 * smooth][18 + 2 * smooth];
|
||||
|
||||
|
||||
// Precompute generators.
|
||||
for(int x = -1 - smooth; x <= 16 + smooth; x++) {
|
||||
for(int z = -1 - smooth; z <= 16 + smooth; z++) {
|
||||
gens[x + 1 + smooth][z + 1 + smooth] = provider.getBiome(xOrigin + x, zOrigin + z, seed).getGenerator();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int x = -1; x <= 16; x++) {
|
||||
for(int z = -1; z <= 16; z++) {
|
||||
double noise = 0;
|
||||
@@ -37,7 +38,7 @@ public class ElevationInterpolator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double getElevation(int x, int z) {
|
||||
return values[x + 1][z + 1];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
*/
|
||||
public class Interpolator {
|
||||
private final double v0, v1, v2, v3;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an interpolator with given values as vertices of a unit square.
|
||||
*
|
||||
@@ -20,24 +20,26 @@ public class Interpolator {
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1D Linear interpolation between 2 points 1 unit apart.
|
||||
*
|
||||
* @param t - Distance from v0. Total distance between v0 and v1 is 1 unit.
|
||||
* @param v0 - Value at v0.
|
||||
* @param v1 - Value at v1.
|
||||
*
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 2D Bilinear interpolation between 4 points on a unit square.
|
||||
*
|
||||
* @param s - X value
|
||||
* @param t - Z value
|
||||
*
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public double bilerp(double s, double t) {
|
||||
|
||||
@@ -6,7 +6,7 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
public class Interpolator3 {
|
||||
private final Interpolator bottom;
|
||||
private final Interpolator top;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an interpolator with given values as vertices of a unit cube.
|
||||
* * @param _000 The value at <code>(t, u, v) = (0, 0, 0)</code>.
|
||||
@@ -25,7 +25,7 @@ public class Interpolator3 {
|
||||
this.top = new Interpolator(_000, _010, _001, _011);
|
||||
this.bottom = new Interpolator(_100, _110, _101, _111);
|
||||
}
|
||||
|
||||
|
||||
public double trilerp(double x, double y, double z) {
|
||||
return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
|
||||
}
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ChunkInterpolator3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.ElevationInterpolator;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.Sampler;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
|
||||
public class Sampler3D implements Sampler {
|
||||
private final ChunkInterpolator3D interpolator;
|
||||
private final ElevationInterpolator elevationInterpolator;
|
||||
|
||||
|
||||
public Sampler3D(int x, int z, BiomeProvider provider, World world, int elevationSmooth) {
|
||||
this.interpolator = new ChunkInterpolator3D(world, x, z, provider, (generator, coord) -> generator.getBaseSampler().getNoiseSeeded(coord, world.getSeed()));
|
||||
this.interpolator = new ChunkInterpolator3D(world, x, z, provider, (generator, coord) -> generator.getBaseSampler()
|
||||
.getNoiseSeeded(coord,
|
||||
world.getSeed()));
|
||||
this.elevationInterpolator = new ElevationInterpolator(world, x, z, provider, elevationSmooth);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double sample(double x, double y, double z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double sample(int x, int y, int z) {
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
|
||||
@@ -2,21 +2,22 @@ package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette[] palettes;
|
||||
private final int offset;
|
||||
|
||||
|
||||
protected PaletteHolder(Palette[] palettes, int offset) {
|
||||
this.palettes = palettes;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
|
||||
public Palette getPalette(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PaletteHolder build() {
|
||||
|
||||
|
||||
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
|
||||
Palette[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette d = null;
|
||||
|
||||
@@ -3,12 +3,14 @@ package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
||||
@@ -3,32 +3,33 @@ package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteInfo implements Properties {
|
||||
private final PaletteHolder paletteHolder;
|
||||
private final SlantHolder slantHolder;
|
||||
private final Palette ocean;
|
||||
|
||||
|
||||
private final int seaLevel;
|
||||
|
||||
|
||||
public PaletteInfo(PaletteHolder paletteHolder, SlantHolder slantHolder, Palette ocean, int seaLevel) {
|
||||
this.paletteHolder = paletteHolder;
|
||||
this.slantHolder = slantHolder;
|
||||
this.ocean = ocean;
|
||||
this.seaLevel = seaLevel;
|
||||
}
|
||||
|
||||
|
||||
public Palette getOcean() {
|
||||
return ocean;
|
||||
}
|
||||
|
||||
|
||||
public PaletteHolder getPaletteHolder() {
|
||||
return paletteHolder;
|
||||
}
|
||||
|
||||
|
||||
public SlantHolder getSlantHolder() {
|
||||
return slantHolder;
|
||||
}
|
||||
|
||||
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
@@ -3,19 +3,20 @@ package com.dfsek.terra.addons.chunkgenerator.palette;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class SlantHolder {
|
||||
private final TreeMap<Double, PaletteHolder> layers;
|
||||
private final double minSlope;
|
||||
|
||||
|
||||
public SlantHolder(TreeMap<Double, PaletteHolder> layers, double minSlope) {
|
||||
this.layers = layers;
|
||||
this.minSlope = minSlope;
|
||||
}
|
||||
|
||||
|
||||
public PaletteHolder getPalette(double slope) {
|
||||
return layers.floorEntry(slope).getValue();
|
||||
}
|
||||
|
||||
|
||||
public double getMinSlope() {
|
||||
return minSlope;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SlantHolderLoader implements TypeLoader<SlantHolder> {
|
||||
@Override
|
||||
@@ -16,13 +17,13 @@ public class SlantHolderLoader implements TypeLoader<SlantHolder> {
|
||||
List<Map<Object, Object>> layers = (List<Map<Object, Object>>) o;
|
||||
TreeMap<Double, PaletteHolder> slantLayers = new TreeMap<>();
|
||||
double minThreshold = Double.MAX_VALUE;
|
||||
|
||||
|
||||
for(Map<Object, Object> layer : layers) {
|
||||
double threshold = ((Number) layer.get("threshold")).doubleValue();
|
||||
if(threshold < minThreshold) minThreshold = threshold;
|
||||
slantLayers.put(threshold, configLoader.loadType(PaletteHolder.class, layer.get("palette")));
|
||||
}
|
||||
|
||||
|
||||
return new SlantHolder(slantLayers, minThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,22 +11,23 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
|
||||
@Addon("config-biome")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class BiomeAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new BiomeConfigType(event.getPack()), "BIOME", 5);
|
||||
event.getPack().applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new BiomeConfigType(event.getPack()), "BIOME", 5);
|
||||
event.getPack().applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -10,32 +13,16 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
|
||||
public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
private final BiomeFactory factory;
|
||||
|
||||
public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
|
||||
|
||||
|
||||
public BiomeConfigType(ConfigPack pack) {
|
||||
this.factory = new BiomeFactory(pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new BiomeTemplate(pack, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<BiomeTemplate, TerraBiome> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<TerraBiome> getTypeKey() {
|
||||
return BIOME_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<TerraBiome>> registrySupplier(ConfigPack pack) {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<TerraBiome>) (t, c, loader) -> {
|
||||
@@ -46,4 +33,19 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new BiomeTemplate(pack, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<BiomeTemplate, TerraBiome> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<TerraBiome> getTypeKey() {
|
||||
return BIOME_TYPE_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,22 @@ import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class BiomeFactory implements ConfigFactory<BiomeTemplate, TerraBiome> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
|
||||
public BiomeFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome build(BiomeTemplate template, TerraPlugin main) {
|
||||
UserDefinedGenerationSettings generator = new UserDefinedGenerationSettings(template.getNoiseEquation(), template.getElevationEquation(), template.getCarvingEquation(), template.getBiomeNoise(), template.getElevationWeight(),
|
||||
template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight());
|
||||
UserDefinedGenerationSettings generator = new UserDefinedGenerationSettings(template.getNoiseEquation(),
|
||||
template.getElevationEquation(),
|
||||
template.getCarvingEquation(), template.getBiomeNoise(),
|
||||
template.getElevationWeight(),
|
||||
template.getBlendDistance(), template.getBlendStep(),
|
||||
template.getBlendWeight());
|
||||
return new UserDefinedBiome(template.getVanilla(), generator, template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,14 @@ import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
@@ -15,196 +23,191 @@ import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
public class BiomeTemplate implements AbstractableTemplate, ValidatedConfigTemplate {
|
||||
private final ConfigPack pack;
|
||||
|
||||
|
||||
@Value("id")
|
||||
@Final
|
||||
private @Meta String id;
|
||||
|
||||
|
||||
@Value("extends")
|
||||
@Final
|
||||
@Default
|
||||
private List<String> extended = Collections.emptyList();
|
||||
|
||||
|
||||
@Value("variables")
|
||||
@Default
|
||||
private @Meta Map<String, @Meta Double> variables = new HashMap<>();
|
||||
|
||||
|
||||
@Value("beta.carving.equation")
|
||||
@Default
|
||||
private @Meta NoiseSampler carvingEquation = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("vanilla")
|
||||
private @Meta ProbabilityCollection<Biome> vanilla;
|
||||
|
||||
|
||||
@Value("biome-noise")
|
||||
@Default
|
||||
private @Meta NoiseSampler biomeNoise = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("blend.distance")
|
||||
@Default
|
||||
private @Meta int blendDistance = 3;
|
||||
|
||||
|
||||
@Value("blend.weight")
|
||||
@Default
|
||||
private @Meta double blendWeight = 1;
|
||||
|
||||
|
||||
@Value("blend.step")
|
||||
@Default
|
||||
private @Meta int blendStep = 4;
|
||||
|
||||
|
||||
@Value("noise")
|
||||
private @Meta NoiseSampler noiseEquation;
|
||||
|
||||
|
||||
@Value("ocean.level")
|
||||
@Default
|
||||
private @Meta int seaLevel = 62;
|
||||
|
||||
|
||||
@Value("elevation.equation")
|
||||
@Default
|
||||
private @Meta NoiseSampler elevationEquation = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("elevation.weight")
|
||||
@Default
|
||||
private @Meta double elevationWeight = 1;
|
||||
|
||||
|
||||
@Value("slabs.enable")
|
||||
@Default
|
||||
private @Meta boolean doSlabs = false;
|
||||
|
||||
|
||||
@Value("slabs.threshold")
|
||||
@Default
|
||||
private @Meta double slabThreshold = 0.0075D;
|
||||
|
||||
|
||||
@Value("slabs.palettes")
|
||||
@Default
|
||||
private @Meta Map<@Meta BlockType, @Meta Palette> slabPalettes;
|
||||
|
||||
|
||||
@Value("slabs.stair-palettes")
|
||||
@Default
|
||||
private @Meta Map<@Meta BlockType, @Meta Palette> stairPalettes;
|
||||
|
||||
|
||||
@Value("interpolate-elevation")
|
||||
@Default
|
||||
private @Meta boolean interpolateElevation = true;
|
||||
|
||||
|
||||
@Value("color")
|
||||
@Final
|
||||
@Default
|
||||
private @Meta int color = 0;
|
||||
|
||||
|
||||
@Value("tags")
|
||||
@Default
|
||||
private @Meta Set<@Meta String> tags = new HashSet<>();
|
||||
|
||||
|
||||
@Value("colors")
|
||||
@Default
|
||||
private @Meta Map<String, @Meta Integer> colors = new HashMap<>(); // Plain ol' map, so platforms can decide what to do with colors (if anything).
|
||||
|
||||
private @Meta Map<String, @Meta Integer> colors = new HashMap<>();
|
||||
// Plain ol' map, so platforms can decide what to do with colors (if anything).
|
||||
|
||||
public BiomeTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public List<String> getExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public double getBlendWeight() {
|
||||
return blendWeight;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getBlendDistance() {
|
||||
return blendDistance;
|
||||
}
|
||||
|
||||
|
||||
public boolean interpolateElevation() {
|
||||
return interpolateElevation;
|
||||
}
|
||||
|
||||
public double getSlabThreshold() {
|
||||
return slabThreshold;
|
||||
}
|
||||
|
||||
|
||||
public boolean doSlabs() {
|
||||
return doSlabs;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
}
|
||||
|
||||
public NoiseSampler getBiomeNoise() {
|
||||
return biomeNoise;
|
||||
}
|
||||
|
||||
public NoiseSampler getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public NoiseSampler getCarvingEquation() {
|
||||
return carvingEquation;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Biome> getVanilla() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
public NoiseSampler getNoiseEquation() {
|
||||
return noiseEquation;
|
||||
}
|
||||
|
||||
public double getElevationWeight() {
|
||||
return elevationWeight;
|
||||
}
|
||||
|
||||
public int getBlendStep() {
|
||||
return blendStep;
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
color |= 0xff000000; // Alpha adjustment
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getExtended() {
|
||||
return extended;
|
||||
}
|
||||
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getColors() {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public double getBlendWeight() {
|
||||
return blendWeight;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getBlendDistance() {
|
||||
return blendDistance;
|
||||
}
|
||||
|
||||
public double getSlabThreshold() {
|
||||
return slabThreshold;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getSlabPalettes() {
|
||||
return slabPalettes;
|
||||
}
|
||||
|
||||
public Map<BlockType, Palette> getStairPalettes() {
|
||||
return stairPalettes;
|
||||
}
|
||||
|
||||
public NoiseSampler getBiomeNoise() {
|
||||
return biomeNoise;
|
||||
}
|
||||
|
||||
public NoiseSampler getElevationEquation() {
|
||||
return elevationEquation;
|
||||
}
|
||||
|
||||
public NoiseSampler getCarvingEquation() {
|
||||
return carvingEquation;
|
||||
}
|
||||
|
||||
public ConfigPack getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public int getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Biome> getVanilla() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
public NoiseSampler getNoiseEquation() {
|
||||
return noiseEquation;
|
||||
}
|
||||
|
||||
public double getElevationWeight() {
|
||||
return elevationWeight;
|
||||
}
|
||||
|
||||
public int getBlendStep() {
|
||||
return blendStep;
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,23 +3,24 @@ package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
|
||||
|
||||
public class BlankFunction implements DynamicFunction {
|
||||
private final int args;
|
||||
|
||||
|
||||
public BlankFunction(int args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double eval(double... d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateless() {
|
||||
return true;
|
||||
|
||||
@@ -4,13 +4,14 @@ import com.dfsek.terra.addons.biome.holder.PaletteHolder;
|
||||
import com.dfsek.terra.api.world.biome.PaletteSettings;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteSettingsImpl implements PaletteSettings {
|
||||
private final PaletteHolder palette;
|
||||
|
||||
|
||||
public PaletteSettingsImpl(PaletteHolder palette) {
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Palette getPalette(int y) {
|
||||
return palette.getPalette(y);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class representing a config-defined biome
|
||||
@@ -18,9 +19,9 @@ public class UserDefinedBiome implements TerraBiome {
|
||||
private final BiomeTemplate config;
|
||||
private final int color;
|
||||
private final Set<String> tags;
|
||||
|
||||
|
||||
private final Context context = new Context();
|
||||
|
||||
|
||||
public UserDefinedBiome(ProbabilityCollection<Biome> vanilla, UserDefinedGenerationSettings gen, BiomeTemplate config) {
|
||||
this.vanilla = vanilla;
|
||||
this.gen = gen;
|
||||
@@ -30,7 +31,12 @@ public class UserDefinedBiome implements TerraBiome {
|
||||
this.tags = config.getTags();
|
||||
tags.add("BIOME:" + id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{BIOME:" + getID() + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Vanilla biomes to represent the custom biome.
|
||||
*
|
||||
@@ -40,36 +46,31 @@ public class UserDefinedBiome implements TerraBiome {
|
||||
public ProbabilityCollection<Biome> getVanillaBiomes() {
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public BiomeTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GenerationSettings getGenerator() {
|
||||
return gen;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{BIOME:" + getID() + "}";
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public BiomeTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return context;
|
||||
|
||||
@@ -3,65 +3,67 @@ package com.dfsek.terra.addons.biome;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.world.biome.GenerationSettings;
|
||||
|
||||
public class UserDefinedGenerationSettings implements GenerationSettings {
|
||||
|
||||
public class UserDefinedGenerationSettings implements GenerationSettings {
|
||||
|
||||
private final NoiseSampler noise;
|
||||
private final NoiseSampler elevation;
|
||||
private final NoiseSampler carving;
|
||||
|
||||
|
||||
private final NoiseSampler biomeNoise;
|
||||
private final double elevationWeight;
|
||||
private final int blendDistance;
|
||||
private final int blendStep;
|
||||
private final double blendWeight;
|
||||
|
||||
public UserDefinedGenerationSettings(NoiseSampler noise, NoiseSampler elevation, NoiseSampler carving, NoiseSampler biomeNoise, double elevationWeight, int blendDistance, int blendStep, double blendWeight) {
|
||||
|
||||
public UserDefinedGenerationSettings(NoiseSampler noise, NoiseSampler elevation, NoiseSampler carving, NoiseSampler biomeNoise,
|
||||
double elevationWeight, int blendDistance, int blendStep, double blendWeight) {
|
||||
this.noise = noise;
|
||||
this.elevation = elevation;
|
||||
this.carving = carving;
|
||||
|
||||
|
||||
this.biomeNoise = biomeNoise;
|
||||
this.elevationWeight = elevationWeight;
|
||||
this.blendDistance = blendDistance;
|
||||
this.blendStep = blendStep;
|
||||
this.blendWeight = blendWeight;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NoiseSampler getBaseSampler() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NoiseSampler getElevationSampler() {
|
||||
return elevation;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NoiseSampler getCarver() {
|
||||
return carving;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBlendDistance() {
|
||||
return blendDistance;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return blendWeight;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NoiseSampler getBiomeNoise() {
|
||||
return biomeNoise;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getElevationWeight() {
|
||||
return elevationWeight;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBlendStep() {
|
||||
return blendStep;
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Runnable that locates a biome asynchronously
|
||||
*/
|
||||
public class AsyncBiomeFinder implements Runnable {
|
||||
|
||||
|
||||
protected final BiomeProvider provider;
|
||||
protected final TerraBiome target;
|
||||
protected final int startRadius;
|
||||
@@ -24,8 +26,9 @@ public class AsyncBiomeFinder implements Runnable {
|
||||
protected final TerraPlugin main;
|
||||
private final Consumer<Vector3> callback;
|
||||
protected int searchSize = 1;
|
||||
|
||||
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius, Consumer<Vector3> callback, TerraPlugin main) {
|
||||
|
||||
public AsyncBiomeFinder(BiomeProvider provider, TerraBiome target, @NotNull Vector3 origin, World world, int startRadius, int maxRadius,
|
||||
Consumer<Vector3> callback, TerraPlugin main) {
|
||||
this.provider = provider;
|
||||
this.target = target;
|
||||
this.main = main;
|
||||
@@ -36,35 +39,23 @@ public class AsyncBiomeFinder implements Runnable {
|
||||
this.world = world;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get biome at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
* @return TerraBiome at coordinates
|
||||
*/
|
||||
public boolean isValid(int x, int z, TerraBiome target) {
|
||||
int res = main.getTerraConfig().getBiomeSearchResolution();
|
||||
return getProvider().getBiome(x * res, z * res, world.getSeed()).equals(target);
|
||||
}
|
||||
|
||||
|
||||
public Vector3 finalizeVector(Vector3 orig) {
|
||||
return orig.multiply(main.getTerraConfig().getBiomeSearchResolution());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int x = centerX;
|
||||
int z = centerZ;
|
||||
|
||||
|
||||
x /= searchSize;
|
||||
z /= searchSize;
|
||||
|
||||
|
||||
int run = 1;
|
||||
boolean toggle = true;
|
||||
boolean found = false;
|
||||
|
||||
|
||||
main:
|
||||
for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
@@ -89,23 +80,36 @@ public class AsyncBiomeFinder implements Runnable {
|
||||
Vector3 finalSpawn = found ? finalizeVector(new Vector3(x, 0, z)) : null;
|
||||
callback.accept(finalSpawn);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to get biome at location
|
||||
*
|
||||
* @param x X coordinate
|
||||
* @param z Z coordinate
|
||||
*
|
||||
* @return TerraBiome at coordinates
|
||||
*/
|
||||
public boolean isValid(int x, int z, TerraBiome target) {
|
||||
int res = main.getTerraConfig().getBiomeSearchResolution();
|
||||
return getProvider().getBiome(x * res, z * res, world.getSeed()).equals(target);
|
||||
}
|
||||
|
||||
public TerraBiome getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
public BiomeProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
|
||||
public int getSearchSize() {
|
||||
return searchSize;
|
||||
}
|
||||
|
||||
|
||||
public void setSearchSize(int searchSize) {
|
||||
this.searchSize = searchSize;
|
||||
}
|
||||
|
||||
@@ -12,18 +12,11 @@ import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
@Command(
|
||||
subcommands = {
|
||||
@Subcommand(
|
||||
value = "info",
|
||||
aliases = {"i"},
|
||||
clazz = BiomeInfoCommand.class
|
||||
),
|
||||
@Subcommand(
|
||||
value = "locate",
|
||||
aliases = {"l"},
|
||||
clazz = BiomeLocateCommand.class
|
||||
)
|
||||
@Subcommand(value = "info", aliases = "i", clazz = BiomeInfoCommand.class),
|
||||
@Subcommand(value = "locate", aliases = "l", clazz = BiomeLocateCommand.class)
|
||||
},
|
||||
usage = "/terra biome"
|
||||
)
|
||||
@@ -32,11 +25,11 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
public class BiomeCommand implements CommandTemplate {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
|
||||
BiomeProvider provider = player.world().getBiomeProvider();
|
||||
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.position(), player.world().getSeed());
|
||||
sender.sendMessage("You are standing in " + biome.getID());
|
||||
|
||||
@@ -11,27 +11,24 @@ import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
@Command(
|
||||
arguments = {
|
||||
@Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@Command(arguments = @Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
))
|
||||
public class BiomeInfoCommand implements CommandTemplate {
|
||||
@ArgumentTarget("biome")
|
||||
private TerraBiome biome;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
sender.sendMessage("Biome info for \"" + biome.getID() + "\".");
|
||||
sender.sendMessage("Vanilla biome: " + biome.getVanillaBiomes());
|
||||
|
||||
|
||||
if(biome instanceof UserDefinedBiome) {
|
||||
BiomeTemplate bio = ((UserDefinedBiome) biome).getConfig();
|
||||
|
||||
|
||||
if(bio.getExtended().size() == 0) {
|
||||
sender.sendMessage("No Parent Biomes");
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.addons.biome.command.biome.arg.BiomeArgumentParser;
|
||||
import com.dfsek.terra.addons.biome.command.biome.tab.BiomeTabCompleter;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
@@ -18,58 +20,58 @@ import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@PlayerCommand
|
||||
@WorldCommand
|
||||
@Command(
|
||||
arguments = {
|
||||
@Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
),
|
||||
@Argument(
|
||||
value = "radius",
|
||||
required = false,
|
||||
defaultValue = "1000",
|
||||
argumentParser = IntegerArgumentParser.class
|
||||
)
|
||||
},
|
||||
switches = {
|
||||
@Switch(
|
||||
value = "teleport",
|
||||
aliases = {"t", "tp"}
|
||||
)
|
||||
}
|
||||
)
|
||||
@Command(arguments = {
|
||||
@Argument(
|
||||
value = "biome",
|
||||
tabCompleter = BiomeTabCompleter.class,
|
||||
argumentParser = BiomeArgumentParser.class
|
||||
),
|
||||
@Argument(
|
||||
value = "radius",
|
||||
required = false,
|
||||
defaultValue = "1000",
|
||||
argumentParser = IntegerArgumentParser.class
|
||||
)
|
||||
}, switches = @Switch(
|
||||
value = "teleport",
|
||||
aliases = { "t", "tp" }
|
||||
))
|
||||
public class BiomeLocateCommand implements CommandTemplate {
|
||||
|
||||
|
||||
@ArgumentTarget("radius")
|
||||
private Integer radius;
|
||||
|
||||
|
||||
@ArgumentTarget("biome")
|
||||
private TerraBiome biome;
|
||||
|
||||
|
||||
@SwitchTarget("teleport")
|
||||
private boolean teleport;
|
||||
|
||||
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender) {
|
||||
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
|
||||
|
||||
new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome,
|
||||
player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())),
|
||||
player.world(), 0, radius, location -> {
|
||||
if(location != null) {
|
||||
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
|
||||
sender.sendMessage(
|
||||
String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT),
|
||||
location.getBlockX(), location.getBlockZ(),
|
||||
location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
|
||||
if(teleport) {
|
||||
main.runPossiblyUnsafeTask(() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
|
||||
main.runPossiblyUnsafeTask(
|
||||
() -> player.position(new Vector3(location.getX(), player.position().getY(), location.getZ())));
|
||||
}
|
||||
} else sender.sendMessage("Unable to locate biome \"" + biome.getID() + "\"");
|
||||
}, main), "Biome Location Thread").start();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
|
||||
public class BiomeArgumentParser implements ArgumentParser<TerraBiome> {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public TerraBiome parse(CommandSender sender, String arg) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.addons.biome.command.biome.tab;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.command.tab.TabCompleter;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
@@ -7,16 +10,15 @@ import com.dfsek.terra.api.entity.Player;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BiomeTabCompleter implements TabCompleter {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> complete(CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
return player.world().getConfig().getRegistry(TerraBiome.class).entries().stream().map(TerraBiome::getID).collect(Collectors.toList());
|
||||
return player.world().getConfig().getRegistry(TerraBiome.class).entries().stream().map(TerraBiome::getID).collect(
|
||||
Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,21 +2,22 @@ package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolder {
|
||||
private final Palette[] palettes;
|
||||
private final int offset;
|
||||
|
||||
|
||||
protected PaletteHolder(Palette[] palettes, int offset) {
|
||||
this.palettes = palettes;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
|
||||
public Palette getPalette(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
? index < palettes.length
|
||||
? palettes[index]
|
||||
: palettes[palettes.length - 1]
|
||||
: palettes[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
|
||||
|
||||
public PaletteHolderBuilder add(int y, Palette palette) {
|
||||
paletteMap.put(y, palette);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public PaletteHolder build() {
|
||||
|
||||
|
||||
int min = FastMath.min(paletteMap.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(paletteMap.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
|
||||
Palette[] palettes = new Palette[paletteMap.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(paletteMap.lastKey(), max); y++) {
|
||||
Palette d = null;
|
||||
|
||||
@@ -3,13 +3,14 @@ package com.dfsek.terra.addons.biome.holder;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteHolderLoader implements TypeLoader<PaletteHolder> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
package com.dfsek.terra.addons.carver;
|
||||
|
||||
import com.dfsek.terra.addons.carver.carving.Worm;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
@@ -18,43 +10,60 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class CarverCache {
|
||||
import com.dfsek.terra.addons.carver.carving.Worm;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
|
||||
public class CarverCache {
|
||||
|
||||
private final LoadingCache<Long, List<Worm.WormPoint>> cache;
|
||||
private final UserDefinedCarver carver;
|
||||
|
||||
|
||||
public CarverCache(World w, TerraPlugin main, UserDefinedCarver carver) {
|
||||
this.carver = carver;
|
||||
cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getCarverCacheSize())
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public List<Worm.WormPoint> load(@NotNull Long key) {
|
||||
int chunkX = (int) (key >> 32);
|
||||
int chunkZ = (int) key.longValue();
|
||||
BiomeProvider provider = w.getBiomeProvider();
|
||||
if(CarverCache.this.carver.isChunkCarved(w, chunkX, chunkZ, new Random(PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + CarverCache.this.carver.hashCode())))) {
|
||||
long seed = PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||
Random r = new Random(seed);
|
||||
Worm carving = CarverCache.this.carver.getWorm(seed, new Vector3((chunkX << 4) + r.nextInt(16), CarverCache.this.carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
|
||||
List<Worm.WormPoint> points = new ArrayList<>();
|
||||
for(int i = 0; i < carving.getLength(); i++) {
|
||||
carving.step();
|
||||
TerraBiome biome = provider.getBiome(carving.getRunning(), w.getSeed());
|
||||
.build(new CacheLoader<>() {
|
||||
@Override
|
||||
public List<Worm.WormPoint> load(@NotNull Long key) {
|
||||
int chunkX = (int) (key >> 32);
|
||||
int chunkZ = (int) key.longValue();
|
||||
BiomeProvider provider = w.getBiomeProvider();
|
||||
if(CarverCache.this.carver.isChunkCarved(w, chunkX, chunkZ, new Random(
|
||||
PopulationUtil.getCarverChunkSeed(chunkX, chunkZ,
|
||||
w.getSeed() + CarverCache.this.carver.hashCode())))) {
|
||||
long seed = PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||
Random r = new Random(seed);
|
||||
Worm carving = CarverCache.this.carver.getWorm(seed, new Vector3((chunkX << 4) + r.nextInt(16),
|
||||
CarverCache.this.carver.getConfig()
|
||||
.getHeight()
|
||||
.get(r),
|
||||
(chunkZ << 4) + r.nextInt(16)));
|
||||
List<Worm.WormPoint> points = new ArrayList<>();
|
||||
for(int i = 0; i < carving.getLength(); i++) {
|
||||
carving.step();
|
||||
TerraBiome biome = provider.getBiome(carving.getRunning(), w.getSeed());
|
||||
/*
|
||||
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop if we enter a biome this carver is not present in
|
||||
if(!((UserDefinedBiome) biome).getConfig().getCarvers().containsKey(CarverCache.this.carver)) { // Stop
|
||||
if we enter a biome this carver is not present in
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
*/
|
||||
points.add(carving.getPoint());
|
||||
}
|
||||
return points;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
points.add(carving.getPoint());
|
||||
}
|
||||
return points;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ) {
|
||||
return cache.getUnchecked(MathUtil.squash(chunkX, chunkZ));
|
||||
}
|
||||
|
||||
@@ -3,30 +3,33 @@ package com.dfsek.terra.addons.carver;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CarverFactory implements ConfigFactory<CarverTemplate, UserDefinedCarver> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
|
||||
public CarverFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UserDefinedCarver build(CarverTemplate config, TerraPlugin main) throws LoadException {
|
||||
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
||||
double[] start = { config.getStartX(), config.getStartY(), config.getStartZ() };
|
||||
double[] mutate = { config.getMutateX(), config.getMutateY(), config.getMutateZ() };
|
||||
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
||||
long hash = MathUtil.hashToLong(config.getID());
|
||||
UserDefinedCarver carver;
|
||||
try {
|
||||
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, new Scope(), hash, config.getCutTop(), config.getCutBottom(), config, main);
|
||||
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, new Scope(), hash,
|
||||
config.getCutTop(), config.getCutBottom(), config, main);
|
||||
} catch(ParseException e) {
|
||||
throw new LoadException("Unable to parse radius equations", e);
|
||||
}
|
||||
|
||||
@@ -1,52 +1,54 @@
|
||||
package com.dfsek.terra.addons.carver;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes", "RedundantSuppression" })
|
||||
public class CarverPalette {
|
||||
private final boolean blacklist;
|
||||
private final MaterialSet replace;
|
||||
private final TreeMap<Integer, ProbabilityCollection<BlockState>> map = new TreeMap<>();
|
||||
private ProbabilityCollection<BlockState>[] layers;
|
||||
private int offset = 0;
|
||||
|
||||
|
||||
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
this.replace = replaceable;
|
||||
}
|
||||
|
||||
|
||||
public CarverPalette add(ProbabilityCollection<BlockState> collection, int y) {
|
||||
map.put(y, collection);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ProbabilityCollection<BlockState> get(int y) {
|
||||
int index = y + offset;
|
||||
return index >= 0
|
||||
? index < layers.length
|
||||
? layers[index]
|
||||
: layers[layers.length - 1]
|
||||
: layers[0];
|
||||
? index < layers.length
|
||||
? layers[index]
|
||||
: layers[layers.length - 1]
|
||||
: layers[0];
|
||||
}
|
||||
|
||||
|
||||
public boolean canReplace(BlockType material) {
|
||||
return blacklist != replace.contains(material);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the palette to an array.
|
||||
*/
|
||||
public void build() {
|
||||
int min = FastMath.min(map.keySet().stream().min(Integer::compareTo).orElse(0), 0);
|
||||
int max = FastMath.max(map.keySet().stream().max(Integer::compareTo).orElse(255), 255);
|
||||
|
||||
|
||||
layers = new ProbabilityCollection[map.lastKey() + 1 - min];
|
||||
for(int y = min; y <= FastMath.max(map.lastKey(), max); y++) {
|
||||
ProbabilityCollection<BlockState> d = null;
|
||||
|
||||
@@ -4,6 +4,10 @@ package com.dfsek.terra.addons.carver;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
@@ -11,176 +15,174 @@ import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class CarverTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
|
||||
@Value("step")
|
||||
@Default
|
||||
private @Meta int step = 2;
|
||||
|
||||
|
||||
@Value("recalculate-magnitude")
|
||||
@Default
|
||||
private @Meta double recaclulateMagnitude = 4;
|
||||
|
||||
|
||||
@Value("recalculate-direction")
|
||||
@Default
|
||||
private @Meta Range recalc = new ConstantRange(8, 10);
|
||||
|
||||
|
||||
@Value("length")
|
||||
private @Meta Range length;
|
||||
|
||||
|
||||
@Value("start.x")
|
||||
private @Meta double startX;
|
||||
|
||||
|
||||
@Value("start.y")
|
||||
private @Meta double startY;
|
||||
|
||||
|
||||
@Value("start.z")
|
||||
private @Meta double startZ;
|
||||
|
||||
|
||||
@Value("start.radius.x")
|
||||
private @Meta String radMX;
|
||||
|
||||
|
||||
@Value("start.radius.y")
|
||||
private @Meta String radMY;
|
||||
|
||||
|
||||
@Value("start.radius.z")
|
||||
private @Meta String radMZ;
|
||||
|
||||
|
||||
@Value("start.height")
|
||||
private @Meta Range height;
|
||||
|
||||
|
||||
@Value("cut.bottom")
|
||||
@Default
|
||||
private @Meta int cutBottom = 0;
|
||||
|
||||
|
||||
@Value("cut.top")
|
||||
@Default
|
||||
private @Meta int cutTop = 0;
|
||||
|
||||
|
||||
@Value("mutate.x")
|
||||
private @Meta double mutateX;
|
||||
|
||||
|
||||
@Value("mutate.y")
|
||||
private @Meta double mutateY;
|
||||
|
||||
|
||||
@Value("mutate.z")
|
||||
private @Meta double mutateZ;
|
||||
|
||||
|
||||
@Value("palette.top")
|
||||
private @Meta CarverPalette top;
|
||||
|
||||
|
||||
@Value("palette.bottom")
|
||||
private @Meta CarverPalette bottom;
|
||||
|
||||
|
||||
@Value("palette.outer")
|
||||
private @Meta CarverPalette outer;
|
||||
|
||||
|
||||
@Value("palette.inner")
|
||||
private @Meta CarverPalette inner;
|
||||
|
||||
|
||||
@Value("shift")
|
||||
@Default
|
||||
private @Meta Map<@Meta BlockType, @Meta MaterialSet> shift = new HashMap<>();
|
||||
|
||||
|
||||
@Value("update")
|
||||
@Default
|
||||
private @Meta MaterialSet update = new MaterialSet();
|
||||
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public int getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
|
||||
public Range getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
public double getStartX() {
|
||||
return startX;
|
||||
}
|
||||
|
||||
|
||||
public double getStartY() {
|
||||
return startY;
|
||||
}
|
||||
|
||||
|
||||
public double getStartZ() {
|
||||
return startZ;
|
||||
}
|
||||
|
||||
|
||||
public String getRadMX() {
|
||||
return radMX;
|
||||
}
|
||||
|
||||
|
||||
public String getRadMY() {
|
||||
return radMY;
|
||||
}
|
||||
|
||||
|
||||
public String getRadMZ() {
|
||||
return radMZ;
|
||||
}
|
||||
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
public int getCutBottom() {
|
||||
return cutBottom;
|
||||
}
|
||||
|
||||
|
||||
public int getCutTop() {
|
||||
return cutTop;
|
||||
}
|
||||
|
||||
|
||||
public double getMutateX() {
|
||||
return mutateX;
|
||||
}
|
||||
|
||||
|
||||
public double getMutateY() {
|
||||
return mutateY;
|
||||
}
|
||||
|
||||
|
||||
public double getMutateZ() {
|
||||
return mutateZ;
|
||||
}
|
||||
|
||||
|
||||
public CarverPalette getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
public CarverPalette getBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
|
||||
public CarverPalette getOuter() {
|
||||
return outer;
|
||||
}
|
||||
|
||||
|
||||
public CarverPalette getInner() {
|
||||
return inner;
|
||||
}
|
||||
|
||||
|
||||
public Map<BlockType, MaterialSet> getShift() {
|
||||
return shift;
|
||||
}
|
||||
|
||||
|
||||
public MaterialSet getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
|
||||
public Range getRecalc() {
|
||||
return recalc;
|
||||
}
|
||||
|
||||
|
||||
public double getRecaclulateMagnitude() {
|
||||
return recaclulateMagnitude;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.dfsek.terra.addons.carver;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -11,20 +17,17 @@ import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.generator.Chunkified;
|
||||
import com.dfsek.terra.api.world.generator.GenerationStage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class CavePopulator implements GenerationStage, Chunkified {
|
||||
private static final Map<BlockType, BlockState> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
|
||||
private static final Map<BlockType, BlockState> shiftStorage = new HashMap<>();
|
||||
// Persist BlockData created for shifts, to avoid re-calculating each time.
|
||||
private final TerraPlugin main;
|
||||
|
||||
|
||||
public CavePopulator(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Chunk chunk) {
|
||||
@@ -32,7 +35,7 @@ public class CavePopulator implements GenerationStage, Chunkified {
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
WorldConfig config = world.getConfig();
|
||||
if(config.disableCarving()) return;
|
||||
|
||||
|
||||
for(UserDefinedCarver c : config.getRegistry(UserDefinedCarver.class).entries()) {
|
||||
CarverTemplate template = c.getConfig();
|
||||
Map<Vector3, BlockState> shiftCandidate = new HashMap<>();
|
||||
@@ -43,25 +46,29 @@ public class CavePopulator implements GenerationStage, Chunkified {
|
||||
switch(type) {
|
||||
case CENTER:
|
||||
if(template.getInner().canReplace(re)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getInner().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(),
|
||||
template.getInner().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
|
||||
}
|
||||
break;
|
||||
case WALL:
|
||||
if(template.getOuter().canReplace(re)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getOuter().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(),
|
||||
template.getOuter().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
|
||||
}
|
||||
break;
|
||||
case TOP:
|
||||
if(template.getTop().canReplace(re)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getTop().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(),
|
||||
template.getTop().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
|
||||
}
|
||||
break;
|
||||
case BOTTOM:
|
||||
if(template.getBottom().canReplace(re)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getBottom().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(),
|
||||
template.getBottom().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
|
||||
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
|
||||
}
|
||||
break;
|
||||
@@ -73,16 +80,19 @@ public class CavePopulator implements GenerationStage, Chunkified {
|
||||
Vector3 mut = l.clone();
|
||||
BlockState orig = chunk.getBlock(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(mut.getY() > world.getMinHeight() && chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).matches(orig));
|
||||
while(mut.getY() > world.getMinHeight() && chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).matches(
|
||||
orig));
|
||||
try {
|
||||
if(template.getShift().get(entry.getValue().getBlockType()).contains(chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).getBlockType())) {
|
||||
chunk.setBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
|
||||
if(template.getShift().get(entry.getValue().getBlockType()).contains(
|
||||
chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).getBlockType())) {
|
||||
chunk.setBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ(),
|
||||
shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
|
||||
}
|
||||
} catch(NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,6 @@ import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.terra.addons.carver.carving.Carver;
|
||||
import com.dfsek.terra.addons.carver.carving.Worm;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,6 +12,15 @@ import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.addons.carver.carving.Carver;
|
||||
import com.dfsek.terra.addons.carver.carving.Worm;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.ConstantRange;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public class UserDefinedCarver extends Carver {
|
||||
private final double[] start; // 0, 1, 2 = x, y, z.
|
||||
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
||||
@@ -30,14 +32,15 @@ public class UserDefinedCarver extends Carver {
|
||||
private final Expression xRad;
|
||||
private final Expression yRad;
|
||||
private final Expression zRad;
|
||||
|
||||
|
||||
private final Map<Long, CarverCache> cacheMap = new ConcurrentHashMap<>();
|
||||
private final TerraPlugin main;
|
||||
private double step = 2;
|
||||
private Range recalc = new ConstantRange(8, 10);
|
||||
private double recalcMagnitude = 3;
|
||||
|
||||
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash, int topCut, int bottomCut, CarverTemplate config, TerraPlugin main) throws ParseException {
|
||||
|
||||
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash,
|
||||
int topCut, int bottomCut, CarverTemplate config, TerraPlugin main) throws ParseException {
|
||||
super(height.getMin(), height.getMax());
|
||||
this.length = length;
|
||||
this.start = start;
|
||||
@@ -47,41 +50,27 @@ public class UserDefinedCarver extends Carver {
|
||||
this.bottomCut = bottomCut;
|
||||
this.config = config;
|
||||
this.main = main;
|
||||
|
||||
|
||||
Parser p = new Parser();
|
||||
|
||||
|
||||
Scope s = new Scope().withParent(parent);
|
||||
|
||||
|
||||
|
||||
|
||||
s.addInvocationVariable("x");
|
||||
s.addInvocationVariable("y");
|
||||
s.addInvocationVariable("z");
|
||||
|
||||
|
||||
s.addInvocationVariable("length");
|
||||
s.addInvocationVariable("position");
|
||||
s.addInvocationVariable("seed");
|
||||
|
||||
|
||||
|
||||
|
||||
xRad = p.parse(radii.get(0), s);
|
||||
yRad = p.parse(radii.get(1), s);
|
||||
zRad = p.parse(radii.get(2), s);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector3 vector) {
|
||||
Random r = new Random(l + hash);
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, topCut, bottomCut, l);
|
||||
}
|
||||
|
||||
public void setStep(double step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public void setRecalc(Range recalc) {
|
||||
this.recalc = recalc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector3, CarvingType> consumer) {
|
||||
synchronized(cacheMap) {
|
||||
@@ -91,7 +80,8 @@ public class UserDefinedCarver extends Carver {
|
||||
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
|
||||
cache.getPoints(x, z).forEach(point -> {
|
||||
Vector3 origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ) // We only want to carve this chunk.
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) !=
|
||||
chunkZ) // We only want to carve this chunk.
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer, w);
|
||||
});
|
||||
@@ -99,24 +89,39 @@ public class UserDefinedCarver extends Carver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRecalcMagnitude(double recalcMagnitude) {
|
||||
this.recalcMagnitude = recalcMagnitude;
|
||||
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector3 vector) {
|
||||
Random r = new Random(l + hash);
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, topCut, bottomCut, l);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||
/*BiomeTemplate conf = ((UserDefinedBiome) main.getWorld(w).getBiomeProvider().getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8)).getConfig();
|
||||
/*BiomeTemplate conf = ((UserDefinedBiome) main.getWorld(w).getBiomeProvider().getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8))
|
||||
.getConfig();
|
||||
if(conf.getCarvers().get(this) != null) {
|
||||
return new Random(random.nextLong() + hash).nextInt(100) < conf.getCarvers().get(this);
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void setRecalc(Range recalc) {
|
||||
this.recalc = recalc;
|
||||
}
|
||||
|
||||
public void setRecalcMagnitude(double recalcMagnitude) {
|
||||
this.recalcMagnitude = recalcMagnitude;
|
||||
}
|
||||
|
||||
public void setStep(double step) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public CarverTemplate getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
private class UserDefinedWorm extends Worm {
|
||||
private final Vector3 direction;
|
||||
private final Vector3 origin;
|
||||
@@ -124,41 +129,44 @@ public class UserDefinedCarver extends Carver {
|
||||
private int steps;
|
||||
private int nextDirection = 0;
|
||||
private double[] currentRotation = new double[3];
|
||||
|
||||
|
||||
public UserDefinedWorm(int length, Random r, Vector3 origin, int topCut, int bottomCut, long seed) {
|
||||
super(length, r, origin);
|
||||
this.origin = origin;
|
||||
this.seed = seed;
|
||||
super.setTopCut(topCut);
|
||||
super.setBottomCut(bottomCut);
|
||||
direction = new Vector3((r.nextDouble() - 0.5D) * start[0], (r.nextDouble() - 0.5D) * start[1], (r.nextDouble() - 0.5D) * start[2]).normalize().multiply(step);
|
||||
double[] args = {origin.getX(), origin.getY(), origin.getZ(), length, 0, seed};
|
||||
setRadius(new int[] {(int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args))});
|
||||
direction = new Vector3((r.nextDouble() - 0.5D) * start[0], (r.nextDouble() - 0.5D) * start[1],
|
||||
(r.nextDouble() - 0.5D) * start[2]).normalize().multiply(step);
|
||||
double[] args = { origin.getX(), origin.getY(), origin.getZ(), length, 0, seed };
|
||||
setRadius(new int[]{ (int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args)) });
|
||||
}
|
||||
|
||||
@Override
|
||||
public WormPoint getPoint() {
|
||||
return new WormPoint(getRunning().clone(), getRadius(), config.getCutTop(), config.getCutBottom());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void step() {
|
||||
if(steps == nextDirection) {
|
||||
direction.rotateAroundX(FastMath.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||
direction.rotateAroundY(FastMath.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||
direction.rotateAroundZ(FastMath.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
||||
currentRotation = new double[] {(getRandom().nextGaussian()) * mutate[0],
|
||||
currentRotation = new double[]{
|
||||
(getRandom().nextGaussian()) * mutate[0],
|
||||
(getRandom().nextGaussian()) * mutate[1],
|
||||
(getRandom().nextGaussian()) * mutate[2]};
|
||||
(getRandom().nextGaussian()) * mutate[2]
|
||||
};
|
||||
nextDirection += recalc.get(getRandom());
|
||||
}
|
||||
steps++;
|
||||
double[] args = {origin.getX(), origin.getY(), origin.getZ(), getLength(), steps, seed};
|
||||
setRadius(new int[] {(int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args))});
|
||||
double[] args = { origin.getX(), origin.getY(), origin.getZ(), getLength(), steps, seed };
|
||||
setRadius(new int[]{ (int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args)) });
|
||||
direction.rotateAroundX(FastMath.toRadians(currentRotation[0] * mutate[0]));
|
||||
direction.rotateAroundY(FastMath.toRadians(currentRotation[1] * mutate[1]));
|
||||
direction.rotateAroundZ(FastMath.toRadians(currentRotation[2] * mutate[2]));
|
||||
getRunning().add(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WormPoint getPoint() {
|
||||
return new WormPoint(getRunning().clone(), getRadius(), config.getCutTop(), config.getCutBottom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
package com.dfsek.terra.addons.carver.carving;
|
||||
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public abstract class Carver {
|
||||
private final int minY;
|
||||
private final int maxY;
|
||||
private final double sixtyFourSq = FastMath.pow(64, 2);
|
||||
private int carvingRadius = 4;
|
||||
|
||||
|
||||
public Carver(int minY, int maxY) {
|
||||
this.minY = minY;
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
|
||||
public abstract void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector3, CarvingType> consumer);
|
||||
|
||||
|
||||
public int getCarvingRadius() {
|
||||
return carvingRadius;
|
||||
}
|
||||
|
||||
|
||||
public void setCarvingRadius(int carvingRadius) {
|
||||
this.carvingRadius = carvingRadius;
|
||||
}
|
||||
|
||||
|
||||
public abstract Worm getWorm(long seed, Vector3 l);
|
||||
|
||||
|
||||
public abstract boolean isChunkCarved(World w, int chunkX, int chunkZ, Random r);
|
||||
|
||||
|
||||
public enum CarvingType {
|
||||
CENTER, WALL, TOP, BOTTOM
|
||||
CENTER,
|
||||
WALL,
|
||||
TOP,
|
||||
BOTTOM
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.dfsek.terra.addons.carver.carving;
|
||||
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
|
||||
public abstract class Worm {
|
||||
private final Random r;
|
||||
private final Vector3 origin;
|
||||
@@ -14,78 +16,73 @@ public abstract class Worm {
|
||||
private final int length;
|
||||
private int topCut = 0;
|
||||
private int bottomCut = 0;
|
||||
private int[] radius = new int[] {0, 0, 0};
|
||||
|
||||
private int[] radius = { 0, 0, 0 };
|
||||
|
||||
public Worm(int length, Random r, Vector3 origin) {
|
||||
this.r = r;
|
||||
this.length = length;
|
||||
this.origin = origin;
|
||||
this.running = origin;
|
||||
}
|
||||
|
||||
|
||||
public abstract void step();
|
||||
|
||||
public void setBottomCut(int bottomCut) {
|
||||
this.bottomCut = bottomCut;
|
||||
}
|
||||
|
||||
|
||||
public void setTopCut(int topCut) {
|
||||
this.topCut = topCut;
|
||||
}
|
||||
|
||||
|
||||
public Vector3 getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
public Vector3 getRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
public WormPoint getPoint() {
|
||||
return new WormPoint(running, radius, topCut, bottomCut);
|
||||
}
|
||||
|
||||
|
||||
public int[] getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
|
||||
public void setRadius(int[] radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
|
||||
public Random getRandom() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public abstract void step();
|
||||
|
||||
|
||||
|
||||
public static class WormPoint {
|
||||
private final Vector3 origin;
|
||||
private final int topCut;
|
||||
private final int bottomCut;
|
||||
private final int[] rad;
|
||||
|
||||
|
||||
public WormPoint(Vector3 origin, int[] rad, int topCut, int bottomCut) {
|
||||
this.origin = origin;
|
||||
this.rad = rad;
|
||||
this.topCut = topCut;
|
||||
this.bottomCut = bottomCut;
|
||||
}
|
||||
|
||||
|
||||
private static double ellipseEquation(int x, int y, int z, double xr, double yr, double zr) {
|
||||
return (FastMath.pow2(x) / FastMath.pow2(xr + 0.5D)) + (FastMath.pow2(y) / FastMath.pow2(yr + 0.5D)) + (FastMath.pow2(z) / FastMath.pow2(zr + 0.5D));
|
||||
return (FastMath.pow2(x) / FastMath.pow2(xr + 0.5D)) + (FastMath.pow2(y) / FastMath.pow2(yr + 0.5D)) + (FastMath.pow2(z) /
|
||||
FastMath.pow2(
|
||||
zr + 0.5D));
|
||||
}
|
||||
|
||||
public Vector3 getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public int getRadius(int index) {
|
||||
return rad[index];
|
||||
}
|
||||
|
||||
|
||||
public void carve(int chunkX, int chunkZ, BiConsumer<Vector3, Carver.CarvingType> consumer, World world) {
|
||||
int xRad = getRadius(0);
|
||||
int yRad = getRadius(1);
|
||||
@@ -101,8 +98,10 @@ public abstract class Worm {
|
||||
if(position.getY() < world.getMinHeight() || position.getY() > world.getMaxHeight()) continue;
|
||||
double eq = ellipseEquation(x, y, z, xRad, yRad, zRad);
|
||||
if(eq <= 1 &&
|
||||
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {
|
||||
consumer.accept(new Vector3(position.getBlockX() - originX, position.getBlockY(), position.getBlockZ() - originZ), Carver.CarvingType.CENTER);
|
||||
y >= -yRad - 1 + bottomCut && y <= yRad + 1 - topCut) {
|
||||
consumer.accept(
|
||||
new Vector3(position.getBlockX() - originX, position.getBlockY(), position.getBlockZ() - originZ),
|
||||
Carver.CarvingType.CENTER);
|
||||
} else if(eq <= 1.5) {
|
||||
Carver.CarvingType type = Carver.CarvingType.WALL;
|
||||
if(y <= -yRad - 1 + bottomCut) {
|
||||
@@ -110,11 +109,21 @@ public abstract class Worm {
|
||||
} else if(y >= yRad + 1 - topCut) {
|
||||
type = Carver.CarvingType.TOP;
|
||||
}
|
||||
consumer.accept(new Vector3(position.getBlockX() - originX, position.getBlockY(), position.getBlockZ() - originZ), type);
|
||||
consumer.accept(
|
||||
new Vector3(position.getBlockX() - originX, position.getBlockY(), position.getBlockZ() - originZ),
|
||||
type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public int getRadius(int index) {
|
||||
return rad[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra.addons.feature.distributor;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.config.AndDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.NoiseDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.OrDistributorTemplate;
|
||||
@@ -19,31 +22,32 @@ import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Addon("config-distributors")
|
||||
@Version("1.0.0")
|
||||
@Author("Terra")
|
||||
public class DistributorAddon extends TerraAddon {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<Distributor>>> DISTRIBUTOR_TOKEN = new TypeKey<>() {};
|
||||
public static final TypeKey<Supplier<ObjectTemplate<Distributor>>> DISTRIBUTOR_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Distributor>>> distributorRegistry = event.getPack().getOrCreateRegistry(DISTRIBUTOR_TOKEN);
|
||||
distributorRegistry.register("NOISE", NoiseDistributorTemplate::new);
|
||||
distributorRegistry.register("POINTS", PointSetDistributorTemplate::new);
|
||||
distributorRegistry.register("AND", AndDistributorTemplate::new);
|
||||
distributorRegistry.register("OR", OrDistributorTemplate::new);
|
||||
|
||||
event.getPack()
|
||||
.applyLoader(Point.class, PointTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Distributor>>> distributorRegistry = event.getPack().getOrCreateRegistry(
|
||||
DISTRIBUTOR_TOKEN);
|
||||
distributorRegistry.register("NOISE", NoiseDistributorTemplate::new);
|
||||
distributorRegistry.register("POINTS", PointSetDistributorTemplate::new);
|
||||
distributorRegistry.register("AND", AndDistributorTemplate::new);
|
||||
distributorRegistry.register("OR", OrDistributorTemplate::new);
|
||||
|
||||
event.getPack()
|
||||
.applyLoader(Point.class, PointTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,18 @@ import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AndDistributorTemplate implements ObjectTemplate<Distributor>, ValidatedConfigTemplate {
|
||||
@Value("distributors")
|
||||
private @Meta List<@Meta Distributor> distributors;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
Distributor current = distributors.remove(0);
|
||||
@@ -22,7 +24,7 @@ public class AndDistributorTemplate implements ObjectTemplate<Distributor>, Vali
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(distributors.isEmpty()) throw new ValidationException("AND Distributor must specify at least 1 distributor.");
|
||||
|
||||
@@ -3,19 +3,20 @@ package com.dfsek.terra.addons.feature.distributor.config;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.distributors.NoiseDistributor;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
public class NoiseDistributorTemplate implements ObjectTemplate<Distributor> {
|
||||
@Value("distribution")
|
||||
private @Meta NoiseSampler noise;
|
||||
|
||||
public class NoiseDistributorTemplate implements ObjectTemplate<Distributor> {
|
||||
@Value("threshold")
|
||||
@Default
|
||||
private @Meta double threshold = 0;
|
||||
|
||||
private final @Meta double threshold = 0;
|
||||
@Value("distribution")
|
||||
private @Meta NoiseSampler noise;
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
return new NoiseDistributor(noise, threshold);
|
||||
|
||||
@@ -4,16 +4,18 @@ import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OrDistributorTemplate implements ObjectTemplate<Distributor>, ValidatedConfigTemplate {
|
||||
@Value("distributors")
|
||||
private @Meta List<@Meta Distributor> distributors;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
Distributor current = distributors.remove(0);
|
||||
@@ -22,7 +24,7 @@ public class OrDistributorTemplate implements ObjectTemplate<Distributor>, Valid
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(distributors.isEmpty()) throw new ValidationException("AND Distributor must specify at least 1 distributor.");
|
||||
|
||||
@@ -2,17 +2,19 @@ package com.dfsek.terra.addons.feature.distributor.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.distributors.PointSetDistributor;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributorTemplate implements ObjectTemplate<Distributor> {
|
||||
@Value("points")
|
||||
private @Meta Set<@Meta Point> points;
|
||||
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
return new PointSetDistributor(points);
|
||||
|
||||
@@ -3,15 +3,17 @@ package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
|
||||
public class NoiseDistributor implements Distributor {
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
private final double threshold;
|
||||
|
||||
public NoiseDistributor(NoiseSampler sampler, double threshold) {
|
||||
this.sampler = sampler;
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int z, long seed) {
|
||||
return sampler.getNoiseSeeded(seed, x, z) > threshold;
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributor implements Distributor {
|
||||
private final Set<Point> points;
|
||||
|
||||
|
||||
public PointSetDistributor(Set<Point> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int z, long seed) {
|
||||
return points.contains(new Point(x, z));
|
||||
|
||||
@@ -3,28 +3,28 @@ package com.dfsek.terra.addons.feature.distributor.util;
|
||||
public class Point {
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
|
||||
private final int hash;
|
||||
|
||||
|
||||
public Point(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.hash = 31 * x + z;
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Point)) return false;
|
||||
|
||||
@@ -2,15 +2,17 @@ package com.dfsek.terra.addons.feature.distributor.util;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
|
||||
|
||||
public class PointTemplate implements ObjectTemplate<Point> {
|
||||
@Value("x")
|
||||
private @Meta int x;
|
||||
|
||||
|
||||
@Value("z")
|
||||
private @Meta int z;
|
||||
|
||||
|
||||
@Override
|
||||
public Point get() {
|
||||
return new Point(x, z);
|
||||
|
||||
@@ -8,30 +8,32 @@ 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) {
|
||||
|
||||
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;
|
||||
|
||||
@@ -9,19 +9,20 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
|
||||
@Addon("config-feature")
|
||||
@Version("1.0.0")
|
||||
@Author("Terra")
|
||||
public class FeatureAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().registerConfigType(new FeatureConfigType(), "FEATURE", 2))
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> event.getPack().registerConfigType(new FeatureConfigType(), "FEATURE", 2))
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.addons.feature;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -8,30 +10,30 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.structure.feature.Feature;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FeatureConfigType implements ConfigType<FeatureTemplate, Feature> {
|
||||
public static final TypeKey<Feature> FEATURE_TYPE_KEY = new TypeKey<>() {};
|
||||
|
||||
public static final TypeKey<Feature> FEATURE_TYPE_KEY = new TypeKey<>() {
|
||||
};
|
||||
|
||||
private final FeatureFactory factory = new FeatureFactory();
|
||||
|
||||
@Override
|
||||
public FeatureTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FeatureTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FeatureTemplate, Feature> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Feature> getTypeKey() {
|
||||
return FEATURE_TYPE_KEY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Feature>> registrySupplier(ConfigPack pack) {
|
||||
return pack.getRegistryFactory()::create;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FeatureTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FeatureTemplate, Feature> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Feature> getTypeKey() {
|
||||
return FEATURE_TYPE_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.dfsek.terra.addons.feature;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
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, TerraPlugin main) throws LoadException {
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.addons.feature;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
@@ -11,40 +11,41 @@ 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;
|
||||
}
|
||||
|
||||
@@ -11,22 +11,23 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
|
||||
@Addon("config-flora")
|
||||
@Author("Terra")
|
||||
@Version("0.1.0")
|
||||
public class FloraAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new FloraConfigType(), "FLORA", 2);
|
||||
event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new FloraConfigType(), "FLORA", 2);
|
||||
event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.addons.flora;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -8,30 +10,29 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
|
||||
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
private final FloraFactory factory = new FloraFactory();
|
||||
|
||||
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
@Override
|
||||
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FloraTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FloraTemplate, Flora> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Flora> getTypeKey() {
|
||||
return FLORA_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Flora>> registrySupplier(ConfigPack pack) {
|
||||
return pack.getRegistryFactory()::create;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FloraTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FloraTemplate, Flora> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Flora> getTypeKey() {
|
||||
return FLORA_TYPE_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
|
||||
|
||||
public class FloraFactory implements ConfigFactory<FloraTemplate, Flora> {
|
||||
@Override
|
||||
public TerraFlora build(FloraTemplate config, TerraPlugin main) {
|
||||
return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist(), config.getIrrigableOffset(), main, config.getNoiseDistribution());
|
||||
return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(),
|
||||
config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(),
|
||||
config.isSpawnBlacklist(), config.getIrrigableOffset(), main, config.getNoiseDistribution());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.dfsek.terra.addons.flora;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import com.dfsek.terra.addons.flora.flora.gen.TerraFlora;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
@@ -10,108 +13,107 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
public class FloraTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
|
||||
@Value("spawnable")
|
||||
private @Meta MaterialSet spawnable;
|
||||
|
||||
|
||||
@Value("spawn-blacklist")
|
||||
@Default
|
||||
private @Meta boolean spawnBlacklist = false;
|
||||
|
||||
|
||||
|
||||
|
||||
@Value("replaceable")
|
||||
@Default
|
||||
private @Meta MaterialSet replaceable = MaterialSet.empty();
|
||||
|
||||
|
||||
@Value("irrigable")
|
||||
@Default
|
||||
private @Meta MaterialSet irrigable = null;
|
||||
|
||||
private @Meta MaterialSet irrigable;
|
||||
|
||||
@Value("rotatable")
|
||||
@Default
|
||||
private @Meta MaterialSet rotatable = MaterialSet.empty();
|
||||
|
||||
|
||||
@Value("physics")
|
||||
@Default
|
||||
private @Meta boolean doPhysics = false;
|
||||
|
||||
|
||||
@Value("ceiling")
|
||||
@Default
|
||||
private @Meta boolean ceiling = false;
|
||||
|
||||
|
||||
@Value("search")
|
||||
@Default
|
||||
private TerraFlora.@Meta Search search = TerraFlora.Search.UP;
|
||||
|
||||
|
||||
@Value("max-placements")
|
||||
@Default
|
||||
private @Meta int maxPlacements = -1;
|
||||
|
||||
|
||||
@Value("irrigable-offset")
|
||||
@Default
|
||||
private @Meta int irrigableOffset;
|
||||
|
||||
|
||||
@Value("layers")
|
||||
private @Meta List<@Meta BlockLayer> layers;
|
||||
|
||||
|
||||
@Value("layer-distribution")
|
||||
private @Meta NoiseSampler noiseDistribution;
|
||||
|
||||
public NoiseSampler getNoiseDistribution() {
|
||||
return noiseDistribution;
|
||||
}
|
||||
|
||||
public List<BlockLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public int getIrrigableOffset() {
|
||||
return irrigableOffset;
|
||||
}
|
||||
|
||||
public TerraFlora.Search getSearch() {
|
||||
return search;
|
||||
}
|
||||
|
||||
public int getMaxPlacements() {
|
||||
return maxPlacements;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public MaterialSet getIrrigable() {
|
||||
return irrigable;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public boolean doPhysics() {
|
||||
return doPhysics;
|
||||
}
|
||||
|
||||
|
||||
public NoiseSampler getNoiseDistribution() {
|
||||
return noiseDistribution;
|
||||
}
|
||||
|
||||
public List<BlockLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public int getIrrigableOffset() {
|
||||
return irrigableOffset;
|
||||
}
|
||||
|
||||
public TerraFlora.Search getSearch() {
|
||||
return search;
|
||||
}
|
||||
|
||||
public int getMaxPlacements() {
|
||||
return maxPlacements;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public MaterialSet getIrrigable() {
|
||||
return irrigable;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isCeiling() {
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSpawnBlacklist() {
|
||||
return spawnBlacklist;
|
||||
}
|
||||
|
||||
|
||||
public MaterialSet getRotatable() {
|
||||
return rotatable;
|
||||
}
|
||||
|
||||
@@ -2,18 +2,20 @@ package com.dfsek.terra.addons.flora.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class BlockLayerTemplate implements ObjectTemplate<BlockLayer> {
|
||||
@Value("layers")
|
||||
private @Meta int layers;
|
||||
|
||||
|
||||
@Value("materials")
|
||||
private @Meta ProbabilityCollection<BlockState> data;
|
||||
|
||||
|
||||
@Override
|
||||
public BlockLayer get() {
|
||||
return new BlockLayer(layers, data);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user