From a34b3b652b48bde72448bdeb849fec78fb2a0384 Mon Sep 17 00:00:00 2001 From: Smyler Date: Sun, 17 Sep 2023 19:55:48 +0200 Subject: [PATCH 1/2] TPLL: read generation settings from the generator --- .../terraplusminus/commands/TpllCommand.java | 44 ++++++++++++------- .../gen/RealWorldGenerator.java | 13 ++++-- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java b/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java index e585019..bffb3c8 100644 --- a/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java +++ b/src/main/java/de/btegermany/terraplusminus/commands/TpllCommand.java @@ -4,20 +4,24 @@ import com.google.common.io.ByteStreams; import de.btegermany.terraplusminus.Terraplusminus; import de.btegermany.terraplusminus.data.TerraConnector; +import de.btegermany.terraplusminus.gen.RealWorldGenerator; import de.btegermany.terraplusminus.utils.PluginMessageUtil; import io.papermc.lib.PaperLib; import net.buildtheearth.terraminusminus.generator.EarthGeneratorSettings; +import net.buildtheearth.terraminusminus.projection.GeographicProjection; import net.buildtheearth.terraminusminus.projection.OutOfProjectionBoundsException; import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; -public class TpllCommand implements CommandExecutor { +import static org.bukkit.ChatColor.RED; + - private final EarthGeneratorSettings bteGeneratorSettings = EarthGeneratorSettings.parse(EarthGeneratorSettings.BTE_DEFAULT_SETTINGS); +public class TpllCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { @@ -101,28 +105,36 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command if (args.length >= 2) { if (player.hasPermission("t+-.tpll")) { - int xOffset = Terraplusminus.config.getInt("terrain_offset.x"); - int yOffset = Terraplusminus.config.getInt("terrain_offset.y"); - int zOffset = Terraplusminus.config.getInt("terrain_offset.z"); - Double minLat = Terraplusminus.config.getDouble("min_latitude"); - Double maxLat = Terraplusminus.config.getDouble("max_latitude"); - Double minLon = Terraplusminus.config.getDouble("min_longitude"); - Double maxLon = Terraplusminus.config.getDouble("max_longitude"); + double minLat = Terraplusminus.config.getDouble("min_latitude"); + double maxLat = Terraplusminus.config.getDouble("max_latitude"); + double minLon = Terraplusminus.config.getDouble("min_longitude"); + double maxLon = Terraplusminus.config.getDouble("max_longitude"); double[] coordinates = new double[2]; coordinates[1] = Double.parseDouble(args[0].replace(",", "").replace("°", "")); coordinates[0] = Double.parseDouble(args[1].replace("°", "")); - double[] mcCoordinates = new double[0]; + ChunkGenerator generator = player.getWorld().getGenerator(); + if (!(generator instanceof RealWorldGenerator)) { + commandSender.sendMessage(RED + "Must be in a Terra 1 to 1 world!"); + return true; + } + RealWorldGenerator terraGenerator = (RealWorldGenerator) generator; + EarthGeneratorSettings generatorSettings = terraGenerator.getSettings(); + GeographicProjection projection = generatorSettings.projection(); + int yOffset = terraGenerator.getYOffset(); + + double[] mcCoordinates; try { - mcCoordinates = bteGeneratorSettings.projection().fromGeo(coordinates[0], coordinates[1]); + mcCoordinates = projection.fromGeo(coordinates[0], coordinates[1]); } catch (OutOfProjectionBoundsException e) { - e.printStackTrace(); + commandSender.sendMessage(RED + "Location is not within projection bounds"); + return true; } if (minLat != 0 && maxLat != 0 && minLon != 0 && maxLon != 0 && !player.hasPermission("t+-.admin")) { if (coordinates[1] < minLat || coordinates[0] < minLon || coordinates[1] > maxLat || coordinates[0] > maxLon) { - player.sendMessage(Terraplusminus.config.getString("prefix") + "§cYou cannot tpll to these coordinates, because this area is being worked on by another build team."); + player.sendMessage(Terraplusminus.config.getString("prefix") + RED + "You cannot tpll to these coordinates, because this area is being worked on by another build team."); return true; } } @@ -184,13 +196,13 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command return true; } } - Location location = new Location(player.getWorld(), mcCoordinates[0] + xOffset, height, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + Location location = new Location(player.getWorld(), mcCoordinates[0], height, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); if (PaperLib.isChunkGenerated(location)) { if (args.length >= 3) { - location = new Location(player.getWorld(), mcCoordinates[0] + xOffset, height, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + location = new Location(player.getWorld(), mcCoordinates[0], height, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); } else { - location = new Location(player.getWorld(), mcCoordinates[0] + xOffset, player.getWorld().getHighestBlockYAt((int) mcCoordinates[0] + xOffset, (int) mcCoordinates[1] + zOffset) + 1, mcCoordinates[1] + zOffset, player.getLocation().getYaw(), player.getLocation().getPitch()); + location = new Location(player.getWorld(), mcCoordinates[0], player.getWorld().getHighestBlockYAt((int) mcCoordinates[0], (int) mcCoordinates[1]) + 1, mcCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()); } } else { player.sendMessage(Terraplusminus.config.getString("prefix") + "§7Location is generating. Please wait a moment..."); diff --git a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java index 0ab19dd..dc37f6c 100644 --- a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java +++ b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java @@ -5,6 +5,7 @@ import de.btegermany.terraplusminus.Terraplusminus; import de.btegermany.terraplusminus.gen.tree.TreePopulator; import de.btegermany.terraplusminus.utils.ConfigurationHelper; +import lombok.Getter; import net.buildtheearth.terraminusminus.generator.CachedChunkData; import net.buildtheearth.terraminusminus.generator.ChunkDataLoader; import net.buildtheearth.terraminusminus.generator.EarthGeneratorSettings; @@ -37,12 +38,16 @@ public class RealWorldGenerator extends ChunkGenerator { + + @Getter + private final EarthGeneratorSettings settings; + @Getter + private final int yOffset; private Location spawnLocation = null; - public LoadingCache> cache; + private final LoadingCache> cache; private final CustomBiomeProvider customBiomeProvider; - private final int yOffset; private final Material surfaceMaterial; private final Map materialMapping; @@ -66,13 +71,13 @@ public RealWorldGenerator() { ); this.yOffset = Terraplusminus.config.getInt("terrain_offset.y"); - settings = settings.withProjection(projection); + this.settings = settings.withProjection(projection); this.customBiomeProvider = new CustomBiomeProvider(); this.cache = CacheBuilder.newBuilder() .expireAfterAccess(5L, TimeUnit.MINUTES) .softValues() - .build(new ChunkDataLoader(settings)); + .build(new ChunkDataLoader(this.settings)); this.surfaceMaterial = ConfigurationHelper.getMaterial(Terraplusminus.config, "surface_material", GRASS_BLOCK); this.materialMapping = Map.of( From 988f2f9f461bfe19e24503ab034e7c9cbc6a99d0 Mon Sep 17 00:00:00 2001 From: Smyler Date: Fri, 6 Oct 2023 17:38:42 +0200 Subject: [PATCH 2/2] Fix y offset not being taken into account when calculating max cube Y --- .../de/btegermany/terraplusminus/gen/RealWorldGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java index dc37f6c..d3693f6 100644 --- a/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java +++ b/src/main/java/de/btegermany/terraplusminus/gen/RealWorldGenerator.java @@ -100,7 +100,7 @@ public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, // We start by finding the lowest 16x16x16 cube that's not underground //TODO expose the minimum surface Y in Terra-- so we don't have to scan this way int minSurfaceCubeY = blockToCube(minWorldY - this.yOffset); - int maxWorldCubeY = blockToCube(maxWorldY); + int maxWorldCubeY = blockToCube(maxWorldY - this.yOffset); if (terraData.aboveSurface(minSurfaceCubeY)) { return; // All done, it's all air }