mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 06:40:55 +00:00
remove flora generation addon
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.properties.Properties;
|
|
||||||
|
|
||||||
|
|
||||||
public class BiomeFlora implements Properties {
|
|
||||||
private final List<FloraLayer> layers;
|
|
||||||
|
|
||||||
public BiomeFlora(List<FloraLayer> layers) {
|
|
||||||
this.layers = layers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FloraLayer> getLayers() {
|
|
||||||
return layers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
import com.dfsek.tectonic.annotations.Default;
|
|
||||||
import com.dfsek.tectonic.annotations.Value;
|
|
||||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.config.meta.Meta;
|
|
||||||
|
|
||||||
|
|
||||||
public class BiomeFloraTemplate implements ObjectTemplate<BiomeFlora> {
|
|
||||||
@Value("flora")
|
|
||||||
@Default
|
|
||||||
private @Meta List<@Meta FloraLayer> flora = Collections.emptyList();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BiomeFlora get() {
|
|
||||||
return new BiomeFlora(flora);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
|
||||||
import com.dfsek.terra.api.addon.TerraAddon;
|
|
||||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
|
||||||
import com.dfsek.terra.api.addon.annotations.Author;
|
|
||||||
import com.dfsek.terra.api.addon.annotations.Version;
|
|
||||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
|
||||||
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;
|
|
||||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
|
||||||
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
|
||||||
|
|
||||||
|
|
||||||
@Addon("generation-stage-flora")
|
|
||||||
@Version("1.0.0")
|
|
||||||
@Author("Terra")
|
|
||||||
public class FloraGenerationAddon extends TerraAddon {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private TerraPlugin main;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
main.getEventManager()
|
|
||||||
.getHandler(FunctionalEventHandler.class)
|
|
||||||
.register(this, ConfigPackPreLoadEvent.class)
|
|
||||||
.then(event -> {
|
|
||||||
event.getPack().applyLoader(FloraLayer.class, FloraLayerLoader::new);
|
|
||||||
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("FLORA",
|
|
||||||
pack -> new FloraGenerationStage(main));
|
|
||||||
})
|
|
||||||
.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 BiomeFloraTemplate()).get());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.failThrough();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
|
||||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
|
||||||
import com.dfsek.terra.api.util.PopulationUtil;
|
|
||||||
import com.dfsek.terra.api.vector.Vector2;
|
|
||||||
import com.dfsek.terra.api.world.Chunk;
|
|
||||||
import com.dfsek.terra.api.world.World;
|
|
||||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
|
||||||
import com.dfsek.terra.api.world.generator.GenerationStage;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Populates Flora
|
|
||||||
*/
|
|
||||||
public class FloraGenerationStage implements GenerationStage {
|
|
||||||
private final TerraPlugin main;
|
|
||||||
|
|
||||||
public FloraGenerationStage(TerraPlugin main) {
|
|
||||||
this.main = main;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("try")
|
|
||||||
@Override
|
|
||||||
public void populate(@NotNull World world, @NotNull Chunk chunk) {
|
|
||||||
try(ProfileFrame ignore = main.getProfiler().profile("flora")) {
|
|
||||||
if(world.getConfig().disableFlora()) return;
|
|
||||||
|
|
||||||
long seed = world.getSeed();
|
|
||||||
BiomeProvider provider = world.getBiomeProvider();
|
|
||||||
Map<Vector2, List<FloraLayer>> layers = new HashMap<>();
|
|
||||||
for(int x = 0; x < 16; x++) {
|
|
||||||
for(int z = 0; z < 16; z++) {
|
|
||||||
Vector2 l = new Vector2(x, z);
|
|
||||||
layers.put(l, provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, seed)
|
|
||||||
.getContext()
|
|
||||||
.get(BiomeFlora.class)
|
|
||||||
.getLayers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Random random = PopulationUtil.getRandom(chunk);
|
|
||||||
|
|
||||||
int iter = 0;
|
|
||||||
boolean finished = false;
|
|
||||||
while(!finished) {
|
|
||||||
finished = true;
|
|
||||||
for(Map.Entry<Vector2, List<FloraLayer>> entry : layers.entrySet()) {
|
|
||||||
if(entry.getValue().size() <= iter) continue;
|
|
||||||
finished = false;
|
|
||||||
FloraLayer layer = entry.getValue().get(iter);
|
|
||||||
if(layer.getDensity() >= random.nextDouble() * 100D) layer.place(chunk, entry.getKey());
|
|
||||||
}
|
|
||||||
iter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
|
||||||
import com.dfsek.terra.api.util.Range;
|
|
||||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
|
||||||
import com.dfsek.terra.api.vector.Vector2;
|
|
||||||
import com.dfsek.terra.api.world.Chunk;
|
|
||||||
import com.dfsek.terra.api.world.Flora;
|
|
||||||
|
|
||||||
|
|
||||||
public class FloraLayer {
|
|
||||||
protected final double density;
|
|
||||||
protected final Range level;
|
|
||||||
protected final ProbabilityCollection<Flora> layer;
|
|
||||||
protected final NoiseSampler noise;
|
|
||||||
|
|
||||||
public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, NoiseSampler noise) {
|
|
||||||
this.density = density;
|
|
||||||
this.level = level;
|
|
||||||
this.layer = layer;
|
|
||||||
this.noise = noise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void place(Chunk chunk, Vector2 coords) {
|
|
||||||
int cx = (chunk.getX() << 4);
|
|
||||||
int cz = (chunk.getZ() << 4);
|
|
||||||
Flora item = layer.get(noise, cx + coords.getX(), cz + coords.getZ(), chunk.getWorld().getSeed());
|
|
||||||
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(
|
|
||||||
block -> item.plant(block.add(cx, 0, cz), chunk.getWorld()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public NoiseSampler getNoise() {
|
|
||||||
return noise;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDensity() {
|
|
||||||
return density;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Range getLevel() {
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProbabilityCollection<Flora> getLayer() {
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
package com.dfsek.terra.addons.generation.flora;
|
|
||||||
|
|
||||||
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.util.Range;
|
|
||||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
|
||||||
import com.dfsek.terra.api.world.Flora;
|
|
||||||
|
|
||||||
|
|
||||||
public class FloraLayerLoader implements ObjectTemplate<FloraLayer> {
|
|
||||||
@Value("density")
|
|
||||||
private @Meta double density;
|
|
||||||
|
|
||||||
@Value("y")
|
|
||||||
private @Meta Range y;
|
|
||||||
|
|
||||||
@Value("items")
|
|
||||||
private @Meta ProbabilityCollection<@Meta Flora> items;
|
|
||||||
|
|
||||||
@Value("distribution")
|
|
||||||
private @Meta NoiseSampler distribution;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FloraLayer get() {
|
|
||||||
return new FloraLayer(density, y, items, distribution);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user