Advertisement
Guest User

1.14 end island code

a guest
Oct 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.40 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Comparator;
  3. import java.util.HashSet;
  4. import java.util.List;
  5. import java.util.Random;
  6. import java.util.Set;
  7.  
  8. public class Main {
  9.  
  10.     private static List<EndIsland> endIslands = new ArrayList<>();
  11.    
  12.     public static void main(String[] args) {
  13.         List<BlockPos> positions = new ArrayList<>();
  14.         for (int x = -768; x <= 768; x++) {
  15.             for (int z = -768; z <= 768; z++) {
  16.                 if (Math.round(Math.sqrt(x * x + z * z)) == 768) {
  17.                     positions.add(new BlockPos(x, 0, z));
  18.                 }
  19.             }
  20.         }
  21.        
  22.         System.out.println("Positions on the perimeter: " + positions.size());
  23.         for (BlockPos pos : positions)
  24.             doStuffWithExitPortal(pos.x, pos.z);
  25.        
  26.         endIslands.sort(Comparator.comparing(island -> -island.usableEndStone));
  27.        
  28.         int i = 0;
  29.         for (EndIsland island : endIslands) {
  30.             System.out.println("(" + island.x + ", " + island.z + ") " + island.usableEndStone + " usable out of " + island.totalEndStone + " total");
  31.             i++;
  32.             if (i > 200)
  33.                 break;
  34.         }
  35.     }
  36.  
  37.     public static void doStuffWithExitPortal(int islandX, int islandZ) {
  38.         //System.out.println(portalX + ", " + portalZ);
  39.         /*
  40.         LOGGER = LogManager.getLogger();
  41.         ORIGIN = new BlockPos(0, 0, 0);
  42.         SIZE_BITS_X = 1 + MathHelper.log2(MathHelper.smallestEncompassingPowerOfTwo(30000000));
  43.         SIZE_BITS_Z = BlockPos.SIZE_BITS_X;
  44.         SIZE_BITS_Y = 64 - BlockPos.SIZE_BITS_X - BlockPos.SIZE_BITS_Z;
  45.         BITS_X = (1L << BlockPos.SIZE_BITS_X) - 1L;
  46.         BITS_Y = (1L << BlockPos.SIZE_BITS_Y) - 1L;
  47.         BITS_Z = (1L << BlockPos.SIZE_BITS_Z) - 1L;
  48.         BIT_SHIFT_Z = BlockPos.SIZE_BITS_Y;
  49.         BIT_SHIFT_X = BlockPos.SIZE_BITS_Y + BlockPos.SIZE_BITS_Z;
  50.        
  51.         long long4 = 0L;
  52.         long4 |= ((long)x & BlockPos.BITS_X) << BlockPos.BIT_SHIFT_X;
  53.         long4 |= ((long)y & BlockPos.BITS_Y) << 0;
  54.         long4 |= ((long)z & BlockPos.BITS_Z) << BlockPos.BIT_SHIFT_Z;
  55.         return long4;
  56.         */
  57.        
  58.         final int NUM_X_BITS = 26;
  59.         final int NUM_Z_BITS = NUM_X_BITS;
  60.         final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS;
  61.         final int Y_SHIFT = 0 + NUM_Z_BITS;
  62.         final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;
  63.         final long X_MASK = (1L << NUM_X_BITS) - 1L;
  64.         final long Y_MASK = (1L << NUM_Y_BITS) - 1L;
  65.         final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
  66.         long seed = 0L;
  67.         seed |= ((long)islandX & X_MASK) << 38;
  68.         seed |= ((long)75.0 & Y_MASK) << 0;
  69.         seed |= ((long)islandZ & Z_MASK) << 12;
  70.         //System.out.println(seed);
  71.         Set<BlockPos> endStone = new HashSet<>();
  72.         generate(islandX, islandZ, new Random(seed), endStone);
  73.        
  74.         int totalCount = endStone.size();
  75.         int chunkX = islandX >> 4, chunkZ = islandZ >> 4;
  76.         int usableCount = 0;
  77.         for (BlockPos pos : endStone) {
  78.             if (pos.x >> 4 != chunkX || pos.z >> 4 != chunkZ) {
  79.                 if (pos.x != islandX && pos.z != islandZ) {
  80.                     usableCount++;
  81.                 }
  82.             }
  83.         }
  84.        
  85.         endIslands.add(new EndIsland(islandX, islandZ, totalCount, usableCount));
  86.     }
  87.  
  88.     public static boolean generate(int x, int z, Random rand, Set<BlockPos> endStone) {
  89.         float f = (float) (rand.nextInt(3) + 4);
  90.  
  91.         for (int i = 0; f > 0.5F; --i) {
  92.             for (int j = (int) Math.floor(-f); j <= Math.ceil(f); ++j) {
  93.                 for (int k = (int) Math.floor(-f); k <= Math.ceil(f); ++k) {
  94.                     if ((float) (j * j + k * k) <= (f + 1.0F) * (f + 1.0F)) {
  95.                         endStone.add(new BlockPos(x + j, i, z + k));
  96.                     }
  97.                 }
  98.             }
  99.  
  100.             f = (float) ((double) f - ((double) rand.nextInt(2) + 0.5D));
  101.         }
  102.  
  103.         return true;
  104.     }
  105.    
  106.     public static class EndIsland {
  107.         private int x;
  108.         private int z;
  109.         private int totalEndStone;
  110.         private int usableEndStone;
  111.        
  112.         public EndIsland(int x, int z, int totalEndStone, int usableEndStone) {
  113.             this.x = x;
  114.             this.z = z;
  115.             this.totalEndStone = totalEndStone;
  116.             this.usableEndStone = usableEndStone;
  117.         }
  118.     }
  119.  
  120.     public static class BlockPos {
  121.         private int x, y, z;
  122.  
  123.         public BlockPos(int x, int y, int z) {
  124.             this.x = x;
  125.             this.y = y;
  126.             this.z = z;
  127.         }
  128.  
  129.         @Override
  130.         public int hashCode() {
  131.             final int prime = 31;
  132.             int result = 1;
  133.             result = prime * result + x;
  134.             result = prime * result + y;
  135.             result = prime * result + z;
  136.             return result;
  137.         }
  138.  
  139.         @Override
  140.         public boolean equals(Object obj) {
  141.             if (this == obj)
  142.                 return true;
  143.             if (obj == null)
  144.                 return false;
  145.             if (getClass() != obj.getClass())
  146.                 return false;
  147.             BlockPos other = (BlockPos) obj;
  148.             if (x != other.x)
  149.                 return false;
  150.             if (y != other.y)
  151.                 return false;
  152.             if (z != other.z)
  153.                 return false;
  154.             return true;
  155.         }
  156.     }
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement