chore: archive early implementations and chunk checker tools
This commit is contained in:
parent
7a06f94577
commit
69f7f7a34b
9 changed files with 1408 additions and 0 deletions
53
tools/sliming.cpp
Normal file
53
tools/sliming.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#pragma GCC optimize("wrapv")
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct JavaRandom {
|
||||
int64_t seed;
|
||||
|
||||
JavaRandom(int64_t seed) : seed((seed ^ 0x5DEECE66DLL) & ((1LL << 48) - 1)) {}
|
||||
|
||||
int32_t next(int bits) {
|
||||
seed = (seed * 0x5DEECE66DLL + 0xBLL) & ((1LL << 48) - 1);
|
||||
return (int32_t)((uint64_t)seed >> (48 - bits));
|
||||
}
|
||||
|
||||
int32_t nextInt(int32_t n) {
|
||||
if ((n & -n) == n) // n is a power of 2
|
||||
return (int32_t)((n * (int64_t)next(31)) >> 31);
|
||||
|
||||
int32_t bits, val;
|
||||
do {
|
||||
bits = next(31);
|
||||
val = bits % n;
|
||||
} while (bits - val + (n - 1) < 0);
|
||||
return val;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
bool isSlimeChunk(int64_t worldSeed, int32_t chunkX, int32_t chunkZ) {
|
||||
int64_t seed = worldSeed +
|
||||
(int64_t)(chunkX * chunkX * 4987142) +
|
||||
(int64_t)(chunkX * 5947611) +
|
||||
(int64_t)(chunkZ * chunkZ) * 4392871LL +
|
||||
(int64_t)(chunkZ * 389711) ^ 987234911LL;
|
||||
JavaRandom rand(seed);
|
||||
return rand.nextInt(10) == 0;
|
||||
}
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 4) {
|
||||
return 1;
|
||||
}
|
||||
int64_t worldSeed = atoll(argv[1]);
|
||||
int32_t chunkX = atoi(argv[2]);
|
||||
int32_t chunkZ = atoi(argv[3]);
|
||||
bool isSlime = isSlimeChunk(worldSeed, chunkX, chunkZ);
|
||||
printf("Is Slime Chunk: %s\n", isSlime ? "true" : "false");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue