Implement tpbiome command

This commit is contained in:
dfsek
2020-10-02 00:49:06 -07:00
parent 8b0c2030ee
commit d91f5b03d0
6 changed files with 134 additions and 45 deletions

View File

@@ -1,4 +1,63 @@
package com.dfsek.terra.async;
public class AsyncBiomeFinder {
import com.dfsek.terra.Terra;
import com.dfsek.terra.biome.TerraBiomeGrid;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.generation.GenerationPhase;
public class AsyncBiomeFinder implements Runnable {
private final TerraBiomeGrid grid;
private final int centerX;
private final int centerZ;
private final int startRadius;
private final int maxRadius;
private final Biome target;
private final Player p;
private final boolean tp;
public AsyncBiomeFinder(TerraBiomeGrid grid, Biome target, Player p, int startRadius, int maxRadius, boolean tp) {
this.grid = grid;
this.target = target;
this.p = p;
this.centerX = p.getLocation().getBlockX();
this.centerZ = p.getLocation().getBlockZ();
this.startRadius = startRadius;
this.maxRadius = maxRadius;
this.tp = tp;
}
@Override
public void run() {
int x = centerX;
int z = centerZ;
int run = 1;
boolean toggle = true;
main: for(int i = startRadius; i < maxRadius; i++) {
for(int j = 0; j < run; j++) {
if(toggle) x++;
else x--;
if(checkBiome(x, z).equals(target)) break main;
}
for(int j = 0; j < run; j++) {
if(toggle) z++;
else z--;
if(checkBiome(x, z).equals(target)) break main;
}
run++;
toggle = !toggle;
}
if(checkBiome(x, z).equals(target) && p.isOnline()) {
p.sendMessage("Located biome at (" + x + ", " + z + ").");
if(tp) {
int finalX = x;
int finalZ = z;
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 biome.");
}
private Biome checkBiome(int x, int z) {
return grid.getBiome(x, z, GenerationPhase.POST_GEN);
}
}