mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Implement ceiling flora, allow configuring block updates for flora & ores.
This commit is contained in:
parent
d09737f81b
commit
ecf9a583dd
@ -4,6 +4,7 @@ import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.population.OrePopulator;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.TerraTree;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
@ -75,10 +76,11 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
if(contains("extends")) {
|
||||
try {
|
||||
abstractBiome = config.getAbstractBiomes().get(getString("extends"));
|
||||
if(abstractBiome == null) throw new NotFoundException("Abstract Biome", getString("extends"), getID());
|
||||
extending = true;
|
||||
Debug.info("Extending biome " + getString("extends"));
|
||||
} 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 {
|
||||
Debug.info("[Terra] Is custom flora: true");
|
||||
Flora floraCustom = getConfig().getFlora(e.getKey());
|
||||
if(floraCustom == null) throw new NotFoundException("Flora", e.getKey(), getID());
|
||||
flora.add(floraCustom, (Integer) val.get("weight"));
|
||||
floraHeights.put(floraCustom, new Range((Integer) y.get("min"), (Integer) y.get("max")));
|
||||
} catch(NullPointerException ex2) {
|
||||
@ -272,8 +275,10 @@ public class BiomeConfig extends TerraConfigObject {
|
||||
}
|
||||
if(oreData != null) {
|
||||
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")));
|
||||
oreHeights.put(config.getOre(m.getKey()), new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
|
||||
OreConfig ore = config.getOre(m.getKey());
|
||||
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 {
|
||||
ores = new HashMap<>();
|
||||
|
@ -26,6 +26,7 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
private final Palette<BlockData> floraPalette;
|
||||
private final String id;
|
||||
private final boolean physics;
|
||||
private final boolean ceiling;
|
||||
|
||||
Set<Material> spawnable;
|
||||
Set<Material> replaceable;
|
||||
@ -41,6 +42,7 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
|
||||
replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID());
|
||||
physics = getBoolean("physics", false);
|
||||
ceiling = getBoolean("ceiling", false);
|
||||
|
||||
Palette<BlockData> p = new RandomPalette<>(new Random(getInt("seed", 4)));
|
||||
|
||||
@ -54,9 +56,18 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
@Override
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -66,11 +77,14 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
@Override
|
||||
public boolean plant(Location location) {
|
||||
int size = floraPalette.getSize();
|
||||
for(int i = 0; i < size; i++) {
|
||||
if(!replaceable.contains(location.clone().add(0, i+1, 0).getBlock().getType())) return false;
|
||||
int c = ceiling ? -1 : 1;
|
||||
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++) {
|
||||
location.clone().add(0, i+1, 0).getBlock().setBlockData(floraPalette.get(size-(i+1), location.getBlockX(), location.getBlockZ()), physics);
|
||||
for(int i = 0; Math.abs(i) < size; i+=c) { // Down if ceiling, up if floor
|
||||
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;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ public class OreConfig extends TerraConfigObject {
|
||||
private final double deform;
|
||||
private final double deformFrequency;
|
||||
private final String id;
|
||||
private final boolean update;
|
||||
Set<Material> replaceable;
|
||||
public OreConfig(File file, TerraConfig config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
@ -41,6 +42,7 @@ public class OreConfig extends TerraConfigObject {
|
||||
max = getInt("radius.max", 1);
|
||||
deform = getDouble("deform");
|
||||
deformFrequency = getDouble("deform-frequency");
|
||||
update = getBoolean("update", false);
|
||||
|
||||
replaceable = ConfigUtil.toBlockData(getStringList("replace"), "replaceable", getID());
|
||||
|
||||
@ -64,7 +66,7 @@ public class OreConfig extends TerraConfigObject {
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.FloraConfig;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
Loading…
x
Reference in New Issue
Block a user