slabs and stairs generate on ceiling

This commit is contained in:
dfsek
2020-12-02 21:34:45 -07:00
parent 7db83c1dee
commit 3807b8c277
10 changed files with 76 additions and 36 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ dependencies {
implementation("net.jafama:jafama:2.3.2") implementation("net.jafama:jafama:2.3.2")
implementation(name = "Tectonic-1.0.0", group = "") implementation(name = "Tectonic-1.0.1", group = "")
// JUnit. // JUnit.
Binary file not shown.
@@ -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) { public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
PluginConfig.load(getMain()); PluginConfig.load(getMain());
LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language. LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language.
ConfigRegistry.loadAll(getMain()); if(!ConfigRegistry.loadAll(getMain())) LangUtil.send("command.reload-error", sender);
TerraWorld.invalidate(); TerraWorld.invalidate();
LangUtil.send("command.reload", sender); LangUtil.send("command.reload", sender);
return true; return true;
@@ -13,6 +13,6 @@ public class Sampler {
} }
public double sample(double x, double y, double z) { 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.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.Stairs; import org.bukkit.block.data.type.Stairs;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@@ -85,33 +87,15 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
return c.getPalette().getPalette(y); return c.getPalette().getPalette(y);
} }
private static void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs, private static void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) { Map<Material, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
double elevation = elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ()); if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4 - elevation, block.getBlockZ()) > thresh) {
if(stairs != null) { if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getMaterial()); Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
if(stairPalette != null) { if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()); BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
Stairs stairNew = (Stairs) stair.clone(); Stairs stairNew = (Stairs) stair.clone();
int elevationN = (int) elevationInterpolator.getElevation(block.getBlockX(), block.getBlockZ() - 1); // Northern elevation if(placePart(orig, chunk, block, thresh, sampler, stairNew)) return;
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;
}
} }
} }
BlockData slab = slabs.getOrDefault(down.getMaterial(), DataUtil.BLANK_PALETTE).get(0, block.getBlockX(), block.getBlockZ()); 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 @Override
public void attachProfiler(WorldProfiler p) { public void attachProfiler(WorldProfiler p) {
super.attachProfiler(p); super.attachProfiler(p);
@@ -158,19 +182,30 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
int sea = c.getSeaLevel(); int sea = c.getSeaLevel();
Palette<BlockData> seaPalette = c.getOceanPalette(); Palette<BlockData> seaPalette = c.getOceanPalette();
boolean justSet = false;
BlockData data = null;
for(int y = world.getMaxHeight() - 1; y >= 0; y--) { for(int y = world.getMaxHeight() - 1; y >= 0; y--) {
if(sampler.sample(x, y, z) > 0) { 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); chunk.setBlock(x, y, z, data);
if(paletteLevel == 0 && c.doSlabs() && y < 255) { if(paletteLevel == 0 && c.doSlabs() && y < 255) {
prepareBlockPart(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), c.getSlabPalettes(), prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector(x, y + 1, z), c.getSlabPalettes(),
c.getStairPalettes(), c.getSlabThreshold(), interpolator, elevationInterpolator); c.getStairPalettes(), c.getSlabThreshold(), sampler);
} }
paletteLevel++; paletteLevel++;
} else if(y <= sea) { } else if(y <= sea) {
justSet = false;
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig)); chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
paletteLevel = 0; 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); 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"); File packsFolder = new File(main.getDataFolder(), "packs");
for(File dir : packsFolder.listFiles(File::isDirectory)) { for(File dir : packsFolder.listFiles(File::isDirectory)) {
try { try {
getRegistry().load(dir); getRegistry().load(dir);
} catch(ConfigException e) { } catch(ConfigException e) {
e.printStackTrace(); e.printStackTrace();
valid = false;
} }
} }
for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".jar") || file.getName().endsWith(".terra"))) { 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)); getRegistry().load(new ZipFile(zip));
} catch(IOException | ConfigException e) { } catch(IOException | ConfigException e) {
e.printStackTrace(); e.printStackTrace();
valid = false;
} }
} }
return valid;
} }
public void load(ZipFile file) throws ConfigException { 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); UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeTemplate c = b.getConfig(); BiomeTemplate c = b.getConfig();
if(y <= c.getSeaLevel()) return false; if(y <= c.getSeaLevel()) return false;
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z)); double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0; 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) { public boolean matches(int x, int y, int z) {
TerraWorld tw = TerraWorld.getWorld(getWorld()); TerraWorld tw = TerraWorld.getWorld(getWorld());
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z)); double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) > 0; 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); UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeTemplate c = b.getConfig(); BiomeTemplate c = b.getConfig();
if(y > c.getSeaLevel()) return false; if(y > c.getSeaLevel()) return false;
int yf = (int) (y - ((WorldGenerator) b.getGenerator()).getElevation(x, z)); double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
return b.getGenerator().getNoise(getNoise(), getWorld(), x, yf, z) <= 0; return b.getGenerator().getNoise(getNoise(), getWorld(), x, y, z) + elevation <= 0;
} }
} }
+1
View File
@@ -11,6 +11,7 @@ command:
players-only: "Command is for players only." players-only: "Command is for players only."
world: "This command must be executed in a Terra world!" world: "This command must be executed in a Terra world!"
reload: "Reloaded Terra config." reload: "Reloaded Terra config."
reload-error: "Errors occurred while reloading Terra configurations. See logs for more information."
version: "This server is running Terra version \"%1$s\", implementing Gaea version \"%2$s\"" version: "This server is running Terra version \"%1$s\", implementing Gaea version \"%2$s\""
main-menu: main-menu:
- "--------------------Terra--------------------" - "--------------------Terra--------------------"