-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnlyNeededFunctions.h
57 lines (49 loc) · 1.44 KB
/
OnlyNeededFunctions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdint.h>
// from "rng.h"
#define ATTR(...) __attribute__((__VA_ARGS__))
// from "rng.h"
static inline void setSeed(uint64_t *seed, uint64_t value)
{
//*seed = (value ^ 0x5deece66d) & ((1ULL << 48) - 1);
*seed = (value ^ 0x5deece66d) & 0xFFFFFFFFFFFF;
}
// from "rng.h"
//static inline int next(uint64_t *seed, const int bits)
static inline int next(uint64_t *seed)
{
//*seed = (*seed * 0x5deece66d + 0xb) & ((1ULL << 48) - 1);
*seed = (*seed * 0x5deece66d + 0xb) & 0xFFFFFFFFFFFF;
//return (int) ((int64_t)*seed >> (48 - bits));
return (int) ((int64_t)*seed >> 17);
}
// from "rng.h"
//static inline int nextInt(uint64_t *seed, const int n)
static inline int nextInt(uint64_t *seed) // n = 10
{
int bits, val;
//const int m = n - 1; // m = 9
//if ((m & n) == 0) {
// uint64_t x = n * (uint64_t)next(seed, 31);
// return (int) ((int64_t) x >> 31);
//}
do {
bits = next(seed);
val = bits % 10;
}
//while (bits - val + m < 0);
while (bits - val < -9);
return val;
}
// from "finders.h"
static inline ATTR(const)
//int isSlimeChunk(uint64_t seed, int chunkX, int chunkZ)
int isSlimeChunk(int chunkX, int chunkZ)
{
uint64_t rnd = (int)(chunkX * 0x5ac0db);
rnd += (int)(chunkX * chunkX * 0x4c1906);
rnd += (int)(chunkZ * 0x5f24f);
rnd += (int)(chunkZ * chunkZ) * 0x4307a7ULL;
rnd ^= 0x3ad8025fULL;
setSeed(&rnd, rnd);
return nextInt(&rnd) == 0;
}