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 int max = 0;
- private static List<BlockPos> startPortals = new ArrayList<>();
- public static void main(String[] args) {
- final int MIN_RADIUS = 768 - 16;
- final int MAX_RADIUS = 1024 + 16;
- for (int x = -MAX_RADIUS; x <= MAX_RADIUS; x++) {
- System.out.println(x);
- for (int z = -MAX_RADIUS; z <= MAX_RADIUS; z++) {
- if (x * x + z * z <= MAX_RADIUS * MAX_RADIUS && x * x + z * z >= MIN_RADIUS * MIN_RADIUS) {
- doStuffWithPortal(x, z);
- }
- }
- }
- startPortals.sort(Comparator.<BlockPos>comparingDouble(portal -> {
- double angle = Math.atan2(portal.z, portal.x);
- angle *= 20 / (Math.PI * 2);
- double rounded = Math.round(angle);
- return Math.abs(rounded - angle);
- }));
- System.out.println("Found " + startPortals.size() + " max portals");
- System.out.println("Max size: " + max);
- startPortals.forEach(pos -> System.out.println(pos.x + ", " + pos.z));
- }
- public static void doStuffWithPortal(int portalX, int portalZ) {
- double distance = Math.sqrt(portalX * portalX + portalZ * portalZ);
- double normX = portalX / distance;
- double normZ = portalZ / distance;
- double x = normX * 768;
- double z = normZ * 768;
- doStuffWithExitPortal(portalX, portalZ, (int) Math.round(x), (int) Math.round(z));
- }
- public static void doStuffWithExitPortal(int startX, int startZ, int portalX, int portalZ) {
- //System.out.println(portalX + ", " + portalZ);
- 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 = ((long)portalX & X_MASK) << X_SHIFT | ((long)75 & Y_MASK) << Y_SHIFT | ((long)portalZ & Z_MASK) << 0;
- //System.out.println(seed);
- Set<BlockPos> endStone = new HashSet<>();
- generate(new Random(seed), endStone);
- int count = endStone.size();
- if (count > max) {
- max = count;
- startPortals.clear();
- }
- if (count == max) {
- startPortals.add(new BlockPos(startX, 0, startZ));
- }
- }
- public static boolean generate(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(j, i, k));
- }
- }
- }
- f = (float) ((double) f - ((double) rand.nextInt(2) + 0.5D));
- }
- return true;
- }
- 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