Allow multi-level Flora, use ID hash for cave checking

This commit is contained in:
dfsek 2020-09-29 11:23:01 -07:00
parent ed77802ffd
commit ca5accafa2
4 changed files with 19 additions and 11 deletions

View File

@ -95,7 +95,7 @@
<dependency> <dependency>
<groupId>org.polydev</groupId> <groupId>org.polydev</groupId>
<artifactId>gaea</artifactId> <artifactId>gaea</artifactId>
<version>1.10.47</version> <version>1.10.48</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.lucko</groupId> <groupId>me.lucko</groupId>

View File

@ -41,7 +41,7 @@ public class UserDefinedCarver extends Carver {
@Override @Override
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) { public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
return random.nextInt(100) < BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this); return new Random(random.nextLong()+hash).nextInt(100) < BiomeConfig.fromBiome((UserDefinedBiome) TerraBiomeGrid.fromWorld(w).getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getCarverChance(this);
} }
private class UserDefinedWorm extends Worm { private class UserDefinedWorm extends Worm {

View File

@ -15,6 +15,7 @@ import org.polydev.gaea.world.palette.RandomPalette;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -81,11 +82,15 @@ public class FloraConfig extends TerraConfigObject implements Flora {
} }
@Override @Override
public Block getHighestValidSpawnAt(Chunk chunk, int x, int z) { public List<Block> getValidSpawnsAt(Chunk chunk, int x, int z) {
List<Block> blocks = new ArrayList<>();
int y; int y;
for(y = chunk.getWorld().getMaxHeight() - 1; (!spawnable.contains(chunk.getBlock(x, y, z).getType())) && y > 0; y--); for(y = chunk.getWorld().getMaxHeight() - 1; y > 0; y--) {
if(y <= 0) return null; if(spawnable.contains(chunk.getBlock(x, y, z).getType()) && replaceable.contains(chunk.getBlock(x, y+1, z).getType())) {
return chunk.getBlock(x, y, z); blocks.add(chunk.getBlock(x, y, z));
}
}
return blocks;
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.genconfig.BiomeConfig; import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -15,7 +16,9 @@ import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.profiler.ProfileFuture; import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.Flora; import org.polydev.gaea.world.Flora;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -29,17 +32,17 @@ public class FloraPopulator extends GaeaBlockPopulator {
for(int x = 0; x < 16; x++) { for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) { for(int z = 0; z < 16; z++) {
UserDefinedBiome biome = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE); UserDefinedBiome biome = (UserDefinedBiome) TerraBiomeGrid.fromWorld(world).getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
if(biome.getDecorator().getFloraChance() <= 0 || random.nextInt(100) > biome.getDecorator().getFloraChance()) if(biome.getDecorator().getFloraChance() <= 0) continue;
continue;
try { try {
BiomeConfig c = BiomeConfig.fromBiome(biome); BiomeConfig c = BiomeConfig.fromBiome(biome);
for(int i = 0; i < c.getFloraAttempts(); i++) { for(int i = 0; i < c.getFloraAttempts(); i++) {
Flora item; Flora item;
if(c.isFloraSimplex()) item = biome.getDecorator().getFlora().get(c.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z); 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); else item = biome.getDecorator().getFlora().get(random);
Block highest = item.getHighestValidSpawnAt(chunk, x, z); for(Block highest : item.getValidSpawnsAt(chunk, x, z)) {
if(highest != null && c.getFloraHeights(item).isInRange(highest.getY())) if(c.getFloraHeights(item).isInRange(highest.getY()) && random.nextInt(100) < biome.getDecorator().getFloraChance())
item.plant(highest.getLocation()); item.plant(highest.getLocation());
}
} }
} catch(NullPointerException ignore) {} } catch(NullPointerException ignore) {}
} }