Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Comparator;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Random;
- import java.util.Set;
- public class Main {
- private static List<EndIsland> endIslands = new ArrayList<>();
- public static void main(String[] args) {
- List<BlockPos> positions = new ArrayList<>();
- for (int x = -768; x <= 768; x++) {
- for (int z = -768; z <= 768; z++) {
- if (Math.round(Math.sqrt(x * x + z * z)) == 768) {
- positions.add(new BlockPos(x, 0, z));
- }
- }
- }
- System.out.println("Positions on the perimeter: " + positions.size());
- for (BlockPos pos : positions)
- doStuffWithExitPortal(pos.x, pos.z);
- endIslands.sort(Comparator.comparing(island -> -island.usableEndStone));
- int i = 0;
- for (EndIsland island : endIslands) {
- System.out.println("(" + island.x + ", " + island.z + ") " + island.usableEndStone + " usable out of " + island.totalEndStone + " total");
- i++;
- if (i > 200)
- break;
- }
- }
- public static void doStuffWithExitPortal(int islandX, int islandZ) {
- //System.out.println(portalX + ", " + portalZ);
- /*
- LOGGER = LogManager.getLogger();
- ORIGIN = new BlockPos(0, 0, 0);
- SIZE_BITS_X = 1 + MathHelper.log2(MathHelper.smallestEncompassingPowerOfTwo(30000000));
- SIZE_BITS_Z = BlockPos.SIZE_BITS_X;
- SIZE_BITS_Y = 64 - BlockPos.SIZE_BITS_X - BlockPos.SIZE_BITS_Z;
- BITS_X = (1L << BlockPos.SIZE_BITS_X) - 1L;
- BITS_Y = (1L << BlockPos.SIZE_BITS_Y) - 1L;
- BITS_Z = (1L << BlockPos.SIZE_BITS_Z) - 1L;
- BIT_SHIFT_Z = BlockPos.SIZE_BITS_Y;
- BIT_SHIFT_X = BlockPos.SIZE_BITS_Y + BlockPos.SIZE_BITS_Z;
- long long4 = 0L;
- long4 |= ((long)x & BlockPos.BITS_X) << BlockPos.BIT_SHIFT_X;
- long4 |= ((long)y & BlockPos.BITS_Y) << 0;
- long4 |= ((long)z & BlockPos.BITS_Z) << BlockPos.BIT_SHIFT_Z;
- return long4;
- */
- final int NUM_X_BITS = 26;
- final int NUM_Z_BITS = NUM_X_BITS;
- final int NUM_Y_BITS = 64 - NUM_X_BITS - NUM_Z_BITS;
- final int Y_SHIFT = 0 + NUM_Z_BITS;
- final int X_SHIFT = Y_SHIFT + NUM_Y_BITS;
- final long X_MASK = (1L << NUM_X_BITS) - 1L;
- final long Y_MASK = (1L << NUM_Y_BITS) - 1L;
- final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
- long seed = 0L;
- seed |= ((long)islandX & X_MASK) << 38;
- seed |= ((long)75.0 & Y_MASK) << 0;
- seed |= ((long)islandZ & Z_MASK) << 12;
- //System.out.println(seed);
- Set<BlockPos> endStone = new HashSet<>();
- generate(islandX, islandZ, new Random(seed), endStone);
- int totalCount = endStone.size();
- int chunkX = islandX >> 4, chunkZ = islandZ >> 4;
- int usableCount = 0;
- for (BlockPos pos : endStone) {
- if (pos.x >> 4 != chunkX || pos.z >> 4 != chunkZ) {
- if (pos.x != islandX && pos.z != islandZ) {
- usableCount++;
- }
- }
- }
- endIslands.add(new EndIsland(islandX, islandZ, totalCount, usableCount));
- }
- public static boolean generate(int x, int z, Random rand, Set<BlockPos> endStone) {
- float f = (float) (rand.nextInt(3) + 4);
- for (int i = 0; f > 0.5F; --i) {
- for (int j = (int) Math.floor(-f); j <= Math.ceil(f); ++j) {
- for (int k = (int) Math.floor(-f); k <= Math.ceil(f); ++k) {
- if ((float) (j * j + k * k) <= (f + 1.0F) * (f + 1.0F)) {
- endStone.add(new BlockPos(x + j, i, z + k));
- }
- }
- }
- f = (float) ((double) f - ((double) rand.nextInt(2) + 0.5D));
- }
- return true;
- }
- public static class EndIsland {
- private int x;
- private int z;
- private int totalEndStone;
- private int usableEndStone;
- public EndIsland(int x, int z, int totalEndStone, int usableEndStone) {
- this.x = x;
- this.z = z;
- this.totalEndStone = totalEndStone;
- this.usableEndStone = usableEndStone;
- }
- }
- public static class BlockPos {
- private int x, y, z;
- public BlockPos(int x, int y, int z) {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + x;
- result = prime * result + y;
- result = prime * result + z;
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- BlockPos other = (BlockPos) obj;
- if (x != other.x)
- return false;
- if (y != other.y)
- return false;
- if (z != other.z)
- return false;
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement