Advertisement
Earthcomputer

Finding some crap location on some crap server

Mar 10th, 2019
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package carpet;
  2.  
  3. import net.minecraft.init.Biomes;
  4. import net.minecraft.init.Bootstrap;
  5. import net.minecraft.world.WorldType;
  6. import net.minecraft.world.biome.Biome;
  7. import net.minecraft.world.gen.ChunkGeneratorSettings;
  8. import net.minecraft.world.gen.layer.GenLayer;
  9. import net.minecraft.world.gen.layer.IntCache;
  10.  
  11. public class Main {
  12.  
  13.     private static final long SEED = 2791111690993685248L;
  14.     private static final int STRIDE = 15 * 16;
  15.     private static GenLayer biomeGen;
  16.     private static int DESERT, DESERT_HILLS, DESERT_M;
  17.  
  18.     public static void main(String[] args) {
  19.         Bootstrap.register();
  20.  
  21.         DESERT = Biome.getIdForBiome(Biomes.DESERT);
  22.         DESERT_HILLS = Biome.getIdForBiome(Biomes.DESERT_HILLS);
  23.         DESERT_M = Biome.getIdForBiome(Biomes.MUTATED_DESERT);
  24.  
  25.         biomeGen = GenLayer.initializeAllBiomeGenerators(SEED, WorldType.DEFAULT, new ChunkGeneratorSettings.Factory().build())[1];
  26.  
  27.         int minDistance = Integer.MAX_VALUE;
  28.         int x = 0, z = 0;
  29.         if (!checkArea(0, 0)) {
  30.             for (int radius = STRIDE; radius * radius <= minDistance; radius += STRIDE) {
  31.                 for (int dx = radius; dx > -radius; dx -= STRIDE) {
  32.                     int dz = Math.abs(dx) - STRIDE;
  33.                     if (checkArea(dx, dz)) {
  34.                         int distance = dx * dx + dz * dz;
  35.                         if (distance < minDistance) {
  36.                             minDistance = distance;
  37.                             x = dx;
  38.                             z = dz;
  39.                         }
  40.                     }
  41.                 }
  42.                 for (int dx = -radius; dx < radius; dx += STRIDE) {
  43.                     int dz = STRIDE - Math.abs(dx);
  44.                     if (checkArea(dx, dz)) {
  45.                         int distance = dx * dx + dz * dz;
  46.                         if (distance < minDistance) {
  47.                             minDistance = distance;
  48.                             x = dx;
  49.                             z = dz;
  50.                         }
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.  
  56.         System.out.println(x + ", " + z);
  57.     }
  58.  
  59.     private static boolean checkArea(int x, int z) {
  60.         System.out.println("Searching " + x + ", " + z);
  61.  
  62.         if (!isDesert(biomeGen.getInts(x, z, 1, 1)[0]))
  63.             return false;
  64.  
  65.         final int SIZE = 29 * 16;
  66.  
  67.         int[] biomes = biomeGen.getInts(x - 14 * 16, z - 14 * 16, SIZE, SIZE);
  68.         boolean[][] desertChunks = new boolean[29][29];
  69.         for (int chunkX = 0; chunkX < 29; chunkX++) {
  70.             innerChunkLoop:
  71.             for (int chunkZ = 0; chunkZ < 29; chunkZ++) {
  72.                 for (int dx = 0; dx < 16; dx++) {
  73.                     for (int dz = 0; dz < 16; dz++) {
  74.                         if (!isDesert(biomes[chunkX * 16 + dx + SIZE * (chunkZ * 16 + dz)]))
  75.                             continue innerChunkLoop;
  76.                     }
  77.                 }
  78.                 desertChunks[chunkX][chunkZ] = true;
  79.             }
  80.         }
  81.  
  82.         for (int chunkX = 0; chunkX < 15; chunkX++) {
  83.             innerOuter:
  84.             for (int chunkZ = 0; chunkZ < 15; chunkZ++) {
  85.                 for (int dx = 0; dx < 15; dx++) {
  86.                     for (int dz = 0; dz < 15; dz++) {
  87.                         if (!desertChunks[chunkX + dx][chunkZ + dz])
  88.                             continue innerOuter;
  89.                     }
  90.                 }
  91.                 return true;
  92.             }
  93.         }
  94.  
  95.         IntCache.resetIntCache();
  96.  
  97.         return false;
  98.     }
  99.  
  100.     private static boolean isDesert(int biome) {
  101.         return biome == DESERT || biome == DESERT_HILLS || biome == DESERT_M;
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement