mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-14 11:46:06 +00:00
Add block shifting to caves
This commit is contained in:
@@ -2,37 +2,66 @@ package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
import com.dfsek.terra.config.CarverConfig;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.generation.GenerationPopulator;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.world.carving.CarvingData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class CavePopulator extends GenerationPopulator {
|
||||
|
||||
public class CavePopulator extends BlockPopulator {
|
||||
@Override
|
||||
public ChunkGenerator.ChunkData populate(World world, ChunkGenerator.ChunkData chunk, Random random, int chunkX, int chunkZ) {
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
|
||||
ProfileFuture cave = TerraProfiler.fromWorld(world).measure("CaveTime");
|
||||
for(CarverConfig c : CarverConfig.getCarvers()) {
|
||||
ProfileFuture cave = TerraProfiler.fromWorld(world).measure("CaveTime");
|
||||
Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunkX, chunkZ, world).getCarvedBlocks();
|
||||
Map<Location, Material> shiftCandidate = new HashMap<>();
|
||||
Map<Vector, CarvingData.CarvingType> blocks = c.getCarver().carve(chunk.getX(), chunk.getZ(), world).getCarvedBlocks();
|
||||
for(Map.Entry<Vector, CarvingData.CarvingType> e : blocks.entrySet()) {
|
||||
Vector v = e.getKey();
|
||||
Material m = chunk.getType(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
Material m = b.getType();
|
||||
boolean liquid = m.equals(Material.WATER) || m.equals(Material.LAVA);
|
||||
if(e.getValue().equals(CarvingData.CarvingType.CENTER) && c.isReplaceableInner(m)) {
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), Material.AIR);
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) shiftCandidate.put(b.getLocation(), b.getType());
|
||||
b.setBlockData(c.getPaletteInner(v.getBlockY()).get(random), liquid);
|
||||
} else if(c.isReplaceableOuter(m)){
|
||||
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), Material.ANDESITE);
|
||||
if(c.getShiftedBlocks().containsKey(b.getType())) shiftCandidate.put(b.getLocation(), b.getType());
|
||||
b.setBlockData(c.getPaletteOuter(v.getBlockY()).get(random), liquid);
|
||||
} else if(liquid) {
|
||||
b.setBlockData(b.getBlockData(), true);
|
||||
}
|
||||
|
||||
}
|
||||
if(cave != null) cave.complete();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for(Location l : shiftCandidate.keySet()) {
|
||||
Location mut = l.clone();
|
||||
Material orig = l.getBlock().getType();
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(mut.getBlock().getType().equals(orig));
|
||||
try {
|
||||
if(c.getShiftedBlocks().get(shiftCandidate.get(l)).contains(mut.getBlock().getType())) {
|
||||
mut.getBlock().setType(shiftCandidate.get(l));
|
||||
j++;
|
||||
}
|
||||
} catch(NullPointerException ignored) {}
|
||||
i++;
|
||||
}
|
||||
if(i > 0) System.out.println("Shifted " + i + " blocks. " + j + " successful shifts.");
|
||||
}
|
||||
return chunk;
|
||||
|
||||
if(cave != null) cave.complete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.population.GaeaBlockPopulator;
|
||||
import org.polydev.gaea.population.PopulationManager;
|
||||
import org.polydev.gaea.profiler.ProfileFuture;
|
||||
import org.polydev.gaea.util.WorldUtil;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user