Implement ceiling flora, allow configuring block updates for flora & ores.

This commit is contained in:
dfsek 2020-10-02 15:47:35 -07:00
parent d09737f81b
commit ecf9a583dd
4 changed files with 33 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import com.dfsek.terra.Debug;
import com.dfsek.terra.config.TerraConfig; import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException; import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.population.OrePopulator;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import com.dfsek.terra.TerraTree; import com.dfsek.terra.TerraTree;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
@ -75,10 +76,11 @@ public class BiomeConfig extends TerraConfigObject {
if(contains("extends")) { if(contains("extends")) {
try { try {
abstractBiome = config.getAbstractBiomes().get(getString("extends")); abstractBiome = config.getAbstractBiomes().get(getString("extends"));
if(abstractBiome == null) throw new NotFoundException("Abstract Biome", getString("extends"), getID());
extending = true; extending = true;
Debug.info("Extending biome " + getString("extends")); Debug.info("Extending biome " + getString("extends"));
} catch(NullPointerException e) { } catch(NullPointerException e) {
throw new ConfigException("No abstract biome with ID " + getString("extends") + " found.", getID()); throw new NotFoundException("Abstract Biome", getString("extends"), getID());
} }
} }
@ -209,6 +211,7 @@ public class BiomeConfig extends TerraConfigObject {
try { try {
Debug.info("[Terra] Is custom flora: true"); Debug.info("[Terra] Is custom flora: true");
Flora floraCustom = getConfig().getFlora(e.getKey()); Flora floraCustom = getConfig().getFlora(e.getKey());
if(floraCustom == null) throw new NotFoundException("Flora", e.getKey(), getID());
flora.add(floraCustom, (Integer) val.get("weight")); flora.add(floraCustom, (Integer) val.get("weight"));
floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max"))); floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max")));
} catch(NullPointerException ex2) { } catch(NullPointerException ex2) {
@ -272,8 +275,10 @@ public class BiomeConfig extends TerraConfigObject {
} }
if(oreData != null) { if(oreData != null) {
for(Map.Entry<String, Object> m : oreData.entrySet()) { for(Map.Entry<String, Object> m : oreData.entrySet()) {
ores.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max"))); OreConfig ore = config.getOre(m.getKey());
oreHeights.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height"))); if(ore == null) throw new NotFoundException("Ore", m.getKey(), getID());
ores.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max")));
oreHeights.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
} }
} else { } else {
ores = new HashMap<>(); ores = new HashMap<>();

View File

@ -26,6 +26,7 @@ public class FloraConfig extends TerraConfigObject implements Flora {
private final Palette<BlockData> floraPalette; private final Palette<BlockData> floraPalette;
private final String id; private final String id;
private final boolean physics; private final boolean physics;
private final boolean ceiling;
Set<Material> spawnable; Set<Material> spawnable;
Set<Material> replaceable; Set<Material> replaceable;
@ -41,6 +42,7 @@ public class FloraConfig extends TerraConfigObject implements Flora {
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID()); spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID()); replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID());
physics = getBoolean("physics", false); physics = getBoolean("physics", false);
ceiling = getBoolean("ceiling", false);
Palette<BlockData> p = new RandomPalette<>(new Random(getInt("seed", 4))); Palette<BlockData> p = new RandomPalette<>(new Random(getInt("seed", 4)));
@ -54,9 +56,18 @@ public class FloraConfig extends TerraConfigObject implements Flora {
@Override @Override
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) { public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
List<Block> blocks = new ArrayList<>(); List<Block> blocks = new ArrayList<>();
for(int y : range) { if(ceiling) for(int y : range) {
if(y > 255 || y < 1) continue;
Block check = chunk.getBlock(x, y, z); Block check = chunk.getBlock(x, y, z);
if(spawnable.contains(check.getType())) { Block other = chunk.getBlock(x, y-1, z);
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType())) {
blocks.add(check);
}
} else for(int y : range) {
if(y > 254 || y < 0) continue;
Block check = chunk.getBlock(x, y, z);
Block other = chunk.getBlock(x, y+1, z);
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType())) {
blocks.add(check); blocks.add(check);
} }
} }
@ -66,11 +77,14 @@ public class FloraConfig extends TerraConfigObject implements Flora {
@Override @Override
public boolean plant(Location location) { public boolean plant(Location location) {
int size = floraPalette.getSize(); int size = floraPalette.getSize();
for(int i = 0; i < size; i++) { int c = ceiling ? -1 : 1;
if(!replaceable.contains(location.clone().add(0, i+1, 0).getBlock().getType())) return false; for(int i = 0; Math.abs(i) < size; i+= c) { // Down if ceiling, up if floor
if(i+1 > 255) return false;
if(!replaceable.contains(location.clone().add(0, i+c, 0).getBlock().getType())) return false;
} }
for(int i = 0; i < size; i++) { for(int i = 0; Math.abs(i) < size; i+=c) { // Down if ceiling, up if floor
location.clone().add(0, i+1, 0).getBlock().setBlockData(floraPalette.get(size-(i+1), location.getBlockX(), location.getBlockZ()), physics); int lvl = (Math.abs(i));
location.clone().add(0, i+c, 0).getBlock().setBlockData(floraPalette.get((ceiling ? lvl : size-lvl+1), location.getBlockX(), location.getBlockZ()), physics);
} }
return true; return true;
} }

View File

@ -29,6 +29,7 @@ public class OreConfig extends TerraConfigObject {
private final double deform; private final double deform;
private final double deformFrequency; private final double deformFrequency;
private final String id; private final String id;
private final boolean update;
Set<Material> replaceable; Set<Material> replaceable;
public OreConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException { public OreConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
super(file, config); super(file, config);
@ -41,6 +42,7 @@ public class OreConfig extends TerraConfigObject {
max = getInt("radius.max", 1); max = getInt("radius.max", 1);
deform = getDouble("deform"); deform = getDouble("deform");
deformFrequency = getDouble("deform-frequency"); deformFrequency = getDouble("deform-frequency");
update = getBoolean("update", false);
replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID()); replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID());
@ -64,7 +66,7 @@ public class OreConfig extends TerraConfigObject {
for(int z = -rad; z <= rad; z++) { for(int z = -rad; z <= rad; z++) {
if(l.clone().add(x, y, z).distance(l) < (rad + 0.5) * ((ore.getSimplexFractal(x, y, z)+1)*deform)) { if(l.clone().add(x, y, z).distance(l) < (rad + 0.5) * ((ore.getSimplexFractal(x, y, z)+1)*deform)) {
Block b = l.clone().add(x, y, z).getBlock(); Block b = l.clone().add(x, y, z).getBlock();
if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0) b.setBlockData(oreData, false); if(replaceable.contains(b.getType()) && b.getLocation().getY() >= 0) b.setBlockData(oreData, update);
} }
} }
} }

View File

@ -1,11 +1,13 @@
package com.dfsek.terra.population; package com.dfsek.terra.population;
import com.dfsek.terra.Debug;
import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld; import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid; import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.TerraConfig; import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.FloraConfig;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;