mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
More flora controls
This commit is contained in:
@@ -20,8 +20,7 @@ public class TerraProfiler extends WorldProfiler {
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "CaveTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime")
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "SnowTime");
|
||||
.addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime");
|
||||
}
|
||||
|
||||
public static TerraProfiler fromWorld(World w) {
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public class CarverPalette {
|
||||
private final boolean blacklist;
|
||||
private final Set<Material> replace;
|
||||
private final MaterialSet replace;
|
||||
private final TreeMap<Integer, ProbabilityCollection<BlockData>> map = new TreeMap<>();
|
||||
private ProbabilityCollection<BlockData>[] layers;
|
||||
|
||||
public CarverPalette(Set<Material> replaceable, boolean blacklist) {
|
||||
public CarverPalette(MaterialSet replaceable, boolean blacklist) {
|
||||
this.blacklist = blacklist;
|
||||
this.replace = replaceable;
|
||||
}
|
||||
|
||||
@@ -50,42 +50,6 @@ public class BiomeInfoCommand extends WorldCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// Get snow info
|
||||
/*
|
||||
BiomeSnowConfig snowConfig = bio.getSnow();
|
||||
StringBuilder snowMessage = new StringBuilder("----------Snow----------\n");
|
||||
int comp = snowConfig.getSnowChance(0);
|
||||
int compHeight = 0;
|
||||
boolean changed = false;
|
||||
// Rebuild original snow data (rather than simply getting it, since it may have changed during initial assembly, if any overlaps occurred)
|
||||
for(int i = 0; i <= 255; i++) {
|
||||
int snow = snowConfig.getSnowChance(i);
|
||||
if(snow != comp) {
|
||||
changed = true;
|
||||
snowMessage.append("Y=")
|
||||
.append(compHeight)
|
||||
.append("-")
|
||||
.append(i)
|
||||
.append(": ")
|
||||
.append(comp)
|
||||
.append("% snow\n");
|
||||
comp = snow;
|
||||
compHeight = i;
|
||||
}
|
||||
}
|
||||
if(!changed) {
|
||||
snowMessage.append("Y=0")
|
||||
.append("-255")
|
||||
.append(": ")
|
||||
.append(comp)
|
||||
.append("% snow\n");
|
||||
}
|
||||
sender.sendMessage(snowMessage.toString());
|
||||
|
||||
sender.sendMessage("Do snow: " + snowConfig.doSnow());
|
||||
|
||||
*/
|
||||
// TODO: implementation
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ public class FloraFactory implements TerraFactory<FloraTemplate, Flora> {
|
||||
for(PaletteLayer layer : config.getFloraPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize());
|
||||
}
|
||||
return new TerraFlora(palette, config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable());
|
||||
return new TerraFlora(palette, config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class FloraSearchLoader implements TypeLoader<TerraFlora.Search> {
|
||||
@Override
|
||||
public TerraFlora.Search load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
return TerraFlora.Search.valueOf((String) o);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.dfsek.terra.config.loaders;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||
@Override
|
||||
public MaterialSet load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
List<String> stringData = (List<String>) o;
|
||||
MaterialSet set = new MaterialSet();
|
||||
|
||||
for(String string : stringData) {
|
||||
try {
|
||||
if(string.startsWith("#")) set.addTag(string.substring(1));
|
||||
else set.add((Material) configLoader.loadType(Material.class, string));
|
||||
} catch(NullPointerException e) {
|
||||
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,13 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import org.bukkit.Material;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CarverPaletteLoader implements TypeLoader<CarverPalette> {
|
||||
@@ -22,7 +21,7 @@ public class CarverPaletteLoader implements TypeLoader<CarverPalette> {
|
||||
@Override
|
||||
public CarverPalette load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Configuration configuration = new Configuration((Map<String, Object>) o);
|
||||
CarverPalette palette = new CarverPalette((Set<Material>) configLoader.loadType(Types.MATERIAL_SET_TYPE, configuration.get("replace")), (Boolean) configuration.get("replace-blacklist"));
|
||||
CarverPalette palette = new CarverPalette((MaterialSet) configLoader.loadType(MaterialSet.class, configuration.get("replace")), (Boolean) configuration.get("replace-blacklist"));
|
||||
|
||||
for(Map<String, Object> map : (List<Map<String, Object>>) configuration.get("layers")) {
|
||||
ProbabilityCollection<BlockData> layer = (ProbabilityCollection<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
|
||||
@@ -4,13 +4,12 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class CarverTemplate extends AbstractableTemplate {
|
||||
@@ -105,12 +104,12 @@ public class CarverTemplate extends AbstractableTemplate {
|
||||
@Value("shift")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Map<Material, Set<Material>> shift = new HashMap<>();
|
||||
private Map<Material, MaterialSet> shift = new HashMap<>();
|
||||
|
||||
@Value("update")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Set<Material> update = new HashSet<>();
|
||||
private MaterialSet update = new MaterialSet();
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
@@ -188,11 +187,11 @@ public class CarverTemplate extends AbstractableTemplate {
|
||||
return inner;
|
||||
}
|
||||
|
||||
public Map<Material, Set<Material>> getShift() {
|
||||
public Map<Material, MaterialSet> getShift() {
|
||||
return shift;
|
||||
}
|
||||
|
||||
public Set<Material> getUpdate() {
|
||||
public MaterialSet getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
public class FloraTemplate extends AbstractableTemplate {
|
||||
@@ -17,17 +17,23 @@ public class FloraTemplate extends AbstractableTemplate {
|
||||
|
||||
@Value("spawnable")
|
||||
@Abstractable
|
||||
private Set<Material> spawnable;
|
||||
private MaterialSet spawnable;
|
||||
|
||||
@Value("spawn-blacklist")
|
||||
@Abstractable
|
||||
@Default
|
||||
private boolean spawnBlacklist = false;
|
||||
|
||||
|
||||
@Value("replaceable")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Set<Material> replaceable = Sets.newHashSet(Material.AIR);
|
||||
private MaterialSet replaceable = MaterialSet.singleton(Material.AIR);
|
||||
|
||||
@Value("irrigable")
|
||||
@Abstractable
|
||||
@Default
|
||||
private Set<Material> irrigable = null;
|
||||
private MaterialSet irrigable = null;
|
||||
|
||||
@Value("layers")
|
||||
@Abstractable
|
||||
@@ -43,15 +49,33 @@ public class FloraTemplate extends AbstractableTemplate {
|
||||
@Default
|
||||
private boolean ceiling = false;
|
||||
|
||||
public Set<Material> getReplaceable() {
|
||||
@Value("search")
|
||||
@Default
|
||||
@Abstractable
|
||||
private TerraFlora.Search search = TerraFlora.Search.UP;
|
||||
|
||||
@Value("max-placements")
|
||||
@Default
|
||||
@Abstractable
|
||||
private int maxPlacements = -1;
|
||||
|
||||
public TerraFlora.Search getSearch() {
|
||||
return search;
|
||||
}
|
||||
|
||||
public int getMaxPlacements() {
|
||||
return maxPlacements;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public Set<Material> getSpawnable() {
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public Set<Material> getIrrigable() {
|
||||
public MaterialSet getIrrigable() {
|
||||
return irrigable;
|
||||
}
|
||||
|
||||
@@ -70,4 +94,8 @@ public class FloraTemplate extends AbstractableTemplate {
|
||||
public boolean isCeiling() {
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
public boolean isSpawnBlacklist() {
|
||||
return spawnBlacklist;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,10 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import org.bukkit.Material;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class OreTemplate extends AbstractableTemplate {
|
||||
@Value("id")
|
||||
@@ -28,7 +24,7 @@ public class OreTemplate extends AbstractableTemplate {
|
||||
|
||||
@Value("replace")
|
||||
@Abstractable
|
||||
private List<Material> replaceable;
|
||||
private MaterialSet replaceable;
|
||||
|
||||
@Value("physics")
|
||||
@Abstractable
|
||||
@@ -65,8 +61,8 @@ public class OreTemplate extends AbstractableTemplate {
|
||||
return material;
|
||||
}
|
||||
|
||||
public Set<Material> getReplaceable() {
|
||||
return new HashSet<>(replaceable);
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public boolean doPhysics() {
|
||||
|
||||
@@ -4,11 +4,9 @@ import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.Material;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class TreeTemplate extends AbstractableTemplate {
|
||||
@Value("files")
|
||||
@@ -25,7 +23,7 @@ public class TreeTemplate extends AbstractableTemplate {
|
||||
|
||||
@Value("spawnable")
|
||||
@Abstractable
|
||||
private Set<Material> spawnable;
|
||||
private MaterialSet spawnable;
|
||||
|
||||
public ProbabilityCollection<Structure> getStructures() {
|
||||
return structures;
|
||||
@@ -39,7 +37,7 @@ public class TreeTemplate extends AbstractableTemplate {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public Set<Material> getSpawnable() {
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.dfsek.terra.math.MathUtil;
|
||||
import com.dfsek.terra.population.CavePopulator;
|
||||
import com.dfsek.terra.population.FloraPopulator;
|
||||
import com.dfsek.terra.population.OrePopulator;
|
||||
import com.dfsek.terra.population.SnowPopulator;
|
||||
import com.dfsek.terra.population.StructurePopulator;
|
||||
import com.dfsek.terra.population.TreePopulator;
|
||||
import com.dfsek.terra.util.DataUtil;
|
||||
@@ -60,7 +59,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
popMan.attach(new OrePopulator());
|
||||
popMan.attach(new TreePopulator());
|
||||
popMan.attach(new FloraPopulator());
|
||||
popMan.attach(new SnowPopulator());
|
||||
}
|
||||
|
||||
public static synchronized void saveAll() {
|
||||
|
||||
@@ -5,22 +5,21 @@ import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.StructureContainedBlock;
|
||||
import com.dfsek.terra.structure.StructureInfo;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import com.dfsek.terra.util.structure.RotationUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class TerraTree implements Tree {
|
||||
private final Set<Material> spawnable;
|
||||
private final MaterialSet spawnable;
|
||||
private final int yOffset;
|
||||
private final ProbabilityCollection<Structure> structure;
|
||||
|
||||
public TerraTree(Set<Material> spawnable, int yOffset, ProbabilityCollection<Structure> structure) {
|
||||
public TerraTree(MaterialSet spawnable, int yOffset, ProbabilityCollection<Structure> structure) {
|
||||
this.spawnable = spawnable;
|
||||
this.yOffset = yOffset;
|
||||
this.structure = structure;
|
||||
@@ -38,7 +37,7 @@ public class TerraTree implements Tree {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> getSpawnable() {
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.generation.items.flora;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.util.GlueList;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Flora that is just 1 layer of a single block.
|
||||
*/
|
||||
public class BlockFlora implements Flora {
|
||||
|
||||
private final BlockData data;
|
||||
|
||||
public BlockFlora(BlockData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
Block current = chunk.getBlock(x, range.getMin(), z);
|
||||
List<Block> blocks = new GlueList<>();
|
||||
for(int y : range) {
|
||||
if(y > 255 || y < 0) continue;
|
||||
current = current.getRelative(BlockFace.UP);
|
||||
if(current.getType().isSolid() && current.getRelative(BlockFace.UP).isEmpty()) {
|
||||
blocks.add(current); // Add all blocks that are solid with air directly above.
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location) {
|
||||
location.add(0, 1, 0).getBlock().setBlockData(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.generation.items.flora;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -13,37 +13,46 @@ import org.polydev.gaea.world.palette.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TerraFlora implements Flora {
|
||||
private final Palette<BlockData> floraPalette;
|
||||
private final boolean physics;
|
||||
private final boolean ceiling;
|
||||
|
||||
private final Set<Material> irrigable;
|
||||
private final MaterialSet irrigable;
|
||||
|
||||
private final Set<Material> spawnable;
|
||||
private final Set<Material> replaceable;
|
||||
private final MaterialSet spawnable;
|
||||
private final MaterialSet replaceable;
|
||||
|
||||
public TerraFlora(Palette<BlockData> floraPalette, boolean physics, boolean ceiling, Set<Material> irrigable, Set<Material> spawnable, Set<Material> replaceable) {
|
||||
private final int maxPlacements;
|
||||
|
||||
private final Search search;
|
||||
|
||||
private final boolean spawnBlacklist;
|
||||
|
||||
public TerraFlora(Palette<BlockData> floraPalette, boolean physics, boolean ceiling, MaterialSet irrigable, MaterialSet spawnable, MaterialSet replaceable, int maxPlacements, Search search, boolean spawnBlacklist) {
|
||||
this.floraPalette = floraPalette;
|
||||
this.physics = physics;
|
||||
this.spawnBlacklist = spawnBlacklist;
|
||||
this.ceiling = ceiling;
|
||||
this.irrigable = irrigable;
|
||||
this.spawnable = spawnable;
|
||||
this.replaceable = replaceable;
|
||||
this.maxPlacements = maxPlacements;
|
||||
this.search = search;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
int size = floraPalette.getSize();
|
||||
Block current = chunk.getBlock(x, range.getMin(), z);
|
||||
Block current = chunk.getBlock(x, search.equals(Search.UP) ? range.getMin() : range.getMax(), z);
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
for(int y : range) {
|
||||
if(y > 255 || y < 0) continue;
|
||||
current = current.getRelative(BlockFace.UP);
|
||||
if(spawnable.contains(current.getType()) && isIrrigated(current) && valid(size, current)) {
|
||||
current = current.getRelative(search.equals(Search.UP) ? BlockFace.UP : BlockFace.DOWN);
|
||||
if((spawnBlacklist != spawnable.contains(current.getType())) && isIrrigated(current) && valid(size, current)) {
|
||||
blocks.add(current);
|
||||
if(maxPlacements > 0 && blocks.size() > maxPlacements) break;
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
@@ -77,4 +86,9 @@ public class TerraFlora implements Flora {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public enum Search {
|
||||
UP,
|
||||
DOWN
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -9,14 +9,13 @@ import org.polydev.gaea.math.FastNoiseLite;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class DeformedSphereOre extends Ore {
|
||||
private final double deform;
|
||||
private final double deformFrequency;
|
||||
private final Range size;
|
||||
|
||||
public DeformedSphereOre(BlockData material, Set<Material> replaceable, boolean applyGravity, double deform, double deformFrequency, Range size) {
|
||||
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size) {
|
||||
super(material, replaceable, applyGravity);
|
||||
this.deform = deform;
|
||||
this.deformFrequency = deformFrequency;
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Ore {
|
||||
|
||||
private final BlockData material;
|
||||
private final Set<Material> replaceable;
|
||||
private final MaterialSet replaceable;
|
||||
private final boolean applyGravity;
|
||||
|
||||
public Ore(BlockData material, Set<Material> replaceable, boolean applyGravity) {
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity) {
|
||||
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
@@ -27,7 +26,7 @@ public abstract class Ore {
|
||||
return material;
|
||||
}
|
||||
|
||||
public Set<Material> getReplaceable() {
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class VanillaOre extends Ore {
|
||||
private final Range sizeRange;
|
||||
|
||||
public VanillaOre(BlockData material, Set<Material> replaceable, boolean applyGravity, Range size) {
|
||||
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size) {
|
||||
super(material, replaceable, applyGravity);
|
||||
this.sizeRange = size;
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.population.GaeaBlockPopulator;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class SnowPopulator extends GaeaBlockPopulator {
|
||||
private static final Set<Material> blacklistSpawn = new HashSet<>();
|
||||
|
||||
static {
|
||||
for(Material m : Material.values()) {
|
||||
String name = m.toString().toLowerCase();
|
||||
if(name.contains("slab")
|
||||
|| name.contains("stair")
|
||||
|| name.contains("wall")
|
||||
|| name.contains("fence")
|
||||
|| name.contains("lantern")
|
||||
|| name.contains("chest")
|
||||
|| name.contains("door")
|
||||
|| name.contains("repeater")
|
||||
|| name.equals("lily_pad")
|
||||
|| name.equals("snow")
|
||||
|| name.equals("pane")) blacklistSpawn.add(m);
|
||||
}
|
||||
blacklistSpawn.add(Material.END_STONE);
|
||||
if(PluginConfig.isDebug())
|
||||
Bukkit.getLogger().info("Added " + blacklistSpawn.size() + " materials to snow blacklist");
|
||||
}
|
||||
|
||||
@SuppressWarnings("try")
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("SnowTime")) {
|
||||
int origX = chunk.getX() << 4;
|
||||
int origZ = chunk.getZ() << 4;
|
||||
TerraWorld w = TerraWorld.getWorld(world);
|
||||
if(!w.isSafe()) return;
|
||||
TerraBiomeGrid g = w.getGrid();
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
/*
|
||||
BiomeTemplate biome = ((UserDefinedBiome) g.getBiome(origX + x, origZ + z, GenerationPhase.PALETTE_APPLY)).getConfig();
|
||||
if(!biome) continue;
|
||||
int y;
|
||||
Block b = null;
|
||||
for(y = 254; y > 0; y--) {
|
||||
b = chunk.getBlock(x, y, z);
|
||||
if(!b.getType().isAir()) break;
|
||||
}
|
||||
if(random.nextInt(100) >= biome.getSnow().getSnowChance(y))
|
||||
continue;
|
||||
if(blacklistSpawn.contains(b.getType()) || b.isPassable()) continue;
|
||||
boolean phys = biome.getSnow().doPhysics();
|
||||
if(!phys) {
|
||||
BlockData data = b.getBlockData();
|
||||
if(data instanceof Snowable) phys = true;
|
||||
}
|
||||
b.getRelative(BlockFace.UP).setBlockData(DataUtil.SNOW, phys);
|
||||
|
||||
|
||||
*/
|
||||
// TODO: implementation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.registry;
|
||||
|
||||
import com.dfsek.terra.generation.items.flora.BlockFlora;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.FloraType;
|
||||
|
||||
@@ -7,4 +9,11 @@ public class FloraRegistry extends TerraRegistry<Flora> {
|
||||
public FloraRegistry() {
|
||||
for(FloraType f : FloraType.values()) add(f.toString(), f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flora get(String id) {
|
||||
if(id.startsWith("BLOCK:"))
|
||||
return new BlockFlora(Bukkit.createBlockData(id.substring(6))); // Return single flora for BLOCK: shortcut.
|
||||
return super.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.StructureInfo;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -19,16 +19,15 @@ import org.polydev.gaea.util.GlueList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class EntityFeature implements Feature {
|
||||
private final EntityType type;
|
||||
private final Range amount;
|
||||
private final Set<Material> in;
|
||||
private final Set<Material> stand;
|
||||
private final MaterialSet in;
|
||||
private final MaterialSet stand;
|
||||
private final int inSize;
|
||||
|
||||
public EntityFeature(EntityType type, Range amount, Set<Material> stand, Set<Material> in, int inSize) {
|
||||
public EntityFeature(EntityType type, Range amount, MaterialSet stand, MaterialSet in, int inSize) {
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
this.in = in;
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.carving.CarverPalette;
|
||||
import com.dfsek.terra.config.loaders.BlockDataLoader;
|
||||
import com.dfsek.terra.config.loaders.FloraLayerLoader;
|
||||
import com.dfsek.terra.config.loaders.FloraSearchLoader;
|
||||
import com.dfsek.terra.config.loaders.GridSpawnLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialLoader;
|
||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||
import com.dfsek.terra.config.loaders.NoiseBuilderLoader;
|
||||
import com.dfsek.terra.config.loaders.OreConfigLoader;
|
||||
import com.dfsek.terra.config.loaders.OreTypeLoader;
|
||||
@@ -20,6 +22,7 @@ import com.dfsek.terra.config.loaders.VanillaBiomeLoader;
|
||||
import com.dfsek.terra.config.loaders.base.CarverPaletteLoader;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.generation.items.flora.FloraLayer;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.generation.items.ores.OreConfig;
|
||||
import com.dfsek.terra.generation.items.tree.TreeLayer;
|
||||
@@ -50,6 +53,8 @@ public final class ConfigUtil {
|
||||
.registerLoader(Ore.Type.class, new OreTypeLoader())
|
||||
.registerLoader(OreConfig.class, new OreConfigLoader())
|
||||
.registerLoader(NoiseBuilder.class, new NoiseBuilderLoader())
|
||||
.registerLoader(TreeLayer.class, new TreeLayerLoader());
|
||||
.registerLoader(TreeLayer.class, new TreeLayerLoader())
|
||||
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||
.registerLoader(TerraFlora.Search.class, new FloraSearchLoader());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
|
||||
public final class DataUtil {
|
||||
public static final BlockData STONE = Material.STONE.createBlockData();
|
||||
public static final BlockData SNOW = Material.SNOW.createBlockData();
|
||||
public static final BlockData WATER = Material.WATER.createBlockData();
|
||||
public static final BlockData AIR = Material.AIR.createBlockData();
|
||||
public static final Palette<BlockData> BLANK_PALETTE = new RandomPalette<BlockData>(new FastRandom(2403)).add(AIR, 1);
|
||||
|
||||
31
src/main/java/com/dfsek/terra/util/MaterialSet.java
Normal file
31
src/main/java/com/dfsek/terra/util/MaterialSet.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class MaterialSet extends HashSet<Material> {
|
||||
private static final long serialVersionUID = 3056512763631017301L;
|
||||
|
||||
public static MaterialSet singleton(Material material) {
|
||||
MaterialSet set = new MaterialSet();
|
||||
set.add(material);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static MaterialSet get(Material... materials) {
|
||||
MaterialSet set = new MaterialSet();
|
||||
set.addAll(Arrays.asList(materials));
|
||||
return set;
|
||||
}
|
||||
|
||||
public void addTag(String tag) {
|
||||
this.addAll(TagUtil.getTag(tag));
|
||||
}
|
||||
|
||||
private void add(BlockData data) {
|
||||
add(data.getMaterial());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.util;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -8,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@@ -37,6 +39,24 @@ public final class TagUtil {
|
||||
}
|
||||
putCustomSet("minecraft:base_stone_nether", Material.NETHERRACK, Material.BASALT, Material.BLACKSTONE);
|
||||
putCustomSet("minecraft:base_stone_overworld", Material.STONE, Material.GRANITE, Material.DIORITE, Material.ANDESITE);
|
||||
|
||||
Set<Material> snow = new HashSet<>();
|
||||
for(Material m : Material.values()) {
|
||||
String name = m.toString().toLowerCase();
|
||||
if(name.contains("slab")
|
||||
|| name.contains("stair")
|
||||
|| name.contains("wall")
|
||||
|| name.contains("fence")
|
||||
|| name.contains("lantern")
|
||||
|| name.contains("chest")
|
||||
|| name.contains("door")
|
||||
|| name.contains("repeater")
|
||||
|| name.equals("lily_pad")
|
||||
|| name.equals("snow")
|
||||
|| name.equals("pane")) snow.add(m);
|
||||
}
|
||||
tagMap.put("terra:snow_blacklist", snow);
|
||||
Bukkit.getLogger().info("Added " + snow.size() + " materials to snow blacklist");
|
||||
}
|
||||
|
||||
private static Set<Material> getSet(Material... materials) {
|
||||
|
||||
Reference in New Issue
Block a user