Skip to content

Instantly share code, notes, and snippets.

@zyuiop
Created December 20, 2015 14:52
Show Gist options
  • Save zyuiop/19b7a4d028fd81684098 to your computer and use it in GitHub Desktop.
Save zyuiop/19b7a4d028fd81684098 to your computer and use it in GitHub Desktop.
import java.util.*;
/**
* @author zyuiop
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Map seed : ");
long seed = scanner.nextLong();
System.out.print("Spawners qty : ");
int q = scanner.nextInt();
PriorityQueue<ChunkSpawners> treeSet = new PriorityQueue<>();
for (int x = -330; x < 330; x++) {
for (int z = -330; z < 330; z++) {
Random random = new Random(seed);
long px = random.nextLong() / 2L * 2L + 1L;
long pz = random.nextLong() / 2L * 2L + 1L;
random.setSeed((long) x * px + (long) z * pz ^ seed);
ChunkSpawners chunkSpawners = new ChunkSpawners(x, z);
if (random.nextInt(4) == 0)
ignoreLakes(random, false);
if (random.nextInt(8) == 0)
ignoreLakes(random, true);
for (int i = 0; i < q; ++i) {
int posX = random.nextInt(16) + 8;
int posY = random.nextInt(256);
int posZ = random.nextInt(16) + 8;
if (posY < 128)
chunkSpawners.add(new Location(posX, posY, posZ));
}
treeSet.add(chunkSpawners);
}
}
Iterator<ChunkSpawners> iterator = treeSet.iterator();
int i = 0;
while (i < 10 && iterator.hasNext()) {
iterator.next().printDatas();
i++;
}
}
private static void ignoreLakes(Random random, boolean check) {
random.nextInt(16);
int y = random.nextInt(256);
random.nextInt(16);
if (check) {
if (y >= 63 && random.nextInt(10) != 0)
return;
}
int lakes = random.nextInt(4) + 4;
for(int i = 0; i < lakes; ++ i){
random.nextDouble();
random.nextDouble();
random.nextDouble();
random.nextDouble();
random.nextDouble();
random.nextDouble();
}
}
public static class ChunkSpawners implements Comparable<ChunkSpawners> {
private final HashSet<Location> locations;
private final int chunkX;
private final int chunkZ;
public ChunkSpawners(int chunkX, int chunkZ) {
this.locations = new HashSet<>();
this.chunkX = chunkX;
this.chunkZ = chunkZ;
}
public void add(Location location) {
locations.add(location);
}
@Override
public int compareTo(ChunkSpawners chunkSpawners) {
return -(locations.size() - chunkSpawners.locations.size());
}
public void printDatas() {
System.out.println(locations.size() + " possible spawners in chunk " + chunkX + " " + chunkZ);
int i = 1;
for (Location location : locations) {
System.out.println(i++ + " : " + location.getRelative() + " | Absolute location : " + location.getAbsolute(chunkX, chunkZ));
}
}
}
public static class Location {
private int relX;
private int relY;
private int relZ;
public Location(int relX, int relY, int relZ) {
this.relX = relX;
this.relY = relY;
this.relZ = relZ;
}
public String getRelative() {
return relX + " " + relY + " " + relZ;
}
public String getAbsolute(int chunkX, int chunkZ) {
return (relX + (16 * chunkX)) + " " + relY + " " + (relZ + (16 * chunkZ));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment