mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 17:26:07 +00:00
slabs and stairs generate on ceiling
This commit is contained in:
@@ -31,7 +31,7 @@ public class ReloadCommand extends Command implements DebugCommand {
|
||||
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
PluginConfig.load(getMain());
|
||||
LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language.
|
||||
ConfigRegistry.loadAll(getMain());
|
||||
if(!ConfigRegistry.loadAll(getMain())) LangUtil.send("command.reload-error", sender);
|
||||
TerraWorld.invalidate();
|
||||
LangUtil.send("command.reload", sender);
|
||||
return true;
|
||||
|
||||
@@ -13,6 +13,6 @@ public class Sampler {
|
||||
}
|
||||
|
||||
public double sample(double x, double y, double z) {
|
||||
return interpolator.getNoise(x, y - elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)), z);
|
||||
return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Slab;
|
||||
import org.bukkit.block.data.type.Stairs;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -85,33 +87,15 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
return c.getPalette().getPalette(y);
|
||||
}
|
||||
|
||||
private static void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) {
|
||||
double elevation = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ());
|
||||
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4 - elevation, block.getBlockZ()) > thresh) {
|
||||
private static void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
|
||||
if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
|
||||
Stairs stairNew = (Stairs) stair.clone();
|
||||
int elevationN = (int) elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() - 1); // Northern elevation
|
||||
int elevationS = (int) elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() + 1); // Southern elevation
|
||||
int elevationE = (int) elevationInterpolator.getElevation(block.getBlockX() + 1, block.getBlockZ()); // Eastern elevation
|
||||
int elevationW = (int) elevationInterpolator.getElevation(block.getBlockX() - 1, block.getBlockZ()); // Western elevation
|
||||
if(interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY() - elevationW, block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.WEST);
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - elevationN, block.getBlockZ() - 0.5) > thresh) {
|
||||
stairNew.setFacing(BlockFace.NORTH);
|
||||
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - elevationS, block.getBlockZ() + 0.5) > thresh) {
|
||||
stairNew.setFacing(BlockFace.SOUTH);
|
||||
} else if(interpolator.getNoise(block.getBlockX() + 0.5, block.getBlockY() - elevationE, block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
if(orig.matches(DataUtil.WATER)) stairNew.setWaterlogged(true);
|
||||
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
|
||||
return;
|
||||
}
|
||||
if(placePart(orig, chunk, block, thresh, sampler, stairNew)) return;
|
||||
}
|
||||
}
|
||||
BlockData slab = slabs.getOrDefault(down.getMaterial(), DataUtil.BLANK_PALETTE).get(0, block.getBlockX(), block.getBlockZ());
|
||||
@@ -122,6 +106,46 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
|
||||
Map<Material, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
|
||||
if(sampler.sample(block.getBlockX(), block.getBlockY() + 0.4, block.getBlockZ()) > thresh) {
|
||||
if(stairs != null) {
|
||||
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
|
||||
if(stairPalette != null) {
|
||||
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
|
||||
Stairs stairNew = (Stairs) stair.clone();
|
||||
stairNew.setHalf(Bisected.Half.TOP);
|
||||
if(placePart(orig, chunk, block, thresh, sampler, stairNew)) return;
|
||||
}
|
||||
}
|
||||
BlockData slab = slabs.getOrDefault(up.getMaterial(), DataUtil.BLANK_PALETTE).get(0, block.getBlockX(), block.getBlockZ());
|
||||
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
|
||||
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
|
||||
if(slab instanceof Waterlogged) {
|
||||
((Waterlogged) slab).setWaterlogged(orig.matches(DataUtil.WATER));
|
||||
} else if(orig.matches(DataUtil.WATER)) return;
|
||||
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean placePart(BlockData orig, ChunkData chunk, Vector block, double thresh, Sampler sampler, Stairs stairNew) {
|
||||
if(sampler.sample(block.getBlockX() - 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.WEST);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.55) > thresh) {
|
||||
stairNew.setFacing(BlockFace.NORTH);
|
||||
} else if(sampler.sample(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.55) > thresh) {
|
||||
stairNew.setFacing(BlockFace.SOUTH);
|
||||
} else if(sampler.sample(block.getBlockX() + 0.55, block.getBlockY(), block.getBlockZ()) > thresh) {
|
||||
stairNew.setFacing(BlockFace.EAST);
|
||||
} else stairNew = null;
|
||||
if(stairNew != null) {
|
||||
if(orig.matches(DataUtil.WATER)) stairNew.setWaterlogged(true);
|
||||
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachProfiler(WorldProfiler p) {
|
||||
super.attachProfiler(p);
|
||||
@@ -158,19 +182,30 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
|
||||
int sea = c.getSeaLevel();
|
||||
Palette<BlockData> seaPalette = c.getOceanPalette();
|
||||
|
||||
boolean justSet = false;
|
||||
BlockData data = null;
|
||||
for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
|
||||
if(sampler.sample(x, y, z) > 0) {
|
||||
BlockData data = getPalette(x, y, z, c, sampler).get(paletteLevel, cx, cz);
|
||||
justSet = true;
|
||||
data = getPalette(x, y, z, c, sampler).get(paletteLevel, cx, cz);
|
||||
chunk.setBlock(x, y, z, data);
|
||||
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
|
||||
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), c.getSlabPalettes(),
|
||||
c.getStairPalettes(), c.getSlabThreshold(), interpolator, elevationInterpolator);
|
||||
prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), c.getSlabPalettes(),
|
||||
c.getStairPalettes(), c.getSlabThreshold(), sampler);
|
||||
}
|
||||
paletteLevel++;
|
||||
} else if(y <= sea) {
|
||||
justSet = false;
|
||||
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
|
||||
paletteLevel = 0;
|
||||
} else paletteLevel = 0;
|
||||
} else {
|
||||
if(justSet && c.doSlabs()) {
|
||||
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
|
||||
}
|
||||
justSet = false;
|
||||
paletteLevel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,15 @@ public class ConfigRegistry extends TerraRegistry<ConfigPack> {
|
||||
add(pack.getTemplate().getID(), pack);
|
||||
}
|
||||
|
||||
public static void loadAll(JavaPlugin main) {
|
||||
public static boolean loadAll(JavaPlugin main) {
|
||||
boolean valid = true;
|
||||
File packsFolder = new File(main.getDataFolder(), "packs");
|
||||
for(File dir : packsFolder.listFiles(File::isDirectory)) {
|
||||
try {
|
||||
getRegistry().load(dir);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".jar") || file.getName().endsWith(".terra"))) {
|
||||
@@ -44,8 +46,10 @@ public class ConfigRegistry extends TerraRegistry<ConfigPack> {
|
||||
getRegistry().load(new ZipFile(zip));
|
||||
} catch(IOException | ConfigException e) {
|
||||
e.printStackTrace();
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void load(ZipFile file) throws ConfigException {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class AirSpawn extends Requirement {
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y <= c.getSeaLevel()) return false;
|
||||
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class LandSpawn extends Requirement {
|
||||
public boolean matches(int x, int y, int z) {
|
||||
TerraWorld tw = TerraWorld.getWorld(getWorld());
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) > 0;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class OceanSpawn extends Requirement {
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y > c.getSeaLevel()) return false;
|
||||
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z));
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user