PersonTheCat

Random Chunk Selctor

Jul 10th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package personthecat.seededchunkmatcher;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Random;
  5.  
  6. public class Main
  7. {
  8.     static Random rand = new Random(12345);
  9.    
  10.     public static void main(String[] args)
  11.     {
  12.         int[][] coordinates = new int[][]
  13.            
  14.             {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  15.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  16.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  17.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  18.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  19.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  20.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  21.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  22.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
  23.              {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}};
  24.        
  25.         boolean[][] matches = new boolean[10][10];
  26.        
  27.         int ID = getNumberForName("iron_ore");
  28.        
  29.         System.out.println("Name ID: " + ID);
  30.              
  31.         for (int x = 0; x < coordinates.length; x++)
  32.         {
  33.             for (int y = 0; y < coordinates[0].length; y++)
  34.             {
  35.                 int concatenatedValues = concatenateNumbers(ID, x, y);
  36.  
  37.                 matches[x][y] = (((double) rand.nextInt(concatenatedValues) / (double) concatenatedValues) > 0.75);
  38.             }
  39.         }
  40.        
  41.         for (int x = 0; x < matches.length; x++)
  42.         {
  43.             System.out.println(Arrays.toString(matches[x]));
  44.         }
  45.     }
  46.    
  47.     /*
  48.      * Could concatenate these numbers to produce a more unique
  49.      * value of every string. It's easier for me to work with
  50.      * smaller numbers, however.
  51.      */
  52.     private static int getNumberForName(String name)
  53.     {
  54.         int number = 0;
  55.        
  56.         for (Character c : name.toCharArray())
  57.         {
  58.             number += Character.getNumericValue(c);
  59.         }
  60.  
  61.         return number;
  62.     }
  63.    
  64.     private static int concatenateNumbers(int... numbers)
  65.     {
  66.         StringBuilder sb = new StringBuilder(numbers.length);
  67.        
  68.         for (int number : numbers)
  69.         {
  70.             sb.append(Math.abs(number));
  71.         }
  72.        
  73.         return Integer.valueOf(sb.toString());
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment