mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Structure location is fast now
This commit is contained in:
parent
6ec7ab9c72
commit
506e1e0e23
@ -39,14 +39,14 @@ public class AsyncBiomeFinder implements Runnable {
|
||||
boolean toggle = true;
|
||||
main: for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(checkBiome(x, z).equals(target)) break main;
|
||||
if(toggle) x++;
|
||||
else x--;
|
||||
if(checkBiome(x, z).equals(target)) break main;
|
||||
}
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(checkBiome(x, z).equals(target)) break main;
|
||||
if(toggle) z++;
|
||||
else z--;
|
||||
if(checkBiome(x, z).equals(target)) break main;
|
||||
}
|
||||
run++;
|
||||
toggle = !toggle;
|
||||
|
@ -49,6 +49,8 @@ public class AsyncStructureFinder implements Runnable {
|
||||
int z = centerZ;
|
||||
|
||||
int wid = target.getSpawn().getWidth() + 2*target.getSpawn().getSeparation();
|
||||
x/=wid;
|
||||
z/=wid;
|
||||
|
||||
int run = 1;
|
||||
boolean toggle = true;
|
||||
@ -56,22 +58,22 @@ public class AsyncStructureFinder implements Runnable {
|
||||
Vector spawn = null;
|
||||
main: for(int i = startRadius; i < maxRadius; i++) {
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(toggle) x += 16;
|
||||
else x -= 16;
|
||||
spawn = target.getSpawn().getNearestSpawn(x, z, seed);
|
||||
spawn = target.getSpawn().getChunkSpawn(x, z, seed);
|
||||
if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) x += 1;
|
||||
else x -= 1;
|
||||
}
|
||||
for(int j = 0; j < run; j++) {
|
||||
if(toggle) z += 16;
|
||||
else z -= 16;
|
||||
spawn = target.getSpawn().getNearestSpawn(x, z, seed);
|
||||
spawn = target.getSpawn().getChunkSpawn(x, z, seed);
|
||||
if(isValidSpawn(spawn.getBlockX(), spawn.getBlockZ())) {
|
||||
found = true;
|
||||
break main;
|
||||
}
|
||||
if(toggle) z += 1;
|
||||
else z -= 1;
|
||||
}
|
||||
run++;
|
||||
toggle = !toggle;
|
||||
@ -79,8 +81,8 @@ public class AsyncStructureFinder implements Runnable {
|
||||
if(found) {
|
||||
p.sendMessage("Located structure at (" + spawn.getBlockX() + ", " + spawn.getBlockZ() + ").");
|
||||
if(tp) {
|
||||
int finalX = x;
|
||||
int finalZ = z;
|
||||
int finalX = spawn.getBlockX();
|
||||
int finalZ = spawn.getBlockZ();
|
||||
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);
|
||||
|
@ -52,7 +52,7 @@ public class LocateCommand extends WorldCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return tp ? "tp" : "locate";
|
||||
return tp ? "teleport" : "locate";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ public class StructureCommand extends PlayerCommand {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -49,7 +49,7 @@ public class GridSpawn {
|
||||
* @param seed Seed for RNG
|
||||
* @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));
|
||||
int offsetX = r.nextInt(width);
|
||||
int offsetZ = r.nextInt(width);
|
||||
|
Loading…
x
Reference in New Issue
Block a user