Skip to content

Instantly share code, notes, and snippets.

@EDDxample
Created February 24, 2019 18:13
Show Gist options
  • Save EDDxample/f32f5f22850097051c1ae87d7099209d to your computer and use it in GitHub Desktop.
Save EDDxample/f32f5f22850097051c1ae87d7099209d to your computer and use it in GitHub Desktop.
Simulates Minecraft's random calls to find the regions for Village RNG manipulation
import java.util.Random;
public class RNG_Village_Finder {
static boolean stop;
static int radius = 23437;
static long worldSeed = 544L;
static Random randy = new Random();
public static void main(String[] args) { seedLoop(); }
static void seedLoop() {
int x = 0;
int z = 0;
int di = 1;
int dj = 0;
int segmentLength = 1;
int segmentPassed = 0;
while ((x < radius) && (!stop))
{
findAt(x, z);
x += di;
z += dj;
segmentPassed++;
if (segmentPassed == segmentLength) {
segmentPassed = 0;
int buffer = di;
di = -dj;
dj = buffer;
if (dj == 0) {
segmentLength++;
}
}
}
}
static void findAt(int x, int z) {
// canSpawnStructureAtCoords
setRandomSeed(x, z);
nextIntLoop(60, 4); // 4x nextInt(60)
// playerCheckLight
int totalPlayers = 1;
randy.nextInt(totalPlayers);
nextIntLoop(11, 3); // 3x nextInt(11)
// updateBlocks
int renderDistance = 3;
int rdSide = renderDistance * 2 + 1;
nextIntLoop(rdSide * rdSide); // (2rend+1)^2 x nextInt(16)
// removeDeadAndOutOfRangeDoors
randy.nextInt(50);
// spawnGolems
if (randy.nextInt(7000) == 0)
{
// Golem coords
int golemX = randy.nextInt(16) - 8;
int golemY = randy.nextInt(6) - 3;
int golemZ = randy.nextInt(16) - 8;
// Block coords
int fromX = x * 1280;
int fromZ = z * 1280;
int toX = fromX + 1280;
int toZ = fromZ + 1280;
System.out.println(String.format("from %d %d to %d %d; %d %d %d\n", fromX, fromZ, toX, toZ, golemX, golemY, golemZ));
stop = true;
}
}
static void setRandomSeed(int x, int z) {
int konstant = 10387319;
long i = x * 341873128712L + z * 132897987541L + worldSeed + konstant;
randy.setSeed(i);
}
/* Useful when nextInt(n); n is a power of 2 */
static void nextIntLoop(int times) {
for (int i = 0; i < times; i++) randy.nextInt();
}
static void nextIntLoop(int value, int times) {
for (int i = 0; i < times; i++) randy.nextInt(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment