Advertisement
Gdame

Untitled

Aug 21st, 2021 (edited)
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. @Override
  2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  3. Player p = (Player) sender;
  4. List<Chunk> chunks = getChunks(p.getLocation().getChunk(), 10);
  5. Chunk slimeChunk = getNearestChunk(p.getLocation().getChunk(), chunks);
  6. p.sendMessage(String.valueOf(slimeChunk.getX()*16) + " " + String.valueOf(slimeChunk.getZ()*16));
  7. return true;
  8. }
  9.  
  10. public ArrayList<Chunk> getChunks(Chunk centerChunk, int radius) {
  11. ArrayList<Chunk> chunks = new ArrayList<>();
  12. chunks.add(centerChunk);
  13. for (int x = centerChunk.getX() - radius; x < centerChunk.getX() + radius; x++) {
  14. for (int z = centerChunk.getZ() - radius; z < centerChunk.getZ() + radius; z++) {
  15. Chunk chunk = centerChunk.getWorld().getChunkAt(x, z);
  16. if (chunk.isSlimeChunk()) {
  17. chunks.add(chunk);
  18. }
  19. }
  20. }
  21. return chunks;
  22. }
  23.  
  24. public Chunk getNearestChunk(Chunk origin, List<Chunk> chunks) {
  25. Chunk nearestChunk = null;
  26. for (Chunk chunk : chunks) {
  27. if (nearestChunk == null) {
  28. nearestChunk = chunk;
  29. continue;
  30. }
  31. if (distance(origin, chunk) > distance(origin, nearestChunk))
  32. continue;
  33. nearestChunk = chunk;
  34. }
  35. return nearestChunk;
  36. }
  37.  
  38. public double distance(Chunk firstChunk, Chunk secondChunk) {
  39.  
  40. double ac = Math.abs(secondChunk.getZ() - firstChunk.getZ());
  41. double cb = Math.abs(secondChunk.getX() - firstChunk.getX());
  42.  
  43. return Math.hypot(ac, cb);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement