Structure location is fast now

This commit is contained in:
dfsek 2020-10-08 22:44:12 -07:00
parent 6ec7ab9c72
commit 506e1e0e23
6 changed files with 65 additions and 13 deletions

View File

@ -39,14 +39,14 @@ public class AsyncBiomeFinder implements Runnable {
boolean toggle = true; boolean toggle = true;
main: for(int i = startRadius; i < maxRadius; i++) { main: for(int i = startRadius; i < maxRadius; i++) {
for(int j = 0; j < run; j++) { for(int j = 0; j < run; j++) {
if(checkBiome(x, z).equals(target)) break main;
if(toggle) x++; if(toggle) x++;
else x--; else x--;
if(checkBiome(x, z).equals(target)) break main;
} }
for(int j = 0; j < run; j++) { for(int j = 0; j < run; j++) {
if(checkBiome(x, z).equals(target)) break main;
if(toggle) z++; if(toggle) z++;
else z--; else z--;
if(checkBiome(x, z).equals(target)) break main;
} }
run++; run++;
toggle = !toggle; toggle = !toggle;

View File

@ -49,6 +49,8 @@ public class AsyncStructureFinder implements Runnable {
int z = centerZ; int z = centerZ;
int wid = target.getSpawn().getWidth() + 2*target.getSpawn().getSeparation(); int wid = target.getSpawn().getWidth() + 2*target.getSpawn().getSeparation();
x/=wid;
z/=wid;
int run = 1; int run = 1;
boolean toggle = true; boolean toggle = true;
@ -56,22 +58,22 @@ public class AsyncStructureFinder implements Runnable {
Vector spawn = null; Vector spawn = null;
main: for(int i = startRadius; i < maxRadius; i++) { main: for(int i = startRadius; i < maxRadius; i++) {
for(int j = 0; j < run; j++) { for(int j = 0; j < run; j++) {
if(toggle) x += 16; spawn = target.getSpawn().getChunkSpawn(x, z, seed);
else x -= 16;
spawn = target.getSpawn().getNearestSpawn(x, z, seed);
if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) { if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) {
found = true; found = true;
break main; break main;
} }
if(toggle) x += 1;
else x -= 1;
} }
for(int j = 0; j < run; j++) { for(int j = 0; j < run; j++) {
if(toggle) z += 16; spawn = target.getSpawn().getChunkSpawn(x, z, seed);
else z -= 16;
spawn = target.getSpawn().getNearestSpawn(x, z, seed);
if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) { if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) {
found = true; found = true;
break main; break main;
} }
if(toggle) z += 1;
else z -= 1;
} }
run++; run++;
toggle = !toggle; toggle = !toggle;
@ -79,8 +81,8 @@ public class AsyncStructureFinder implements Runnable {
if(found) { if(found) {
p.sendMessage("Located structure at (" + spawn.getBlockX() + ", " + spawn.getBlockZ() + ")."); p.sendMessage("Located structure at (" + spawn.getBlockX() + ", " + spawn.getBlockZ() + ").");
if(tp) { if(tp) {
int finalX = x; int finalX = spawn.getBlockX();
int finalZ = z; int finalZ = spawn.getBlockZ();
Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ))); Bukkit.getScheduler().runTask(Terra.getInstance(), () -> p.teleport(new Location(p.getWorld(), finalX, p.getLocation().getY(), finalZ)));
} }
} else if(p.isOnline()) p.sendMessage("Unable to locate structure. " + spawn); } else if(p.isOnline()) p.sendMessage("Unable to locate structure. " + spawn);

View File

@ -52,7 +52,7 @@ public class LocateCommand extends WorldCommand {
@Override @Override
public String getName() { public String getName() {
return tp ? "tp" : "locate"; return tp ? "teleport" : "locate";
} }
@Override @Override

View File

@ -0,0 +1,50 @@
package com.dfsek.terra.command.structure;
import com.dfsek.terra.command.type.DebugCommand;
import com.dfsek.terra.command.type.WorldCommand;
import com.dfsek.terra.structure.StructureSpawnRequirement;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class SpawnCommand extends WorldCommand implements DebugCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
Location p = sender.getLocation();
int x = p.getBlockX();
int y = p.getBlockY();
int z = p.getBlockZ();
boolean air = StructureSpawnRequirement.AIR.matches(world, x, y, z);
boolean ground = StructureSpawnRequirement.LAND.matches(world, x, y, z);
boolean sea = StructureSpawnRequirement.OCEAN.matches(world, x, y, z);
sender.sendMessage("AIR: " + air + "\nLAND: " + ground + "\nOCEAN: " + sea);
return true;
}
@Override
public String getName() {
return "spawn";
}
@Override
public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@ -20,7 +20,7 @@ public class StructureCommand extends PlayerCommand {
@Override @Override
public List<com.dfsek.terra.command.type.Command> getSubCommands() { public List<com.dfsek.terra.command.type.Command> getSubCommands() {
return Arrays.asList(new ExportCommand(), new LoadCommand(), new LocateCommand(false), new LocateCommand(true)); return Arrays.asList(new ExportCommand(), new LoadCommand(), new LocateCommand(false), new LocateCommand(true), new SpawnCommand());
} }
@Override @Override

View File

@ -49,7 +49,7 @@ public class GridSpawn {
* @param seed Seed for RNG * @param seed Seed for RNG
* @return Vector representing spawnpoint * @return Vector representing spawnpoint
*/ */
private Vector getChunkSpawn(int structureChunkX, int structureChunkZ, long seed) { public Vector getChunkSpawn(int structureChunkX, int structureChunkZ, long seed) {
Random r = new Random(MathUtil.getCarverChunkSeed(structureChunkX, structureChunkZ, seed)); Random r = new Random(MathUtil.getCarverChunkSeed(structureChunkX, structureChunkZ, seed));
int offsetX = r.nextInt(width); int offsetX = r.nextInt(width);
int offsetZ = r.nextInt(width); int offsetZ = r.nextInt(width);