mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Only use RandomPalette if palette contains multiple materials.
This commit is contained in:
parent
0f29a506d0
commit
d239358afe
2
pom.xml
2
pom.xml
@ -95,7 +95,7 @@
|
||||
<dependency>
|
||||
<groupId>org.polydev</groupId>
|
||||
<artifactId>gaea</artifactId>
|
||||
<version>1.10.80</version>
|
||||
<version>1.10.82</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.lucko</groupId>
|
||||
|
@ -1,119 +0,0 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
public class Range implements Iterable<Integer> {
|
||||
private int min;
|
||||
private int max;
|
||||
public Range(int min, int max) {
|
||||
if(min > max) throw new IllegalArgumentException("Minimum must not be grater than maximum!");
|
||||
this.max = max;
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
public boolean isInRange(int test) {
|
||||
return test >= min && test < max;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public Range setMax(int max) {
|
||||
this.max = max;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
return max-min;
|
||||
}
|
||||
|
||||
public Range multiply(int mult) {
|
||||
min*=mult;
|
||||
max*=mult;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Range reflect(int pt) {
|
||||
return new Range(2*pt-this.getMax(), 2*pt-this.getMin());
|
||||
}
|
||||
|
||||
public Range setMin(int min) {
|
||||
this.min = min;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int get(Random r) {
|
||||
return r.nextInt((max-min)+1)+min;
|
||||
}
|
||||
|
||||
public Range intersects(Range other) {
|
||||
try {
|
||||
return new Range(Math.max(this.getMin(), other.getMin()), Math.min(this.getMax(), other.getMax()));
|
||||
} catch(IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Range add(int add) {
|
||||
this.min += add;
|
||||
this.max += add;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Range sub(int sub) {
|
||||
this.min -= sub;
|
||||
this.max -= sub;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Min: " + getMin() + ", Max:" + getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return min * 31 + max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Range)) return false;
|
||||
Range other = (Range) obj;
|
||||
return other.getMin() == this.getMin() && other.getMax() == this.getMax();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Integer> iterator() {
|
||||
return new RangeIterator(this);
|
||||
}
|
||||
private static class RangeIterator implements Iterator<Integer> {
|
||||
private Integer current;
|
||||
private final Range m;
|
||||
|
||||
public RangeIterator(Range m) {
|
||||
this.m = m;
|
||||
current = m.getMin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return current < m.getMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer next() {
|
||||
current++;
|
||||
return current - 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.genconfig.BiomeConfig;
|
||||
|
@ -23,12 +23,14 @@ import java.util.stream.Collectors;
|
||||
public class ConfigUtil {
|
||||
public static boolean debug;
|
||||
public static long dataSave; // Period of population data saving, in ticks.
|
||||
public static boolean masterDisableCaves;
|
||||
public static void loadConfig(JavaPlugin main) {
|
||||
main.saveDefaultConfig();
|
||||
FileConfiguration config = main.getConfig();
|
||||
|
||||
debug = config.getBoolean("debug", false);
|
||||
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis()/20L;
|
||||
masterDisableCaves = config.getBoolean("master-disable.caves", false);
|
||||
|
||||
Logger logger = main.getLogger();
|
||||
logger.info("Loading config values");
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.TerraTree;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.TerraTree;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -4,11 +4,14 @@ import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.world.Flora;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
@ -82,12 +85,12 @@ public class FloraConfig extends TerraConfigObject implements Flora {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z) {
|
||||
public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
int y;
|
||||
for(y = chunk.getWorld().getMaxHeight() - 1; y > 0; y--) {
|
||||
if(spawnable.contains(chunk.getBlock(x, y, z).getType()) && replaceable.contains(chunk.getBlock(x, y+1, z).getType())) {
|
||||
blocks.add(chunk.getBlock(x, y, z));
|
||||
for(int y : range) {
|
||||
Block check = chunk.getBlock(x, y, z);
|
||||
if(spawnable.contains(check.getType())) {
|
||||
blocks.add(check);
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
|
@ -66,16 +66,28 @@ public class PaletteConfig extends TerraConfigObject {
|
||||
return paletteID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static Palette<BlockData> getPalette(List<Map<?, ?>> maps, Palette<BlockData> p) throws InvalidConfigurationException {
|
||||
for(Map<?, ?> m : maps) {
|
||||
try {
|
||||
ProbabilityCollection<BlockData> layer = new ProbabilityCollection<>();
|
||||
for(Map<?, ?> entry : (List<Map<?, ?>>) m.get("materials")) {
|
||||
List<Map<?, ?>> map = (List<Map<?, ?>>) m.get("materials");
|
||||
if(map.size() > 1) {
|
||||
for(Map<?, ?> entry : map) {
|
||||
for(Map.Entry<?, ?> type : entry.entrySet()) {
|
||||
layer.add(Bukkit.createBlockData((String) type.getKey()), (Integer) type.getValue());
|
||||
}
|
||||
}
|
||||
p.add(layer, (Integer) m.get("layers"));
|
||||
} else {
|
||||
Bukkit.getLogger().info("One-block palette layer!");
|
||||
String data = "null";
|
||||
for(Map.Entry<?, ?> e: map.get(0).entrySet()) {
|
||||
data = (String) e.getKey();
|
||||
}
|
||||
p.add(Bukkit.createBlockData(data), (Integer) m.get("layers"));
|
||||
}
|
||||
|
||||
} catch(ClassCastException e) {
|
||||
throw new InvalidConfigurationException("SEVERE configuration error for Palette: \n\n" + e.getMessage());
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.config.genconfig;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.TerraConfigObject;
|
||||
|
@ -71,9 +71,8 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
int sea = c.getSeaLevel();
|
||||
Palette<BlockData> seaPalette = c.getOceanPalette();
|
||||
for(int y = world.getMaxHeight()-1; y >= 0; y--) {
|
||||
BlockData data;
|
||||
if(super.getInterpolatedNoise(x, y, z) > 0) {
|
||||
data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz);
|
||||
BlockData data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
if(paletteLevel == 0 && c.getSlabs() != null) {
|
||||
prepareBlockPart(data, chunk.getBlockData(x, y+1, z), chunk, new Vector(x, y+1, z), c.getSlabs(), c.getStairs(), c.getSlabThreshold());
|
||||
@ -92,15 +91,10 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs, Map<Material, Palette<BlockData>> stairs, double thresh) {
|
||||
double _11 = getInterpolatedNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ());
|
||||
if(_11 > thresh) {
|
||||
//double _00 = interp.getNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ() - 0.5);
|
||||
double _01 = getInterpolatedNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ());
|
||||
//double _02 = interp.getNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ() + 0.5);
|
||||
double _10 = getInterpolatedNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.5);
|
||||
double _12 = getInterpolatedNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.5);
|
||||
//double _20 = interp.getNoise(block.getBlockX() + 0.5, block.getBlockY(), block.getBlockZ() - 0.5);
|
||||
double _21 = getInterpolatedNoise(block.getBlockX() + 0.5, block.getBlockY(), block.getBlockZ());
|
||||
//double _22 = interp.getNoise(block.getBlockX() + 0.5, block.getBlockY(), block.getBlockZ() + 0.5);
|
||||
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.genconfig.CarverConfig;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@ -26,6 +27,7 @@ public class CavePopulator extends BlockPopulator {
|
||||
private static final BlockData AIR = Material.AIR.createBlockData();
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
if(ConfigUtil.masterDisableCaves) return;
|
||||
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
|
||||
for(CarverConfig c : CarverConfig.getCarvers()) {
|
||||
Map<Location, Material> shiftCandidate = new HashMap<>();
|
||||
|
@ -23,12 +23,9 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class FloraPopulator extends GaeaBlockPopulator {
|
||||
Set<Chunk> pop = new HashSet<>();
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
if(pop.contains(chunk)) Bukkit.getLogger().warning("Already populated flora in chunk: " + chunk);
|
||||
pop.add(chunk);
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
|
||||
@ -39,8 +36,8 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
Flora item;
|
||||
if(c.isFloraSimplex()) item = biome.getDecorator().getFlora().get(c.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
else item = biome.getDecorator().getFlora().get(random);
|
||||
for(Block highest : item.getValidSpawnsAt(chunk, x, z)) {
|
||||
if(c.getFloraHeights(item).isInRange(highest.getY()) && random.nextInt(100) < biome.getDecorator().getFloraChance())
|
||||
for(Block highest : item.getValidSpawnsAt(chunk, x, z, c.getFloraHeights(item))) {
|
||||
if(random.nextInt(100) < biome.getDecorator().getFloraChance())
|
||||
item.plant(highest.getLocation());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.biome.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import com.dfsek.terra.Range;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
Loading…
x
Reference in New Issue
Block a user