Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset issues resulting from accidental merge of #13 #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ChunkPos, CompletableFuture<CachedChunkData>> cache;
private final LoadingCache<ChunkPos, CompletableFuture<CachedChunkData>> cache;
private final CustomBiomeProvider customBiomeProvider;

private final int yOffset;

private final Material surfaceMaterial;
private final Map<String, Material> materialMapping;
Expand All @@ -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(
Expand All @@ -95,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
}
Expand Down
Loading