diff --git a/build.gradle.kts b/build.gradle.kts index e93c63ae9..3dd1681c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,7 +56,7 @@ dependencies { implementation("net.jafama:jafama:2.3.2") - implementation(name = "Tectonic-1.0.0", group = "") + implementation(name = "Tectonic-1.0.1", group = "") // JUnit. diff --git a/lib/Tectonic-1.0.0.jar b/lib/Tectonic-1.0.1.jar similarity index 66% rename from lib/Tectonic-1.0.0.jar rename to lib/Tectonic-1.0.1.jar index 577e6ca4c..dc4dd3740 100644 Binary files a/lib/Tectonic-1.0.0.jar and b/lib/Tectonic-1.0.1.jar differ diff --git a/src/main/java/com/dfsek/terra/command/ReloadCommand.java b/src/main/java/com/dfsek/terra/command/ReloadCommand.java index d21c19e35..42ebba93f 100644 --- a/src/main/java/com/dfsek/terra/command/ReloadCommand.java +++ b/src/main/java/com/dfsek/terra/command/ReloadCommand.java @@ -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; diff --git a/src/main/java/com/dfsek/terra/generation/Sampler.java b/src/main/java/com/dfsek/terra/generation/Sampler.java index 4f5254e02..1bc098331 100644 --- a/src/main/java/com/dfsek/terra/generation/Sampler.java +++ b/src/main/java/com/dfsek/terra/generation/Sampler.java @@ -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)); } } diff --git a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java index 337f01ce6..8456291ff 100644 --- a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java +++ b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java @@ -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> slabs, - Map> 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> slabs, + Map> stairs, double thresh, Sampler sampler) { + if(sampler.sample(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) { if(stairs != null) { Palette 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> slabs, + Map> stairs, double thresh, Sampler sampler) { + if(sampler.sample(block.getBlockX(), block.getBlockY() + 0.4, block.getBlockZ()) > thresh) { + if(stairs != null) { + Palette 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 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; + } } } } diff --git a/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java b/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java index d2b11fbd6..5c961e5d6 100644 --- a/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java +++ b/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java @@ -29,13 +29,15 @@ public class ConfigRegistry extends TerraRegistry { 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 { getRegistry().load(new ZipFile(zip)); } catch(IOException | ConfigException e) { e.printStackTrace(); + valid = false; } } + return valid; } public void load(ZipFile file) throws ConfigException { diff --git a/src/main/java/com/dfsek/terra/structure/spawn/AirSpawn.java b/src/main/java/com/dfsek/terra/structure/spawn/AirSpawn.java index 44bcc684c..ee1037798 100644 --- a/src/main/java/com/dfsek/terra/structure/spawn/AirSpawn.java +++ b/src/main/java/com/dfsek/terra/structure/spawn/AirSpawn.java @@ -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; } } diff --git a/src/main/java/com/dfsek/terra/structure/spawn/LandSpawn.java b/src/main/java/com/dfsek/terra/structure/spawn/LandSpawn.java index 50f210215..ffc6132b6 100644 --- a/src/main/java/com/dfsek/terra/structure/spawn/LandSpawn.java +++ b/src/main/java/com/dfsek/terra/structure/spawn/LandSpawn.java @@ -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; } } diff --git a/src/main/java/com/dfsek/terra/structure/spawn/OceanSpawn.java b/src/main/java/com/dfsek/terra/structure/spawn/OceanSpawn.java index fd6aa864a..936a51940 100644 --- a/src/main/java/com/dfsek/terra/structure/spawn/OceanSpawn.java +++ b/src/main/java/com/dfsek/terra/structure/spawn/OceanSpawn.java @@ -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; } } diff --git a/src/main/resources/lang/en_us.yml b/src/main/resources/lang/en_us.yml index 2c7228527..cfcfcff3c 100644 --- a/src/main/resources/lang/en_us.yml +++ b/src/main/resources/lang/en_us.yml @@ -11,6 +11,7 @@ command: players-only: "Command is for players only." world: "This command must be executed in a Terra world!" 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\"" main-menu: - "--------------------Terra--------------------"