forked from upstream/RaycastedAntiESP
Compare commits
1086
Commits
main
...
eventbench
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c667c49f01 | ||
|
|
8d8a327cb0 | ||
|
|
a80b72c008 | ||
|
|
0725062d9c | ||
|
|
0e74a1ba15 | ||
|
|
9a822af8bc | ||
|
|
c6afbf0733 | ||
|
|
4eaa11b193 | ||
|
|
258e47c39f | ||
|
|
c825a4af96 | ||
|
|
244fde97c0 | ||
|
|
8b3a62f1f5 | ||
|
|
45d0e0581c | ||
|
|
aa7934f258 | ||
|
|
cfdb255b56 | ||
|
|
14e6aaaae6 | ||
|
|
d7cc7abd8c | ||
|
|
73e58e191e | ||
|
|
e5a591af1a | ||
|
|
9951b5d7a1 | ||
|
|
e99c3b9de2 | ||
|
|
0500f4bd5f | ||
|
|
9a841308ff | ||
|
|
c4bf1cbf0b | ||
|
|
db22c675db | ||
|
|
5a42fd74ad | ||
|
|
85b788742c | ||
|
|
20f660b8a3 | ||
|
|
4d17483a5a | ||
|
|
274b081c78 | ||
|
|
45e14637e0 | ||
|
|
b007735636 | ||
|
|
bb7275a618 | ||
|
|
853fa1531a | ||
|
|
396382bcc2 | ||
|
|
aae6bdb53c | ||
|
|
2f8f698069 | ||
|
|
fc3badb90a | ||
|
|
7aab3b60e8 | ||
|
|
2ab157bd4a | ||
|
|
3227c63e2e | ||
|
|
1dc77b3e6f | ||
|
|
cb044f789d | ||
|
|
c110aab634 | ||
|
|
5d407afbdf | ||
|
|
a8f12c9a24 | ||
|
|
0e4c251c6c | ||
|
|
e2b598a361 | ||
|
|
8c140cf8b6 | ||
|
|
4fe9ab02ef | ||
|
|
a21102d04f | ||
|
|
22488e9e71 | ||
|
|
bc40438cb3 | ||
|
|
3f633710e7 | ||
|
|
8de5d53198 | ||
|
|
53650f9b63 | ||
|
|
ba812bce3a | ||
|
|
42932abaa5 | ||
|
|
290749dde8 | ||
|
|
e19808fb4b | ||
|
|
691d429652 | ||
|
|
1575091d12 | ||
|
|
4919383c73 | ||
|
|
5293db6c86 | ||
|
|
c5f17a7b12 | ||
|
|
ddafbd0c25 | ||
|
|
8d9a354154 | ||
|
|
64bfcccde5 | ||
|
|
e91dc4647d | ||
|
|
96601efed5 | ||
|
|
c63a194ea9 | ||
|
|
71cde26cb9 | ||
|
|
33ab1cd234 | ||
|
|
e1c96d87ff | ||
|
|
3d8686e1ae | ||
|
|
971a648ad8 | ||
|
|
b0f05eaf4f | ||
|
|
bc9fcd6d7a | ||
|
|
a631c57465 | ||
|
|
9f9fb7f021 | ||
|
|
903e7c84bc | ||
|
|
ae75c37d90 | ||
|
|
17f5040c49 | ||
|
|
c04cf7558e | ||
|
|
11358badac | ||
|
|
008e62eee2 | ||
|
|
409261000e | ||
|
|
4854b1f88b | ||
|
|
e384ea0775 | ||
|
|
61df3f4f2d | ||
|
|
9f3eec6f09 | ||
|
|
4361276070 | ||
|
|
5d852cd6d3 | ||
|
|
2b2c7b9108 | ||
|
|
93949b7906 | ||
|
|
cee4d4b6f9 | ||
|
|
9fed35527d | ||
|
|
d101ba9b99 | ||
|
|
4527a9dd02 | ||
|
|
8aefd39d65 | ||
|
|
ccbed56a99 | ||
|
|
5e4692c753 | ||
|
|
5d05ac00b7 | ||
|
|
7d611ffdcb | ||
|
|
f3ff087874 | ||
|
|
a11711e06f | ||
|
|
30286928b2 | ||
|
|
5fdf26f624 | ||
|
|
f72da61436 | ||
|
|
980cc33e7b | ||
|
|
d873c7b1ff | ||
|
|
f67b0b2ae7 | ||
|
|
c047ed08e1 | ||
|
|
e886efa823 | ||
|
|
740974f17c | ||
|
|
f38bda6993 | ||
|
|
61e7cac35f | ||
|
|
8f61e203f8 | ||
|
|
751398eaaa | ||
|
|
736ccab3e0 | ||
|
|
32a8d92df4 | ||
|
|
af0d887e14 | ||
|
|
f32c8ec9fa | ||
|
|
858c4d4340 | ||
|
|
274d437525 | ||
|
|
c610bc42a6 | ||
|
|
ae8905ed46 | ||
|
|
dcaed38f4d | ||
|
|
512a4db255 | ||
|
|
4fd8954fea | ||
|
|
1b5db5edca | ||
|
|
a08a477176 | ||
|
|
f4f3ca4d63 | ||
|
|
ab537e777b | ||
|
|
02938e3b57 | ||
|
|
e4b488eb69 | ||
|
|
e55b685ce2 | ||
|
|
6fd6d9bc04 | ||
|
|
d1244be5d1 | ||
|
|
dd9db4211d | ||
|
|
162bd3cf20 | ||
|
|
f78c3d1243 | ||
|
|
3feff5eb8a | ||
|
|
a47dcb94a8 | ||
|
|
65b6dbc44a | ||
|
|
a87a403e2d | ||
|
|
ddfb1748f7 | ||
|
|
c4669494b4 | ||
|
|
d340702530 | ||
|
|
fd8aa8a82a | ||
|
|
39f17f92a5 | ||
|
|
f47ef79707 | ||
|
|
f8a3f09c07 | ||
|
|
18c8dd11f5 | ||
|
|
7fccdb6e53 | ||
|
|
769c13db81 | ||
|
|
65bdc8fa7d | ||
|
|
f94c2053eb | ||
|
|
7cb16521a2 | ||
|
|
4dff4245f0 | ||
|
|
5472af1191 | ||
|
|
a7d2c953bc | ||
|
|
f565ea0fe1 | ||
|
|
b4430b70df | ||
|
|
28b3cff770 | ||
|
|
1d4f452098 | ||
|
|
2e7d35bc1a | ||
|
|
1be44580c0 | ||
|
|
a0aba0d37b | ||
|
|
1cc87b5b9e | ||
|
|
dfcfe3576f | ||
|
|
1d15c21200 | ||
|
|
c56aab576b | ||
|
|
c73b9abb6e | ||
|
|
9e9d880691 | ||
|
|
2773b98ef1 | ||
|
|
5f7a247224 | ||
|
|
ae852ae4c7 | ||
|
|
0325ee118e | ||
|
|
55ba8e5b9e | ||
|
|
c7705d8217 | ||
|
|
94ea345614 | ||
|
|
5ebfb36f4b | ||
|
|
4770f22770 | ||
|
|
6451771f1d | ||
|
|
038768adda | ||
|
|
e5338bbc34 | ||
|
|
cfbb6a54aa | ||
|
|
89a2a1cf32 | ||
|
|
955e24da66 | ||
|
|
152dcbc4db | ||
|
|
04d85e843a | ||
|
|
fb28453f4f | ||
|
|
53a60be932 | ||
|
|
284233e1b2 | ||
|
|
6e2a110380 | ||
|
|
dddbaee001 | ||
|
|
958756df2d | ||
|
|
371c9c8155 | ||
|
|
3f212e8766 | ||
|
|
4f086b4d6a | ||
|
|
b97d938425 | ||
|
|
f93723a0a4 | ||
|
|
93e0b54ff4 | ||
|
|
e77d450053 | ||
|
|
50acc8e66c | ||
|
|
fea6800269 | ||
|
|
9e742e62b5 | ||
|
|
0ab820fcd9 | ||
|
|
b07de426a4 | ||
|
|
316c2ec10f | ||
|
|
a7465f9d59 | ||
|
|
332f0becb4 | ||
|
|
3cc6b43999 | ||
|
|
d8daf0dd7a | ||
|
|
b189e576c0 | ||
|
|
165f30e339 | ||
|
|
5d00ae3a02 | ||
|
|
d04a0903bd | ||
|
|
50d1d359c4 | ||
|
|
3e33722426 | ||
|
|
84eb5fc888 | ||
|
|
2923125933 | ||
|
|
812ef94284 | ||
|
|
e47f788086 | ||
|
|
254c86919b | ||
|
|
d42ab704d6 | ||
|
|
f226b53bb0 | ||
|
|
400a5b96eb | ||
|
|
e1d737c67b | ||
|
|
6c5fcc35e8 | ||
|
|
a2094ebac5 | ||
|
|
3250ea4b33 | ||
|
|
df6537b12d | ||
|
|
7a5794efee | ||
|
|
89c07d5b53 | ||
|
|
15132e4825 | ||
|
|
db48f8fe08 | ||
|
|
6dfb7c3715 | ||
|
|
9fc793b761 | ||
|
|
160597a5a0 | ||
|
|
75957b9081 | ||
|
|
da344c7962 | ||
|
|
ba08b02975 | ||
|
|
328de7f129 | ||
|
|
c814e1e0b6 | ||
|
|
50b259ed5b | ||
|
|
f7d21a716d | ||
|
|
ce8ce72151 | ||
|
|
02253fd487 | ||
|
|
b5540006e3 | ||
|
|
344f259f95 | ||
|
|
331310ddd1 | ||
|
|
d35adc6f5f | ||
|
|
8afb1d10e9 | ||
|
|
e963a69f64 | ||
|
|
d66bf182b9 | ||
|
|
ea36d636e9 | ||
|
|
d3a2b43ba3 | ||
|
|
26ce1ff826 | ||
|
|
563f19e4a3 | ||
|
|
bdf22111ad | ||
|
|
b4e65f9653 | ||
|
|
de3ddd88da | ||
|
|
d5a55ef393 | ||
|
|
7dd2d204ce | ||
|
|
b3a418482b | ||
|
|
77c391996e | ||
|
|
5d3fbb92a0 | ||
|
|
30e26de415 | ||
|
|
ff7e71087b | ||
|
|
9221ea87fa | ||
|
|
e72440051c | ||
|
|
7edf021f33 | ||
|
|
e785d2c7d3 | ||
|
|
6b3177175f | ||
|
|
d90f3e4389 | ||
|
|
f733ee6ff6 | ||
|
|
868b41ea02 | ||
|
|
3076fccbea | ||
|
|
f637ac5607 | ||
|
|
da8db38d51 | ||
|
|
cf92d3817b | ||
|
|
dac5d8597d | ||
|
|
e0029df844 | ||
|
|
07865ea73b | ||
|
|
0622ad6f83 | ||
|
|
33863642de | ||
|
|
0c22c40d3e | ||
|
|
4e9d88dc08 | ||
|
|
a2a96a3353 | ||
|
|
e4c8ac11dc | ||
|
|
fda6d08e9a | ||
|
|
db7032b5b2 | ||
|
|
a46746d5cf | ||
|
|
35a42a49a9 | ||
|
|
cf953eb3c8 | ||
|
|
92f4b9ac45 | ||
|
|
b0f0e1a8f5 | ||
|
|
ca9da23ceb | ||
|
|
25295627cc | ||
|
|
090b96ac81 | ||
|
|
63efc23203 | ||
|
|
e57238897a | ||
|
|
a870d24c31 | ||
|
|
c895787ce2 | ||
|
|
91ab493a77 | ||
|
|
b6ac0d54be | ||
|
|
63c7b398c1 | ||
|
|
acf9c27c86 | ||
|
|
422a189069 | ||
|
|
80ac9d287f | ||
|
|
d2dff3de3c | ||
|
|
30dc0f420e | ||
|
|
bae7feea94 | ||
|
|
c5c5d12002 | ||
|
|
75d50eecbc | ||
|
|
c9e8b9b1c0 | ||
|
|
59e42d75f6 | ||
|
|
aa0d909505 | ||
|
|
7339d64322 | ||
|
|
6a4c344143 | ||
|
|
eba11b6717 | ||
|
|
05e7a4295a | ||
|
|
1d2c7d2afb | ||
|
|
60913b3c13 | ||
|
|
d3da22dfa9 | ||
|
|
7f836b85bf | ||
|
|
d8fc2bfc93 | ||
|
|
ccb4672da6 | ||
|
|
0bdd1fe61c | ||
|
|
da07fa063b | ||
|
|
1f3ac0e2a5 | ||
|
|
c498cfa634 | ||
|
|
3c28104ba4 | ||
|
|
cdca05ca32 | ||
|
|
fb83bbbf4a | ||
|
|
9f860c1a40 | ||
|
|
dcca2d4733 | ||
|
|
e53c51002b | ||
|
|
c58b19d411 | ||
|
|
f243c305b1 | ||
|
|
a9d6679c45 | ||
|
|
ede8662f79 | ||
|
|
7f9d543339 | ||
|
|
868776bd04 | ||
|
|
c47535cdb1 | ||
|
|
5ba314045e | ||
|
|
1e45335bad | ||
|
|
d6356faf6a | ||
|
|
81d05427e5 | ||
|
|
311b69433f | ||
|
|
fc819abb2c | ||
|
|
e35f32705b | ||
|
|
f15a571c1d | ||
|
|
b5179739dc | ||
|
|
1e7a7cf02a | ||
|
|
4a63e0420d | ||
|
|
fea9794a01 | ||
|
|
3b53334f1a | ||
|
|
4e9b43d2d3 | ||
|
|
2ba7a24f19 | ||
|
|
7861298502 | ||
|
|
e6ba88d981 | ||
|
|
081ccb9408 | ||
|
|
63fab1d5ee | ||
|
|
bb628a7b41 | ||
|
|
43980c1364 | ||
|
|
321f8d4c3a | ||
|
|
d19987d337 | ||
|
|
65a4b7c94e | ||
|
|
8e0420b31f | ||
|
|
f686e81430 | ||
|
|
0ba40c8dbb | ||
|
|
6bce78a254 | ||
|
|
7ea2602282 | ||
|
|
bc37329ff7 | ||
|
|
8b57d5ce34 | ||
|
|
33cd4b0455 | ||
|
|
bf733b4c5b | ||
|
|
d3a088a30c | ||
|
|
0166031975 | ||
|
|
3b712d6918 | ||
|
|
d44f3d0fdf | ||
|
|
0e4dfc08b7 | ||
|
|
dbe72d3c5e | ||
|
|
4e1c77fe7b | ||
|
|
9c7bfdfa57 | ||
|
|
1e73d78724 | ||
|
|
a284eb98f5 | ||
|
|
2dafdb53af | ||
|
|
acb71072ac | ||
|
|
fdde9d957f | ||
|
|
3abc73e9f7 | ||
|
|
130166d787 | ||
|
|
c2e9d81942 | ||
|
|
b80a9c0f3c | ||
|
|
b493b1af2e | ||
|
|
807bfa02f3 | ||
|
|
d134343bc9 | ||
|
|
8c5aaea5f5 | ||
|
|
93fd8b4d3e | ||
|
|
61e550894f | ||
|
|
417ebae0ec | ||
|
|
4cf4453996 | ||
|
|
545a0eae2a | ||
|
|
c56edb67ac | ||
|
|
cbe6bf2635 | ||
|
|
8b84d6e43a | ||
|
|
ad3d06f1aa | ||
|
|
4a8fb2ca53 | ||
|
|
912523aba9 | ||
|
|
71cf2f4657 | ||
|
|
bbdd4982a0 | ||
|
|
785729c443 | ||
|
|
eb2ec969a9 | ||
|
|
fed0379899 | ||
|
|
1ea51136ce | ||
|
|
2fb8b0e92a | ||
|
|
c3ebfbbcd0 | ||
|
|
934825daef | ||
|
|
627c3c3f10 | ||
|
|
36c349d7e9 | ||
|
|
593211fad2 | ||
|
|
e0037b5da9 | ||
|
|
4a71852fd4 | ||
|
|
0eb47f5a93 | ||
|
|
275fc53f9a | ||
|
|
e157f50f86 | ||
|
|
27ca927d55 | ||
|
|
a3e2f3d052 | ||
|
|
0c16268142 | ||
|
|
41bafad04c | ||
|
|
9f7a06cc89 | ||
|
|
94ee2ef6fd | ||
|
|
a2c09831cf | ||
|
|
8c61813bbf | ||
|
|
49acaaf4fa | ||
|
|
e6cca8d1b4 | ||
|
|
778ed7bb0e | ||
|
|
5e6e249fd4 | ||
|
|
6685d60fc4 | ||
|
|
7f9f6606bc | ||
|
|
e31349db26 | ||
|
|
58bab35223 | ||
|
|
4afe454de9 | ||
|
|
e75c3731b1 | ||
|
|
2556f5b369 | ||
|
|
0243cef884 | ||
|
|
f8fbbd8a74 | ||
|
|
f22133efe8 | ||
|
|
08db0d384f | ||
|
|
0ac8dc372f | ||
|
|
c5a5009fe9 | ||
|
|
aae0060cd4 | ||
|
|
56ff445cb6 | ||
|
|
be880e80c7 | ||
|
|
d80555c016 | ||
|
|
2e33bf9415 | ||
|
|
0f87b90787 | ||
|
|
0a9f115e92 | ||
|
|
ebfa47efbc | ||
|
|
5be167fdb3 | ||
|
|
0799b911a9 | ||
|
|
97d2bc7bdd | ||
|
|
0bd6b4203f | ||
|
|
f4a61f43ff | ||
|
|
9372928ae9 | ||
|
|
68ed857f25 | ||
|
|
30569c711f | ||
|
|
5005b3eb7b | ||
|
|
dd00bdd1fa | ||
|
|
0e1c2815ae | ||
|
|
489db71b2b | ||
|
|
2a821c0ebf | ||
|
|
7115fe6e34 | ||
|
|
323c83c93e | ||
|
|
aa0dc3297a | ||
|
|
cb4c55fdbd | ||
|
|
a6c79d4bbe | ||
|
|
3f8ac5cc5d | ||
|
|
3bd4c5339c | ||
|
|
9f3bb3793a | ||
|
|
baf560546f | ||
|
|
9f27907a83 | ||
|
|
f4eba53f7f | ||
|
|
f60934a023 | ||
|
|
e524d072b2 | ||
|
|
4e1ca5401c | ||
|
|
4381459a69 | ||
|
|
1e7be8637c | ||
|
|
5ee2a18173 | ||
|
|
c98c1c474f | ||
|
|
d3ddb28ec3 | ||
|
|
1a2469cbc4 | ||
|
|
1fc5000782 | ||
|
|
9121c0f4f6 | ||
|
|
5833213c20 | ||
|
|
1d3d3f5b55 | ||
|
|
dcb5af8721 | ||
|
|
ac3745d1e4 | ||
|
|
76d11242f6 | ||
|
|
108ba8a5b4 | ||
|
|
5228e06033 | ||
|
|
7884b02d8a | ||
|
|
fb861860bb | ||
|
|
d7036dd9d6 | ||
|
|
777e31cf59 | ||
|
|
7645335bb6 | ||
|
|
297278b998 | ||
|
|
b3455dfb92 | ||
|
|
2eecde1ee3 | ||
|
|
688f39463b | ||
|
|
fc23764bce | ||
|
|
5a57e44869 | ||
|
|
4318f8b23e | ||
|
|
8b370d0fe2 | ||
|
|
4a8527909a | ||
|
|
eca024118f | ||
|
|
3f814cd6d6 | ||
|
|
2cbe04c6cc | ||
|
|
2151f88f95 | ||
|
|
af387145fa | ||
|
|
8f760b7769 | ||
|
|
b4d35ab9f5 | ||
|
|
1c510322a9 | ||
|
|
dd1dd32391 | ||
|
|
f1342514e0 | ||
|
|
331bd2a4c0 | ||
|
|
a9de49a9a9 | ||
|
|
e2c61cb926 | ||
|
|
036ff55317 | ||
|
|
19c58d5a71 | ||
|
|
6c3d75643a | ||
|
|
587f45f86b | ||
|
|
5eb815010d | ||
|
|
70a0c1d1de | ||
|
|
c59d650a94 | ||
|
|
bcdbdf3c94 | ||
|
|
99eb62a72e | ||
|
|
e17d0b616a | ||
|
|
7c44cc1614 | ||
|
|
d75c5604e0 | ||
|
|
902d0dcf20 | ||
|
|
dbe04d1861 | ||
|
|
a0ffab833e | ||
|
|
e95fb3a97b | ||
|
|
d033cba970 | ||
|
|
c810152fa8 | ||
|
|
28929c0e20 | ||
|
|
8046bbad91 | ||
|
|
59fef9cd5d | ||
|
|
98b31ee4cf | ||
|
|
be5b1b59f6 | ||
|
|
49d8c7cbf7 | ||
|
|
a51ff8beaa | ||
|
|
c3183ef3d4 | ||
|
|
b5e78cc0ff | ||
|
|
3c7fabb52e | ||
|
|
004fc8bec9 | ||
|
|
45c6306482 | ||
|
|
b37624b38f | ||
|
|
5aaa9bd6c9 | ||
|
|
89a2629b77 | ||
|
|
83759a1c61 | ||
|
|
79cf23d04f | ||
|
|
513dfc2b96 | ||
|
|
1632258ae8 | ||
|
|
98b910fd2e | ||
|
|
4c97544ac7 | ||
|
|
d01b080207 | ||
|
|
f167004657 | ||
|
|
260278c380 | ||
|
|
fe864dfb42 | ||
|
|
ee84361f7f | ||
|
|
054b092b10 | ||
|
|
3dfcb5e8a4 | ||
|
|
53ffc67492 | ||
|
|
38d9f794e8 | ||
|
|
19c1db1fec | ||
|
|
38eeba1875 | ||
|
|
d3561e28ca | ||
|
|
702ef77248 | ||
|
|
e347904aa1 | ||
|
|
03d0844907 | ||
|
|
ca41d935aa | ||
|
|
a7764ada31 | ||
|
|
53c3c5cb4c | ||
|
|
a065180096 | ||
|
|
2389ac0f8a | ||
|
|
b12037bbe9 | ||
|
|
6b8abe25cf | ||
|
|
a791eabacb | ||
|
|
ceb0d48554 | ||
|
|
9e7c62dc02 | ||
|
|
4c21c16e3b | ||
|
|
2db473077f | ||
|
|
078cfa8266 | ||
|
|
e7ee8991b9 | ||
|
|
77a7394d22 | ||
|
|
c34bfdb61f | ||
|
|
43e11210cf | ||
|
|
cb39e82485 | ||
|
|
d3756978dc | ||
|
|
fcaffbabcc | ||
|
|
c6e4af9cdb | ||
|
|
335958939b | ||
|
|
12c3894d04 | ||
|
|
50fdebf44b | ||
|
|
f941b6cc7b | ||
|
|
c30aced6be | ||
|
|
7eb515d8c2 | ||
|
|
36ddc2ab4b | ||
|
|
5e13f99fbf | ||
|
|
af1e35cf80 | ||
|
|
1ac28cca35 | ||
|
|
562f203d09 | ||
|
|
a1c0a6d860 | ||
|
|
2e816d92b8 | ||
|
|
3fedbc2a17 | ||
|
|
abd2dab77c | ||
|
|
a7eacf704d | ||
|
|
a55022d4fd | ||
|
|
8b6b0332eb | ||
|
|
79f018cd13 | ||
|
|
5815d327cf | ||
|
|
b76b0c900b | ||
|
|
9c6ab79f1c | ||
|
|
01f37f6e1d | ||
|
|
958c6468b4 | ||
|
|
3977e21568 | ||
|
|
92dfbe9599 | ||
|
|
74f823b1a7 | ||
|
|
7d07e67d5b | ||
|
|
7ddf475e90 | ||
|
|
20bd20b60a | ||
|
|
e858c4e6eb | ||
|
|
5127ebd260 | ||
|
|
f88b482a65 | ||
|
|
a325dcc05f | ||
|
|
186dd11aeb | ||
|
|
4131f0c61b | ||
|
|
5d94735581 | ||
|
|
7d6a4860f6 | ||
|
|
31b6ec3426 | ||
|
|
97703c90d0 | ||
|
|
d9109fcbcd | ||
|
|
ba93e28d09 | ||
|
|
55de301117 | ||
|
|
2da16f39a5 | ||
|
|
ff81ae5d1a | ||
|
|
18472570f4 | ||
|
|
07d563c343 | ||
|
|
6b89ab91e1 | ||
|
|
8b6c2a895f | ||
|
|
eb49446618 | ||
|
|
6d3e768689 | ||
|
|
d828461ce5 | ||
|
|
bf51d0cfb6 | ||
|
|
73cec9faf5 | ||
|
|
af7c1253e2 | ||
|
|
d84b4c4bd8 | ||
|
|
b8998ca936 | ||
|
|
2363190bbf | ||
|
|
7068eec49e | ||
|
|
516f4425a7 | ||
|
|
5c541178a4 | ||
|
|
acab9879e1 | ||
|
|
d1c7efa586 | ||
|
|
21dceabb2f | ||
|
|
ea8e11710c | ||
|
|
72b838921f | ||
|
|
55d770496a | ||
|
|
bfbe635032 | ||
|
|
d560cbbd56 | ||
|
|
a0a3834c13 | ||
|
|
566cd93e8d | ||
|
|
78fcec3f11 | ||
|
|
fbdbcd39e3 | ||
|
|
2f0555c030 | ||
|
|
758263345f | ||
|
|
56ec5ffcb7 | ||
|
|
7e58806271 | ||
|
|
9791348634 | ||
|
|
09a95cc735 | ||
|
|
529b7977d4 | ||
|
|
6f4a6d4b2e | ||
|
|
f57829e7fc | ||
|
|
cf69030c56 | ||
|
|
828f302d5c | ||
|
|
927066adb9 | ||
|
|
7c2fc00a87 | ||
|
|
29890541af | ||
|
|
0ebd1903b1 | ||
|
|
f0cb5d0281 | ||
|
|
300ae927d7 | ||
|
|
54dc47c89f | ||
|
|
60f8ea55b0 | ||
|
|
47e7a08547 | ||
|
|
e2089aace3 | ||
|
|
cef2a0e7ee | ||
|
|
609fa9f9f4 | ||
|
|
383bfe0abe | ||
|
|
bd2c0f0c62 | ||
|
|
08dff2867f | ||
|
|
84114b3325 | ||
|
|
30f78ab351 | ||
|
|
0d8eec08ae | ||
|
|
79d67832ac | ||
|
|
8429c33791 | ||
|
|
ddc5052741 | ||
|
|
9aff6869d1 | ||
|
|
09f92498fc | ||
|
|
47182ad24a | ||
|
|
e1a7a9b278 | ||
|
|
5390965693 | ||
|
|
75e7a3ddff | ||
|
|
17c0db3980 | ||
|
|
13e6ece4ae | ||
|
|
dfe1ff6f9c | ||
|
|
c84993571a | ||
|
|
a2efea0060 | ||
|
|
15d30ce397 | ||
|
|
5baeb75619 | ||
|
|
11ef7e6388 | ||
|
|
6c1b3fdc7c | ||
|
|
1a25c49271 | ||
|
|
001e8b3688 | ||
|
|
22c1321873 | ||
|
|
167b4be8b8 | ||
|
|
0a5c130cd1 | ||
|
|
eb64d03d05 | ||
|
|
95d14e97b3 | ||
|
|
c1e71c52aa | ||
|
|
18e1857d83 | ||
|
|
6a1214e126 | ||
|
|
6b1f9cf24f | ||
|
|
96dec1d654 | ||
|
|
b6507cb052 | ||
|
|
5f27b1da1f | ||
|
|
433a09b7c6 | ||
|
|
a57dba3ff4 | ||
|
|
5f34f0cc6f | ||
|
|
c09a69381f | ||
|
|
44f9bf4196 | ||
|
|
973e500c9f | ||
|
|
f436f31dea | ||
|
|
a6b9d34bab | ||
|
|
b5ef1d7ac4 | ||
|
|
516197aa36 | ||
|
|
08212cdb78 | ||
|
|
4658e99bd9 | ||
|
|
f74d6c90e8 | ||
|
|
26e830bdd0 | ||
|
|
0fb6d31cde | ||
|
|
07b2c50edc | ||
|
|
be9796c712 | ||
|
|
433f873f82 | ||
|
|
914909039e | ||
|
|
92c5a9f4d1 | ||
|
|
bfaa8605f0 | ||
|
|
55f68eed8c | ||
|
|
2634b1a59e | ||
|
|
dd4d0476dd | ||
|
|
b6bb3abd28 | ||
|
|
a70ecf0b9d | ||
|
|
40b7d9e58d | ||
|
|
05e2caaf43 | ||
|
|
4030db77c7 | ||
|
|
d2913e2c64 | ||
|
|
9f5fa5cd3a | ||
|
|
2f92860f76 | ||
|
|
4d06bac9a3 | ||
|
|
7b63d6b352 | ||
|
|
1fe44a8e45 | ||
|
|
bb3f06a070 | ||
|
|
c9ee55f864 | ||
|
|
5654216ac3 | ||
|
|
351397852c | ||
|
|
6532fb619c | ||
|
|
ae63a4c56f | ||
|
|
ae4ff7c593 | ||
|
|
e016d4339f | ||
|
|
d1071427d1 | ||
|
|
c4d56582d8 | ||
|
|
266e04aa0c | ||
|
|
cf0240b940 | ||
|
|
1eee0946a3 | ||
|
|
f49f58749b | ||
|
|
8e06c4a3d8 | ||
|
|
1f5e428023 | ||
|
|
96a92e95e9 | ||
|
|
5e80239c14 | ||
|
|
8943800c59 | ||
|
|
858b08d558 | ||
|
|
625218513f | ||
|
|
e9cd8a031e | ||
|
|
4d161ca0a2 | ||
|
|
6a92d4de18 | ||
|
|
b8ecbf3636 | ||
|
|
e53fad05e3 | ||
|
|
8138e326b6 | ||
|
|
a31ba406c6 | ||
|
|
2237edc1fd | ||
|
|
f8ec2b7000 | ||
|
|
00ee95a537 | ||
|
|
0e31708380 | ||
|
|
5a3b083928 | ||
|
|
a9cc1ab604 | ||
|
|
4d20087dfa | ||
|
|
b8236c2e6d | ||
|
|
d3d67de973 | ||
|
|
96ee9c6931 | ||
|
|
b184eda584 | ||
|
|
d15420d46a | ||
|
|
b62a008063 | ||
|
|
3e00bbf61b | ||
|
|
359feffdcf | ||
|
|
06978953b1 | ||
|
|
e1fc76df77 | ||
|
|
4153cf4aac | ||
|
|
2d7303eb33 | ||
|
|
b0d8e32202 | ||
|
|
5649f4ad7c | ||
|
|
9e5ad8c0a3 | ||
|
|
57848b81f8 | ||
|
|
2dc2dbb5f7 | ||
|
|
34690d2408 | ||
|
|
90f5ddbe8a | ||
|
|
98edc8968b | ||
|
|
e632a5b98d | ||
|
|
5d8c786ba4 | ||
|
|
bd1edf8332 | ||
|
|
7a003368ff | ||
|
|
542d681bb4 | ||
|
|
500aa72106 | ||
|
|
e9a22ff518 | ||
|
|
fca7cc9d2d | ||
|
|
4486e60ff2 | ||
|
|
f322ab668a | ||
|
|
59059248df | ||
|
|
b499b62745 | ||
|
|
2d7dc391ae | ||
|
|
d81a7bde44 | ||
|
|
149bae4ac2 | ||
|
|
d61be5ba8d | ||
|
|
c06fe81df3 | ||
|
|
9c7dd360a5 | ||
|
|
c58417f15b | ||
|
|
7b6c663510 | ||
|
|
1a97a70d9b | ||
|
|
ee473162bf | ||
|
|
41b41cace6 | ||
|
|
01cd0d04da | ||
|
|
7b6aa88e0f | ||
|
|
dbef12eb7b | ||
|
|
15f5d77bae | ||
|
|
f45c85a838 | ||
|
|
8cdad10f14 | ||
|
|
ae98d76ded | ||
|
|
3f1e3a170d | ||
|
|
3c053dbacc | ||
|
|
1e0f08083e | ||
|
|
ae66f039f7 | ||
|
|
5224317545 | ||
|
|
6a3a8b5768 | ||
|
|
4eeb2b5d06 | ||
|
|
0995d546da | ||
|
|
a01ff503f4 | ||
|
|
066c6a32ea | ||
|
|
5d2b6c9f4a | ||
|
|
7a8a7364df | ||
|
|
0072c9ff8e | ||
|
|
d78f562762 | ||
|
|
c6e845527e | ||
|
|
68cb54c0ed | ||
|
|
7c45f6ec4e | ||
|
|
53f0615805 | ||
|
|
dd9d807d92 | ||
|
|
902ed25a5b | ||
|
|
7a90d92c0a | ||
|
|
7ca097b35c | ||
|
|
d0a6c8475e | ||
|
|
b1fa7e7c96 | ||
|
|
70bbb06ee9 | ||
|
|
8193baf9df | ||
|
|
d6e62f11ee | ||
|
|
992dad2775 | ||
|
|
814cf86541 | ||
|
|
f3e4c1cb47 | ||
|
|
0bf28b6951 | ||
|
|
e71e9006fd | ||
|
|
06b3395d03 | ||
|
|
222987baae | ||
|
|
a495d3946d | ||
|
|
7a514d6236 | ||
|
|
26a4d4c10c | ||
|
|
cbb48372ac | ||
|
|
ff31d9085a | ||
|
|
1d93653422 | ||
|
|
db13824a0f | ||
|
|
dba313847c | ||
|
|
c319a6ffd4 | ||
|
|
486e5dcb36 | ||
|
|
20842449af | ||
|
|
027f62727a | ||
|
|
3ae7ca0d2e | ||
|
|
3fa02c2561 | ||
|
|
32a0b94f61 | ||
|
|
e28b7b6f23 | ||
|
|
2fc7e50145 | ||
|
|
c56ee078c9 | ||
|
|
4400151878 | ||
|
|
50d0e54687 | ||
|
|
2f15ca9d5b | ||
|
|
f6535848c0 | ||
|
|
4b96935f34 | ||
|
|
40b99d5c43 | ||
|
|
e448e18472 | ||
|
|
d806ae3c0b | ||
|
|
34fe60a7ae | ||
|
|
0ff67e11a7 | ||
|
|
98eaf72cae | ||
|
|
e5c7f6ef90 | ||
|
|
da73bb26ec | ||
|
|
bd57a9b72c | ||
|
|
116f5e8e03 | ||
|
|
bcfdd731e2 | ||
|
|
e83ec5e6a2 | ||
|
|
2b48e7e8d2 | ||
|
|
38c39aecc5 | ||
|
|
70ec4c212f | ||
|
|
d5026d28d4 | ||
|
|
df5e9f6ca8 | ||
|
|
7f1a284eae | ||
|
|
87aba0e2b5 | ||
|
|
d46d63668b | ||
|
|
83a278b00a | ||
|
|
c1e0db5613 | ||
|
|
34db141f08 | ||
|
|
61831a813a | ||
|
|
a68bcfdbf5 | ||
|
|
9ca8b4ee3a | ||
|
|
77825067de | ||
|
|
635f407c3a | ||
|
|
c18b30da36 | ||
|
|
b524cfdf10 | ||
|
|
968c803106 | ||
|
|
77c5a18433 | ||
|
|
085fa59e42 | ||
|
|
2db88a4498 | ||
|
|
081e762c5c | ||
|
|
1733fd1884 | ||
|
|
773378e6cb | ||
|
|
ac67aa8786 | ||
|
|
40bbaeb5ff | ||
|
|
76f5816162 | ||
|
|
1201ff1370 | ||
|
|
e9935f0350 | ||
|
|
11f1c6ecb7 | ||
|
|
0a6302674d | ||
|
|
4283dfd87b | ||
|
|
9d01af18f3 | ||
|
|
77dd9bb31a | ||
|
|
47f862323b | ||
|
|
c356ed0172 | ||
|
|
8d39fa5427 | ||
|
|
7e0725c538 | ||
|
|
b958d0dc46 | ||
|
|
e9adb65690 | ||
|
|
6a289c81a9 | ||
|
|
34b04ff059 | ||
|
|
1a73c2509a | ||
|
|
e3731f76f0 | ||
|
|
bd1f6ad482 | ||
|
|
951e4f4ad9 | ||
|
|
114746aeaf | ||
|
|
9dc9652917 | ||
|
|
b97f675159 | ||
|
|
f5e16fc75d | ||
|
|
6dc3f2f84e | ||
|
|
8e76557a88 | ||
|
|
f76e2bbcf7 | ||
|
|
c228cef24a | ||
|
|
098aab5e31 | ||
|
|
31b500bc7b | ||
|
|
d5e3281cf2 | ||
|
|
98dbefd576 | ||
|
|
4dce9b3278 | ||
|
|
d5bf02b4ea | ||
|
|
ed98e2abeb | ||
|
|
9a07bd0119 | ||
|
|
87cd59b346 | ||
|
|
74aca26910 | ||
|
|
25f5652a12 | ||
|
|
7679f08d06 | ||
|
|
7ad99917d1 | ||
|
|
ce56eb316e | ||
|
|
74426d80af | ||
|
|
fdb1f567ac | ||
|
|
e823f7a2f7 | ||
|
|
7c1f7fd2a6 | ||
|
|
c26e6a1623 | ||
|
|
8155903342 | ||
|
|
f2ade6b0b8 | ||
|
|
f486d1fc2e | ||
|
|
50eeab8cfe | ||
|
|
4009fe6d02 | ||
|
|
b7e6fa9c5f | ||
|
|
dcc986c232 | ||
|
|
95cea9f875 | ||
|
|
a151bdbeca | ||
|
|
6d288de95b | ||
|
|
aa0ebdbc93 | ||
|
|
af50b9c69c | ||
|
|
963fbbe9be | ||
|
|
02ef0c3343 | ||
|
|
1ac6e6b50b | ||
|
|
f1dfe64d67 | ||
|
|
6e8d47b96e | ||
|
|
f04b79bb4a | ||
|
|
bf17a65246 | ||
|
|
3d4702e520 | ||
|
|
266302f09c | ||
|
|
ac130a739e | ||
|
|
dcc316e7e7 | ||
|
|
754214fa8d | ||
|
|
a6f47f137c | ||
|
|
97e43e65f8 | ||
|
|
ef81d97eef | ||
|
|
36d75c8933 | ||
|
|
b37f8465aa | ||
|
|
3d34992fcc | ||
|
|
4602dde7df | ||
|
|
a81d5caa45 | ||
|
|
7ef25e5dc3 | ||
|
|
529ab3f583 | ||
|
|
951883cb1b | ||
|
|
08113b57ba | ||
|
|
63e9c8bea1 | ||
|
|
1d14468924 | ||
|
|
5378fd5907 | ||
|
|
5e8d8bb43e | ||
|
|
da5c68b07c | ||
|
|
0f9af7c217 | ||
|
|
1fd227e8ba | ||
|
|
e4c653fe6a | ||
|
|
f2dc9f7d18 | ||
|
|
8998338563 | ||
|
|
361bbf84bc | ||
|
|
384393358c | ||
|
|
9c2d542f3c | ||
|
|
ab930c4c30 | ||
|
|
1f64514366 | ||
|
|
398592225e | ||
|
|
a95b79d428 | ||
|
|
67c9758a96 | ||
|
|
f555249cc9 | ||
|
|
5e4bc1f0fb | ||
|
|
53d49cf542 | ||
|
|
9b34fa51a0 | ||
|
|
573d8331dc | ||
|
|
333b211b00 | ||
|
|
81718b8848 | ||
|
|
6084a373c8 | ||
|
|
f22f6db331 | ||
|
|
4c7733420f | ||
|
|
88c004997d | ||
|
|
8eb18e8793 | ||
|
|
f56a4e147b | ||
|
|
651668b62e | ||
|
|
1e4f45d4ee | ||
|
|
0bab09e26b | ||
|
|
848e0ccbe8 | ||
|
|
ee402042e6 | ||
|
|
744bc97f0f | ||
|
|
c27da66cf0 | ||
|
|
0039ee0e0f | ||
|
|
1c8347ecb4 | ||
|
|
9e86c1680d | ||
|
|
065f2e2a17 | ||
|
|
3cba095d77 | ||
|
|
24f99bebfb | ||
|
|
f650cda9f6 | ||
|
|
392b503223 | ||
|
|
d66b270051 |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: cubicake
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[Bug]: xyz"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behaviour. A video or images may be helpful here.
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**General debugging information**
|
||||
- Any relevant crash or console logs
|
||||
- The output of `/raycastedentityocclusions`
|
||||
- The output of `/raycastedentityocclusions config-values`
|
||||
- The link returned by `/spark profiler start --timeout 11`
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature Request]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
+7
-2
@@ -1,10 +1,15 @@
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
README.md
|
||||
*.md
|
||||
*.toml
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
# mpeltonen/sbt-idea plugin
|
||||
@@ -101,6 +106,7 @@ $RECYCLE.BIN/
|
||||
*.lnk
|
||||
|
||||
.gradle
|
||||
.gradle-user/
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
@@ -112,8 +118,7 @@ gradle-app.setting
|
||||
**/build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
runs/
|
||||
run*/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
[submodule "logging"]
|
||||
path = logging
|
||||
url = https://github.com/Cubicake/CubiLogging.git
|
||||
[submodule "leafpile"]
|
||||
path = leafpile
|
||||
url = https://github.com/Cubicake/ParallelepipedLeafPile.git
|
||||
branch = java-21-main
|
||||
[submodule "locatables"]
|
||||
path = locatables
|
||||
url = https://github.com/Cubicake/Locatables.git
|
||||
@@ -0,0 +1,19 @@
|
||||
## Contributions
|
||||
Contributions via pull requests are welcome. Please join our [discord](https://discord.cubi.games) or make an `issue` to discuss any contributions beforehand to make sure they will not conflict with or hinder existing plans.
|
||||
|
||||
A good place to start with contributions is to look for `issue`s flagged with the label `Outside Help Welcome`. These have been deemed as uninvasive changes, typically not requiring a complete understanding of the project. You are welcome to send a PR resolving these issues without first discussing changes with a maintainer.
|
||||
|
||||
You must hold the rights to any code you contribute, and must agree to licence it under the same licence as the rest of the project in perpetuity, explicitly including any and all changes to the project's licence by project maintainers in the future. The project's licence can always be found at [LICENSE](LICENSE).
|
||||
|
||||
### Attribution
|
||||
Code files may have a copyright notice at the head of the file as follows.
|
||||
```java
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
```
|
||||
If you made a significant contribution to a file with such a header, you may add your name to the list of names in the copyright notice. Contributing project maintainers should be listed first. All other names should be listed in descending order of contribution to the file, adjudicated by `Cubicake` if necessary. If the list of contributors reaches six names, do not add any more names to the list. You may instead append the text `and other contributors`.
|
||||
@@ -1,21 +1,661 @@
|
||||
MIT License
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (c) 2025 Cubicake
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
@@ -1,39 +1,96 @@
|
||||
Latest version: v1.2.2
|
||||
RaycastedAntiESP is a packet-based plugin for Paper, Folia, and its forks that hides entities (including players) and tile entities (blocks such as chests, banners, signs, etc) from players if they would not be visible to a legitimate player. It is **unbypassable** by design, as packets sent by the server are blocked from reaching the client unless the block/entity has been confirmed to be visible.
|
||||
This limits the usefulness of unfair advantages such as cheat clients, freecam, and x-ray, and completely blocks pie-ray.
|
||||
|
||||
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusion/
|
||||
### Supported Versions
|
||||
While the current "stable" plugin version is v1.6.5, it is strongly recommended that you use the [alpha-channel builds](https://modrinth.com/plugin/raycasted-anti-esp/versions?c=alpha) instead. Since v1.6.5, RaycastedAntiESP has been:
|
||||
- Renamed from RaycastedEntityOcclusions to RaycastedAntiESP
|
||||
- Been almost completely rewritten to be faster and more correct
|
||||
|
||||
This is a simple server-side plugin for PaperMC (May also work with Spigot, this is untested) that hides/culls entities from players if they do not have line-of-sight. All raycasts are run async to reduce performance impact.
|
||||
Use cases:
|
||||
The supported minecraft versions are 1.21.4+. Only Paper and derivative software (including Folia/Canvas) is supported, not Spigot.
|
||||
|
||||
- To prevent mob nametags from being visible through walls
|
||||
- If the mobs don't exist, you can't see them
|
||||
- Act as an "anticheat" to block players from using mods such as freecam to find entities through walls
|
||||
- This is not an actual anticheat and will not detect freecam, instead just making freecam less useful
|
||||
- Freecam will still be useful for locating structures and features such as caves
|
||||
- Reduce client lag
|
||||
- In servers with large megabases full of item frames, armour stands and other entities, RaycastedEntityOcclusion will prevent these entities from lagging the client unless they are within line-of-sight
|
||||
## Use cases:
|
||||
|
||||
Default Config:
|
||||
- Prevent cheating (anti-esp hacks)
|
||||
- This is the plugin's primary purpose.
|
||||
- Block usage of pie-ray to locate underground bases or farms.
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of entities which would not be visible to vanilla players.
|
||||
- Increase client-side performance for low-end devices
|
||||
- Massive megabases containing hundreds of armour stands, item frames, banners etc can cause performance issues on low-end devices unable to process so many entities. Raycasted AntiESP will cull those entities for the client, reducing the number of entities to process.
|
||||
- Reduce network load by limiting packets
|
||||
- With `keep-client-entity-when-hidden` set to true, running RaycastedAntiESP will significantly reduce the number of entity packets sent to the client.
|
||||
- While entity packets are only a small portion of network bandwidth, this will still have a measurable impact and may be useful on extremely bandwidth-limited servers.
|
||||
- Unless you are extremely limited by bandwidth, this will probably be unnoticeable.
|
||||
- Hide nametags behind walls
|
||||
- Yes, this plugin is overkill for doing that, yes you can do it anyways.
|
||||
|
||||
- AlwaysShowRadius: 8
|
||||
- RaycastRadius: 48
|
||||
- SearchRadius: 52
|
||||
- MoreChecks: false
|
||||
- OccludePlayers: false
|
||||
- RecheckInterval: 20
|
||||
## Configuration
|
||||
RaycastedAntiESP has many configuration options. A full list with explanations can be found at https://raycastedantiesp.cubi.games/config/.
|
||||
|
||||
## Dependencies:
|
||||
- Packetevents
|
||||
- Required for all features, as packets are intercepted and rewritten to make sure that clients never learn about anything they should not be able to see.
|
||||
|
||||
Entities inside the AlwaysShowRadius are always shown, even if occluded. This is to prevent nasty surprises when turning a corner quickly.
|
||||
## Known issues:
|
||||
- There will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. Various config options exist to partially address this issue, though all such options necessarily weaken the plugin's ability to block cheaters.
|
||||
|
||||
The SearchRadius is a cubic bounding box around the player within which entities will be checked. If an entity is within the SearchRadius but not the RaycastRadius, it will be automatically hidden.
|
||||
## Versioning:
|
||||
Note that the following versioning information only applies to v2 and beyond, and alpha versions of v2 start with a major version number of 0 rather than 2.
|
||||
|
||||
The RaycastRadius is the radius where entities will be checked. If an entity is currently hidden it will run a raycast every tick. This is to quickly detect when the entity becomes visible. If the entity is currently visible, it will only run the raycast every {RecheckInterval} ticks to reduce performance impact.
|
||||
RaycastedAntiESP binaries are composed of four distinct modules: the core, Locatable-lib (used for platform-independent location objects), [CubiLogging](https://github.com/Cubicake/CubiLogging/tree/main), and a platform adapter.
|
||||
|
||||
MoreChecks toggles between two raycasting modes. By default (MoreChecks = false) the plugin runs one raycast from the center of each mob to the player. This means that if the center of the mob is hidden but some parts should be visible, the player won't be able to see the mob at all. Enabling MoreChecks runs a raycast from the top, bottom, left and right of the entity to the player.
|
||||
Each of these has its own versioning system. Locatable-lib and the logging api both declare public apis, and follow [Semantic Versioning](https://semver.org/#semantic-versioning-specification-semver). The platform adapter and core do not declare public apis, and thus [cannot follow semantic versioning](https://semver.org/#spec-item-1). They still follow a major.minor.patch versioning system, but which version number increments is less deterministic. Generally, major version bumps will be for when significant refactoring or rewriting has occurred, or a very significant distinct feature has been added or removed. Minor version bumps will be for the addition/removal of smaller distinct features, while patch version bumps are for bug fixes and tweaks or minor addition/removals which are related to the features added/removed in the minor version bumps.
|
||||
|
||||
OccludePlayers toggles whether players will be checked. Enabling this prevents ESP mods from revealing players.
|
||||
In addition to the versions for each module, there is also an overall version for each platform binary, which is the version that is advertised in the description and file name, and is used for update checks. This version is a combination of the core and platform adapter versions, in the format `{core version}-PlatformName-{platform adapter version}`. This allows all platforms to share the same first three version numbers, while still allowing for differences in the platform adapter versions.
|
||||
|
||||
## Credits:
|
||||
|
||||
Known issues:
|
||||
- Due to the nature of the plugin, there will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. This issue is partially resolved by turning MoreChecks on
|
||||
- If OccludePlayers is set to true any occluded players will be removed from tablist
|
||||
- When updating the plugin to a version with more config versions, no checks are performed to detect this and add the new configs to config.yml. This means that the config file will be missing several options. (This is an issue when updating to v1.1.0 or v1.2.0). To fix, just copy the new config options from the Default Config section above.
|
||||
- Cubicake (Sole developer and maintainer of RaycastedAntiESP)
|
||||
|
||||
### Special mentions:
|
||||
|
||||
- Strokkur424 and other contributors to [StrokkCommands](https://github.com/Strokkur424/StrokkCommands), an LGPL-licensed open-source annotation-based brigadier command tree generator.
|
||||
- While StrokkCommands is not essential for the functioning of the project, it makes handling commands infinitely easier.
|
||||
- Retrooper, Booky10, and all other contributors to [PacketEvents](https://github.com/retrooper/packetevents), a GPL-licensed open-source library for handling minecraft packets.
|
||||
- PacketEvents is essential for the functioning of the plugin, as it allows for handling of packets across multiple platforms and Minecraft versions.
|
||||
- All contributors to Paper and its upstream projects Spigot and Bukkit, without which none of this would be possible.
|
||||
|
||||
### Note about in-game attributions and other (A)GPL requirements:
|
||||
The plugin includes the command `/raycastedantiespCredits`, which displays a list of all authors and contributors, the license and a link to the source code. It can be run by all players. This command is intended to satisfy the "preservation of specified reasonable legal notices or author attributions" requirement of the AGPLv3 license in an easily accessible way for all users of the plugin, including players on a multiplayer server. If you fork this repository and remove the command you must include some other easily accessible way for all users of your fork to view the same information, as required by the AGPLv3.
|
||||
|
||||
This command has been deliberately named a long and unwieldy name to avoid clashing with any commands your server may wish to add, and does not pose any risks to your server as there is no unfair advantage which can be gained due to knowledge of the plugin's existence on your server.
|
||||
|
||||
It is **illegal** to remove the credits without providing an alternative, equally prominent way for users to view the same information. If for some reason crediting people who have worked on a feature for your server for free is a problem for you, you can contact Cubicake on discord (@cubicake) or make an issue to discuss receiving a specially licensed version with all attributions, credits, and source code links removed.
|
||||
|
||||
Using external software such as a command-hiding plugin to hide the command is **still illegal**, so please do not try to circumvent the requirement to provide attributions, credits, and source code links to users of your server.
|
||||
|
||||
Requesting a custom license is also required if you wish to link (as defined by the AGPL) a closed source project to this project.
|
||||
|
||||
An example of a suitable alternative to the command would be a single book-gui or dialog which contains all attributions, licenses, disclaimers, and source code links for all programs used by the server as long as the gui is easily accessible to all users of the server. Another example would be an NPC placed somewhere at your server's spawn which provides the information, as long as the NPC is not hidden somewhere difficult to access.
|
||||
|
||||
## Contributions:
|
||||
Contributions via pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
||||
|
||||
## Forking:
|
||||
|
||||
Please see the [AGPLv3 license](LICENSE)—especially section 5, section 7, and section 13—before forking this repository, as there are some specific legal requirements for forks.
|
||||
|
||||
In summary, translated into layman, plugin-specific terms, the most important requirements for forks are as follows:
|
||||
1. Forks must not remove any names currently present in the authors/contributors list in the plugin's description, as this falls under the "preservation of specified reasonable legal notices or author attributions".
|
||||
2. Forks must not claim to be the original software, as this falls under the "no misrepresentation of the origin of the material".
|
||||
3. Per section 5 subsection c, derivative works such as forks must remain licenced under AGPLv3, and must include a copy of the license with the work. To be clear, copying any non-trivial amount of code from this repository into your own repository, whether via making a fork, directly copying and pasting or other means, makes it a derivative work and obligates you to license your derivative work under the AGPL v3. You must then include a copy of the license and make the source code (not decompiled code) accessible to all users of your program, explicitly including players on a multiplayer server as well as the server owners.
|
||||
4. "Appropriate Legal Notices" such as the copyright notice, license notice, disclaimer, and link to the source code must be preserved. Currently this is implemented via the `/raycastedantiespCredits` command, and while you are not obligated to keep this specific implementation, if you remove the command you must provide an equally prominent way for all users of the plugin (including players on a multiplayer server) to easily view the same information.
|
||||
|
||||
`games.cubi.raycastedantiesp.paper.commands.Attribution` has been written with forks in mind, and a template has been left for forks to modify so that the AGPLv3 license can be obeyed with minimal effort.
|
||||
|
||||
## Copyright and Disclaimer:
|
||||
Copyright © 2025-2026 Cubicake
|
||||
|
||||
This project is licensed under the GNU Affero General Public License v3.0 only (AGPLv3). You may copy, modify, and redistribute this software only in compliance with the terms of that licence. A copy of the licence is provided in the [LICENSE](LICENSE) file.
|
||||
|
||||
If you modify and deploy this software for remote network interaction, including operating a public multiplayer server, you must make the complete corresponding source code of the modified version available to all users interacting with the software over the network, as required by section 13 of the AGPLv3.
|
||||
|
||||
Any modified versions must be clearly marked as modified and must not be misrepresented as the original project.
|
||||
|
||||
This software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability arising from, out of, or in connection with the software or the use of the software.
|
||||
|
||||
The AGPL is the sole license this program is governed by. All statements found in this copyright notice and disclaimer, the above forking guidelines, or anywhere else in this program should only be considered guidelines and interpretations of the AGPL unless they are direct extracts of the AGPL. If any statement conflicts with the AGPL, the AGPL takes legal precedence over any such statement. However, any such conflicting statements should be taken as good-faith non-binding requests by the authors.
|
||||
@@ -1,49 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'games.cubi'
|
||||
version = '1.3.0-dev'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "papermc-repo"
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/groups/public/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
def targetJavaVersion = 21
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
sourceCompatibility = javaVersion
|
||||
targetCompatibility = javaVersion
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = 'UTF-8'
|
||||
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
options.release.set(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
def props = [version: version]
|
||||
inputs.properties props
|
||||
filteringCharset 'UTF-8'
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" apply false
|
||||
id("xyz.jpenilla.run-paper") version "3.0.2" apply false
|
||||
id("com.gradleup.shadow") version "9.4.0" apply false
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
import java.time.Instant
|
||||
|
||||
plugins {
|
||||
id("java-library")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://repo.codemc.io/repository/maven-releases/") }
|
||||
maven { url = uri("https://repo.codemc.io/repository/maven-snapshots/") }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.spongepowered:configurate-core:4.2.0")
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.2.0")
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.18")
|
||||
|
||||
implementation(project(":locatables"))
|
||||
|
||||
compileOnly(project(":leafpile"))
|
||||
compileOnly(project(":logging"))
|
||||
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.2"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api")
|
||||
testImplementation(project(":leafpile"))
|
||||
testImplementation(project(":logging"))
|
||||
testImplementation("org.spongepowered:configurate-core:4.2.0")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testImplementation("it.unimi.dsi:fastutil:8.5.18")
|
||||
}
|
||||
|
||||
val coreVersion = "0.7.1-SNAPSHOT"
|
||||
|
||||
val isRelease = gradle.startParameter.taskNames.any {
|
||||
it.contains("buildRelease")
|
||||
}
|
||||
|
||||
fun getVersionString(): String {
|
||||
if (isRelease) {
|
||||
return coreVersion.substringBefore("-") // Remove any suffixes like "-SNAPSHOT"
|
||||
} else {
|
||||
return coreVersion
|
||||
}
|
||||
}
|
||||
|
||||
fun getBasicVersionString(): String {
|
||||
return if (isRelease) {
|
||||
coreVersion.substringBefore("-") // Remove any suffixes like "-SNAPSHOT"
|
||||
} else {
|
||||
coreVersion
|
||||
}
|
||||
}
|
||||
|
||||
version = getVersionString()
|
||||
|
||||
val commitShort = providers.exec {
|
||||
commandLine("git", "rev-parse", "--short=8", "HEAD")
|
||||
}.standardOutput.asText.map { it.trim() }
|
||||
|
||||
val commitFull = providers.exec {
|
||||
commandLine("git", "rev-parse", "HEAD")
|
||||
}.standardOutput.asText.map { it.trim() }
|
||||
|
||||
val buildTime = providers.provider {
|
||||
Instant.now().toString()
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
val gitProps = mapOf(
|
||||
"short_git" to commitShort.get(),
|
||||
"long_git" to commitFull.get(),
|
||||
"build_time" to buildTime.get(),
|
||||
"version" to getBasicVersionString()
|
||||
)
|
||||
inputs.properties(gitProps)
|
||||
filesMatching("build-properties/core.yml") {
|
||||
expand(gitProps)
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import games.cubi.logs.PlatformLogger;
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
public class Core {
|
||||
|
||||
public static Core instance;
|
||||
|
||||
private Core(PlatformLogger logger) {
|
||||
Logger.init(logger);
|
||||
}
|
||||
|
||||
public static Core initialize(PlatformLogger logger) {
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
}
|
||||
instance = new Core(logger);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Core getInstance() {
|
||||
if (instance == null) {
|
||||
Logger.error(new IllegalStateException("Core has not been initialized yet but Core#getInstance called!"),1, Core.class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void intelliJStopThinkingThisIsAUtilClass() {}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
/**
|
||||
* Implementations should increment (starting from 0) once a tick, and should call AsyncEngine's tick method each time the tick increments.
|
||||
*/
|
||||
public interface Ticker extends IntSupplier {
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.BlockChunkDataBuilder;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.SingleBlockChunkData;
|
||||
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
public interface BlockChunkData extends ChunkOcclusionView {
|
||||
/**
|
||||
* char is used to denote an unsigned 16-bit integer.
|
||||
*/
|
||||
char getBlockID(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* char is used to denote an unsigned 16-bit integer.
|
||||
*/
|
||||
BlockChunkData setBlockID(int x, int y, int z, char blockID, BlockInfoResolver blockInfoResolver);
|
||||
|
||||
static BlockChunkData filled(char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
return new SingleBlockChunkData(blockID, blockInfoResolver.isOccluding(blockID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds chunk data from a source palette. The index reader receives core-packed positions and returns an index into {@code sourcePalette}.
|
||||
* Unused source entries are discarded before choosing the smallest representation.
|
||||
*/
|
||||
static BlockChunkData copyOfPalette(char[] sourcePalette, IntUnaryOperator paletteIndexAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
return BlockChunkDataBuilder.copyOfPalette(sourcePalette, paletteIndexAtPacked, blockInfoResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds chunk data from a block-state reader. The reader receives core-packed positions.
|
||||
*/
|
||||
static BlockChunkData copyOfStates(IntUnaryOperator blockStateAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
return BlockChunkDataBuilder.copyOfStates(blockStateAtPacked, blockInfoResolver);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
public interface BlockInfoResolver {
|
||||
@Contract(pure = true)
|
||||
boolean isOccluding(int blockStateID);
|
||||
|
||||
/**
|
||||
* Anti-ESP managed tile entity state after config exemptions and force-includes.
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
boolean isTileEntity(int blockStateID);
|
||||
|
||||
/**
|
||||
* Raw block entity capability before anti-ESP config overrides.
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
boolean hasBlockEntityData(int blockStateID);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
public final class ChunkData {
|
||||
public static final int CHUNK_SIZE = 16;
|
||||
public static final int LOCAL_MASK = CHUNK_SIZE - 1;
|
||||
public static final int BLOCK_COUNT = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE;
|
||||
public static final int WORD_COUNT = BLOCK_COUNT / Long.SIZE;
|
||||
|
||||
private ChunkData() {
|
||||
}
|
||||
|
||||
public static int packLocalChecked(int x, int y, int z) {
|
||||
checkLocalCoordinate(x, "x");
|
||||
checkLocalCoordinate(y, "y");
|
||||
checkLocalCoordinate(z, "z");
|
||||
return packUncheckedGuarded(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs the local coordinates into a single integer without checking bounds. Coordinates outside the range will be correctly packed.
|
||||
*/
|
||||
public static int packUncheckedGuarded(int x, int y, int z) {
|
||||
return (z & LOCAL_MASK) << 8 | (y & LOCAL_MASK) << 4 | (x & LOCAL_MASK);
|
||||
}
|
||||
|
||||
public static int unpackX(int packed) {
|
||||
checkPacked(packed);
|
||||
return packed & LOCAL_MASK;
|
||||
}
|
||||
|
||||
public static int unpackY(int packed) {
|
||||
checkPacked(packed);
|
||||
return packed >> 4 & LOCAL_MASK;
|
||||
}
|
||||
|
||||
public static int unpackZ(int packed) {
|
||||
checkPacked(packed);
|
||||
return packed >> 8 & LOCAL_MASK;
|
||||
}
|
||||
|
||||
public static void checkPacked(int packed) {
|
||||
if (packed < 0 || packed >= BLOCK_COUNT) {
|
||||
throw new IllegalArgumentException("packed local block index must be in [0, " + (BLOCK_COUNT - 1) + "], but was " + packed);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkLocalCoordinate(int coordinate, String name) {
|
||||
if (coordinate < 0 || coordinate >= CHUNK_SIZE) {
|
||||
throw new IllegalArgumentException(name + " local coordinate must be in [0, " + LOCAL_MASK + "], but was " + coordinate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.LOCAL_MASK;
|
||||
|
||||
public interface ChunkOcclusionView {
|
||||
/**
|
||||
* The parameters here are local coordinates within the chunk section, so they must be in the range [0, 15].
|
||||
*
|
||||
* @return true if the block at the given local coordinates is occluding, false otherwise.
|
||||
*/
|
||||
boolean isOccludingLocal(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 15) int y, @Range(from = 0, to = 15) int z);
|
||||
|
||||
default boolean isOccludingGlobal(int x, int y, int z) {
|
||||
return isOccludingLocal(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK);
|
||||
}
|
||||
|
||||
default boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
public sealed interface OccludingChunkData extends ChunkOcclusionView permits OccludingChunkData.Solid, OccludingChunkDataImpl {
|
||||
/**
|
||||
* The parameters here are local coordinates within the chunk, so they should be in the range [0, 15].
|
||||
* @return The object to be stored. Mutations may require upgrading the object to a more complex implementation, so the returned object may not be the same as the current one.
|
||||
*/
|
||||
OccludingChunkData setOccluding(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 15) int y, @Range(from = 0, to = 15) int z, boolean occluding);
|
||||
|
||||
static OccludingChunkDataImpl empty() {
|
||||
return new OccludingChunkDataImpl();
|
||||
}
|
||||
|
||||
static OccludingChunkData filled() {
|
||||
return OccludingChunkDataImpl.solid();
|
||||
}
|
||||
|
||||
OccludingChunkData SOLID = new Solid();
|
||||
|
||||
static OccludingChunkData solid() {
|
||||
return SOLID;
|
||||
}
|
||||
|
||||
static OccludingChunkData copyOf(BitSet bitSet) {
|
||||
long[] words = bitSet.toLongArray();
|
||||
if (words.length != ChunkData.WORD_COUNT) {
|
||||
long[] resized = new long[ChunkData.WORD_COUNT];
|
||||
System.arraycopy(words, 0, resized, 0, Math.min(words.length, resized.length));
|
||||
words = resized;
|
||||
}
|
||||
return new OccludingChunkDataImpl(words);
|
||||
}
|
||||
|
||||
final class Solid implements OccludingChunkData {
|
||||
@Override
|
||||
public boolean isOccludingLocal(int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OccludingChunkData setOccluding(int x, int y, int z, boolean occluding) {
|
||||
return filled().setOccluding(x, y, z, occluding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.LONG_ARRAY_HANDLE;
|
||||
|
||||
/**
|
||||
* A 4096-bit bitset, where 1 indicates occluding and 0 indicates not occluding.
|
||||
* Safe for single-writer, multiple-reader setups
|
||||
*/
|
||||
public final class OccludingChunkDataImpl implements OccludingChunkData {
|
||||
// Plain reads/writes would probably be fine as occluding state being stale for a few seconds causes no issues, and tearing is a non-issue as this is a bitset, so only a single bit value matters at a time.
|
||||
// However, plain reads can technically be cached indefinitely, so opaque reads are more correct.
|
||||
|
||||
private final long[] occlusionData;
|
||||
|
||||
public OccludingChunkDataImpl() {
|
||||
this.occlusionData = new long[ChunkData.WORD_COUNT];
|
||||
}
|
||||
|
||||
public OccludingChunkDataImpl(long[] occlusionData) {
|
||||
if (occlusionData.length != ChunkData.WORD_COUNT) {
|
||||
throw new IllegalArgumentException("occlusionData must contain " + ChunkData.WORD_COUNT + " longs");
|
||||
}
|
||||
this.occlusionData = Arrays.copyOf(occlusionData, occlusionData.length);
|
||||
}
|
||||
|
||||
static OccludingChunkDataImpl solid() {
|
||||
// Make every bit 1, which is the same as making every long -1
|
||||
long[] solidData = new long[ChunkData.WORD_COUNT];
|
||||
Arrays.fill(solidData, -1L);
|
||||
return new OccludingChunkDataImpl(solidData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccludingLocal(int x, int y, int z) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long.
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask with only the packed block's bit set.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
// & keeps only the target bit; non-zero means that bit is set.
|
||||
return (word & mask) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OccludingChunkData setOccluding(int x, int y, int z, boolean occluding) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long. Avoids signed division; probably an unnecessary optimisation but why not
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask for only the packed block's bit.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
// If occluding is true, OR the mask in to set the bit; otherwise AND with ~mask to clear it.
|
||||
// ~ flips all bits, so mask becomes all 1 except for the bit being set to 0. ANDing this means that anything in word which was already true stays true and already false stays false, except for the bit being set to false.
|
||||
long updated = occluding ? word | mask : word & ~mask;
|
||||
// Not an atomicity issue since writes are single-threaded
|
||||
LONG_ARRAY_HANDLE.setOpaque(occlusionData, wordIndex, updated);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.CHAR_ARRAY_HANDLE;
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.LONG_ARRAY_HANDLE;
|
||||
|
||||
abstract class AbstractPalettedBlockChunkData implements BlockChunkData {
|
||||
// Each concrete palette store allocates its maximum palette size up front. Adding a block only fills another slot in this array.
|
||||
// When the palette is full, the chunk upgrades to the next implementation.
|
||||
protected final char[] palette;
|
||||
protected final long[] occlusionData;
|
||||
private int paletteSize; //netty reads only
|
||||
|
||||
protected AbstractPalettedBlockChunkData(char blockID, int paletteCapacity, BlockInfoResolver blockInfoResolver) {
|
||||
if (paletteCapacity < 1 || paletteCapacity > 256) {
|
||||
throw new IllegalArgumentException("paletteCapacity must be in [1, 256]");
|
||||
}
|
||||
this.palette = new char[paletteCapacity];
|
||||
this.occlusionData = new long[ChunkData.WORD_COUNT];
|
||||
setPaletteBlock(0, blockID);
|
||||
paletteSize = 1;
|
||||
if (blockInfoResolver.isOccluding(blockID)) {
|
||||
Arrays.fill(this.occlusionData, -1L);
|
||||
}
|
||||
}
|
||||
|
||||
protected AbstractPalettedBlockChunkData(char[] palette, int paletteSize, int paletteCapacity, long[] occlusionData) {
|
||||
if (paletteCapacity < 1 || paletteCapacity > 256) {
|
||||
throw new IllegalArgumentException("paletteCapacity must be in [1, 256]");
|
||||
}
|
||||
if (paletteSize < 1 || paletteSize > paletteCapacity || palette.length < paletteSize) {
|
||||
throw new IllegalArgumentException("paletteSize must be in [1, paletteCapacity]");
|
||||
}
|
||||
if (occlusionData.length != ChunkData.WORD_COUNT) {
|
||||
throw new IllegalArgumentException("occlusionData must contain " + ChunkData.WORD_COUNT + " longs");
|
||||
}
|
||||
this.palette = new char[paletteCapacity];
|
||||
for (int i = 0; i < paletteSize; i++) {
|
||||
setPaletteBlock(i, palette[i]);
|
||||
}
|
||||
this.occlusionData = Arrays.copyOf(occlusionData, occlusionData.length);
|
||||
this.paletteSize = paletteSize;
|
||||
}
|
||||
|
||||
protected AbstractPalettedBlockChunkData(AbstractPalettedBlockChunkData source, int paletteCapacity) {
|
||||
this(source.palette, source.paletteSize, paletteCapacity, source.occlusionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final char getBlockID(int x, int y, int z) {
|
||||
return getBlockIDPackedUnchecked(ChunkData.packLocalChecked(x, y, z));
|
||||
}
|
||||
|
||||
protected final char getBlockIDPacked(int packed) {
|
||||
ChunkData.checkPacked(packed);
|
||||
return paletteBlock(getPaletteIndex(packed));
|
||||
}
|
||||
|
||||
private char getBlockIDPackedUnchecked(int packed) {
|
||||
return paletteBlock(getPaletteIndex(packed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isOccludingLocal(int x, int y, int z) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
return isOccludingPacked(packed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockChunkData setBlockID(int x, int y, int z, char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
int paletteIndex = indexOf(blockID);
|
||||
if (paletteIndex >= 0) {
|
||||
setPaletteIndex(packed, paletteIndex);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(blockID));
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!canAddPaletteEntry()) {
|
||||
return upgrade().setBlockID(x, y, z, blockID, blockInfoResolver);
|
||||
}
|
||||
|
||||
paletteIndex = addPaletteEntry(blockID);
|
||||
setPaletteIndex(packed, paletteIndex);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(blockID));
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract int getPaletteIndex(int packed);
|
||||
|
||||
protected abstract void setPaletteIndex(int packed, int paletteIndex);
|
||||
|
||||
protected abstract BlockChunkData upgrade();
|
||||
|
||||
private int indexOf(char blockID) {
|
||||
int size = paletteSize;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (paletteBlock(i) == blockID) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private boolean canAddPaletteEntry() {
|
||||
return paletteSize < palette.length;
|
||||
}
|
||||
|
||||
private int addPaletteEntry(char blockID) {
|
||||
int size = paletteSize;
|
||||
setPaletteBlock(size, blockID);
|
||||
paletteSize = size + 1;
|
||||
return size;
|
||||
}
|
||||
|
||||
protected final boolean isOccludingPacked(int packed) {
|
||||
ChunkData.checkPacked(packed);
|
||||
int wordIndex = packed >>> 6;
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
return (word & mask) != 0;
|
||||
}
|
||||
|
||||
protected final void setOccludingPacked(int packed, boolean occluding) {
|
||||
ChunkData.checkPacked(packed);
|
||||
int wordIndex = packed >>> 6;
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
long updated = occluding ? word | mask : word & ~mask;
|
||||
LONG_ARRAY_HANDLE.setOpaque(occlusionData, wordIndex, updated);
|
||||
}
|
||||
|
||||
protected final char paletteBlock(int index) {
|
||||
return (char) CHAR_ARRAY_HANDLE.getAcquire(palette, index);
|
||||
}
|
||||
|
||||
protected final void setPaletteBlock(int index, char blockID) {
|
||||
CHAR_ARRAY_HANDLE.setRelease(palette, index, blockID);
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
public final class BlockChunkDataBuilder {
|
||||
private static final int BYTE_PALETTE_LIMIT = 256;
|
||||
|
||||
private BlockChunkDataBuilder() {
|
||||
}
|
||||
|
||||
public static BlockChunkData copyOfPalette(char[] sourcePalette, IntUnaryOperator sourceIndexAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
if (sourcePalette.length == 0 || sourcePalette.length > BYTE_PALETTE_LIMIT) {
|
||||
throw new IllegalArgumentException("sourcePalette must contain between 1 and " + BYTE_PALETTE_LIMIT + " entries");
|
||||
}
|
||||
|
||||
// First compact only the source entries actually referenced by the 4,096 blocks.
|
||||
int[] remap = new int[sourcePalette.length];
|
||||
Arrays.fill(remap, -1);
|
||||
char[] compactPalette = new char[sourcePalette.length];
|
||||
int compactSize = 0;
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
int sourceIndex = checkedPaletteIndex(sourceIndexAtPacked.applyAsInt(packed), sourcePalette.length);
|
||||
if (remap[sourceIndex] == -1) {
|
||||
remap[sourceIndex] = compactSize;
|
||||
compactPalette[compactSize++] = sourcePalette[sourceIndex];
|
||||
}
|
||||
}
|
||||
|
||||
final int usedPaletteSize = compactSize;
|
||||
// Readers are intentionally invoked again below; rescanning avoids a 4,096-entry temporary index array.
|
||||
IntUnaryOperator compactIndexAtPacked = packed -> {
|
||||
int sourceIndex = checkedPaletteIndex(sourceIndexAtPacked.applyAsInt(packed), sourcePalette.length);
|
||||
return remap[sourceIndex];
|
||||
};
|
||||
char[] usedPalette = Arrays.copyOf(compactPalette, usedPaletteSize);
|
||||
if (usedPaletteSize == 1) {
|
||||
return new SingleBlockChunkData(usedPalette[0], blockInfoResolver.isOccluding(usedPalette[0]));
|
||||
}
|
||||
if (usedPaletteSize == 2) {
|
||||
long[] bitData = new long[ChunkData.WORD_COUNT];
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
if (compactIndexAtPacked.applyAsInt(packed) == 1) {
|
||||
setPackedBit(bitData, packed);
|
||||
}
|
||||
}
|
||||
return new TwoBlockChunkData(usedPalette[1], usedPalette[0], blockInfoResolver.isOccluding(usedPalette[1]), blockInfoResolver.isOccluding(usedPalette[0]), bitData);
|
||||
}
|
||||
if (usedPaletteSize <= 4) {
|
||||
return new FourBlockChunkData(usedPalette, usedPaletteSize, compactIndexAtPacked, blockInfoResolver);
|
||||
}
|
||||
if (usedPaletteSize <= 16) {
|
||||
return new SixteenBlockChunkData(usedPalette, usedPaletteSize, compactIndexAtPacked, blockInfoResolver);
|
||||
}
|
||||
return new ByteArrayBlockChunkData(usedPalette, usedPaletteSize, compactIndexAtPacked, blockInfoResolver);
|
||||
}
|
||||
|
||||
public static BlockChunkData copyOfStates(IntUnaryOperator blockStateAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
char[] palette = new char[BYTE_PALETTE_LIMIT];
|
||||
int paletteSize = 0;
|
||||
boolean overflow = false;
|
||||
// Global palettes have no local index table. Discover whether a byte palette is possible without storing 4,096 indices.
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
char blockID = checkedBlockID(blockStateAtPacked.applyAsInt(packed));
|
||||
if (!overflow && indexOf(palette, paletteSize, blockID) < 0) {
|
||||
if (paletteSize == BYTE_PALETTE_LIMIT) {
|
||||
overflow = true;
|
||||
} else {
|
||||
palette[paletteSize++] = blockID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!overflow) {
|
||||
// Delegate to the compact palette path; the state reader is rescanned to keep temporary allocation bounded by palette size.
|
||||
final int size = paletteSize;
|
||||
char[] sourcePalette = Arrays.copyOf(palette, size);
|
||||
return copyOfPalette(sourcePalette, packed -> indexOf(sourcePalette, size, checkedBlockID(blockStateAtPacked.applyAsInt(packed))), blockInfoResolver);
|
||||
}
|
||||
|
||||
// More than 256 states require final direct storage, populated together with its occlusion mask.
|
||||
char[] blockData = new char[ChunkData.BLOCK_COUNT];
|
||||
long[] occlusionData = new long[ChunkData.WORD_COUNT];
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
char blockID = checkedBlockID(blockStateAtPacked.applyAsInt(packed));
|
||||
blockData[packed] = blockID;
|
||||
if (blockInfoResolver.isOccluding(blockID)) {
|
||||
setPackedBit(occlusionData, packed);
|
||||
}
|
||||
}
|
||||
return new CharArrayBlockChunkData(blockData, occlusionData, true);
|
||||
}
|
||||
|
||||
private static int indexOf(char[] palette, int paletteSize, char blockID) {
|
||||
for (int index = 0; index < paletteSize; index++) {
|
||||
if (palette[index] == blockID) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int checkedPaletteIndex(int paletteIndex, int paletteSize) {
|
||||
if (paletteIndex < 0 || paletteIndex >= paletteSize) {
|
||||
throw new IllegalArgumentException("palette index must be in [0, " + (paletteSize - 1) + "], but was " + paletteIndex);
|
||||
}
|
||||
return paletteIndex;
|
||||
}
|
||||
|
||||
private static char checkedBlockID(int blockID) {
|
||||
if (blockID < 0 || blockID > Character.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("blockID must fit in an unsigned 16-bit value, but was " + blockID);
|
||||
}
|
||||
return (char) blockID;
|
||||
}
|
||||
|
||||
private static void setPackedBit(long[] data, int packed) {
|
||||
// packed >>> 6 selects the 64-bit word; Java masks the long shift distance to packed & 63 for the bit.
|
||||
data[packed >>> 6] |= 1L << packed;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.BYTE_ARRAY_HANDLE;
|
||||
|
||||
public class ByteArrayBlockChunkData extends AbstractPalettedBlockChunkData {
|
||||
private final byte[] blockData = new byte[ChunkData.BLOCK_COUNT];
|
||||
|
||||
public ByteArrayBlockChunkData(char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
super(blockID, 256, blockInfoResolver);
|
||||
}
|
||||
|
||||
ByteArrayBlockChunkData(char[] palette, int paletteSize, IntUnaryOperator indexAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
super(palette, paletteSize, 256, new long[ChunkData.WORD_COUNT]);
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
int paletteIndex = indexAtPacked.applyAsInt(packed);
|
||||
setPaletteIndex(packed, paletteIndex);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(palette[paletteIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
private ByteArrayBlockChunkData(SixteenBlockChunkData old) {
|
||||
super(old, 256);
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
setPaletteIndex(packed, old.getPaletteIndex(packed));
|
||||
}
|
||||
}
|
||||
|
||||
static ByteArrayBlockChunkData upgradeFromSixteenBlock(SixteenBlockChunkData old) {
|
||||
return new ByteArrayBlockChunkData(old);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPaletteIndex(int packed) {
|
||||
// Each block gets one byte, so the packed block index directly selects the byte containing its palette index.
|
||||
// Byte.toUnsignedInt converts Java's signed byte back to the intended 0-255 palette index.
|
||||
return Byte.toUnsignedInt((byte) BYTE_ARRAY_HANDLE.getOpaque(blockData, packed));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPaletteIndex(int packed, int paletteIndex) {
|
||||
// Each block gets one byte, so the packed block index directly selects where to store the 0-255 palette index.
|
||||
BYTE_ARRAY_HANDLE.setOpaque(blockData, packed, (byte) paletteIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockChunkData upgrade() {
|
||||
return CharArrayBlockChunkData.upgradeFromByteArrayBlock(this);
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.CHAR_ARRAY_HANDLE;
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.LONG_ARRAY_HANDLE;
|
||||
|
||||
public class CharArrayBlockChunkData implements BlockChunkData {
|
||||
private final char[] blockData;
|
||||
private final long[] occlusionData;
|
||||
|
||||
public CharArrayBlockChunkData(char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
this.blockData = new char[ChunkData.BLOCK_COUNT];
|
||||
Arrays.fill(this.blockData, blockID);
|
||||
this.occlusionData = new long[ChunkData.WORD_COUNT];
|
||||
if (blockInfoResolver.isOccluding(blockID)) {
|
||||
Arrays.fill(this.occlusionData, -1L);
|
||||
}
|
||||
}
|
||||
|
||||
CharArrayBlockChunkData(char[] blockData, long[] occlusionData) {
|
||||
this(blockData, occlusionData, false);
|
||||
}
|
||||
|
||||
CharArrayBlockChunkData(char[] blockData, long[] occlusionData, boolean takeOwnership) {
|
||||
if (blockData.length != ChunkData.BLOCK_COUNT) {
|
||||
throw new IllegalArgumentException("blockData must contain " + ChunkData.BLOCK_COUNT + " entries");
|
||||
}
|
||||
if (occlusionData.length != ChunkData.WORD_COUNT) {
|
||||
throw new IllegalArgumentException("occlusionData must contain " + ChunkData.WORD_COUNT + " longs");
|
||||
}
|
||||
this.blockData = takeOwnership ? blockData : Arrays.copyOf(blockData, blockData.length);
|
||||
this.occlusionData = takeOwnership ? occlusionData : Arrays.copyOf(occlusionData, occlusionData.length);
|
||||
}
|
||||
|
||||
static CharArrayBlockChunkData upgradeFromByteArrayBlock(ByteArrayBlockChunkData old) {
|
||||
char[] blockData = new char[ChunkData.BLOCK_COUNT];
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
blockData[packed] = old.getBlockIDPacked(packed);
|
||||
}
|
||||
return new CharArrayBlockChunkData(blockData, old.occlusionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getBlockID(int x, int y, int z) {
|
||||
return (char) CHAR_ARRAY_HANDLE.getOpaque(blockData, ChunkData.packLocalChecked(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockChunkData setBlockID(int x, int y, int z, char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
CHAR_ARRAY_HANDLE.setOpaque(blockData, packed, blockID);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(blockID));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccludingLocal(int x, int y, int z) {
|
||||
int packed = ChunkData.packLocalChecked(x, y, z);
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long.
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask with only the packed block's bit set.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
// & keeps only the target bit; non-zero means that bit is set.
|
||||
return (word & mask) != 0;
|
||||
}
|
||||
|
||||
private void setOccludingPacked(int packed, boolean occluding) {
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long.
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask for only the packed block's bit.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(occlusionData, wordIndex);
|
||||
// If occluding is true, OR the mask in to set the bit; otherwise AND with ~mask to clear it.
|
||||
long updated = occluding ? word | mask : word & ~mask;
|
||||
LONG_ARRAY_HANDLE.setOpaque(occlusionData, wordIndex, updated);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.BYTE_ARRAY_HANDLE;
|
||||
|
||||
public class FourBlockChunkData extends AbstractPalettedBlockChunkData {
|
||||
private static final int ENTRIES_PER_BYTE = 4;
|
||||
private static final int BITS_PER_ENTRY = 2;
|
||||
private static final int PALETTE_MASK = 0b11;
|
||||
|
||||
private final byte[] blockData = new byte[ChunkData.BLOCK_COUNT / ENTRIES_PER_BYTE];
|
||||
|
||||
public FourBlockChunkData(char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
super(blockID, 4, blockInfoResolver);
|
||||
}
|
||||
|
||||
FourBlockChunkData(char[] palette, int paletteSize, int[] indices, long[] occlusionData) {
|
||||
super(palette, paletteSize, 4, occlusionData);
|
||||
if (indices.length != ChunkData.BLOCK_COUNT) {
|
||||
throw new IllegalArgumentException("indices must contain " + ChunkData.BLOCK_COUNT + " entries");
|
||||
}
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
setPaletteIndex(packed, indices[packed]);
|
||||
}
|
||||
}
|
||||
|
||||
FourBlockChunkData(char[] palette, int paletteSize, IntUnaryOperator indexAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
super(palette, paletteSize, 4, new long[ChunkData.WORD_COUNT]);
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
int paletteIndex = indexAtPacked.applyAsInt(packed);
|
||||
setPaletteIndex(packed, paletteIndex);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(palette[paletteIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
static FourBlockChunkData upgradeFromTwoBlock(TwoBlockChunkData old) {
|
||||
int[] indices = new int[ChunkData.BLOCK_COUNT];
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
indices[packed] = old.bitIsSet(packed) ? 1 : 0;
|
||||
}
|
||||
return new FourBlockChunkData(new char[]{old.falseBitBlock(), old.trueBitBlock()}, 2, indices, old.copyOcclusionData());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPaletteIndex(int packed) {
|
||||
// >>> 2 divides the packed block index by 4 to select the byte containing this block's 2-bit palette index.
|
||||
int byteIndex = packed >>> 2;
|
||||
// packed & 0b11 gets the block's position inside that byte, then * 2 converts it to a bit offset.
|
||||
int shift = (packed & 0b11) * BITS_PER_ENTRY;
|
||||
int packedByte = Byte.toUnsignedInt((byte) BYTE_ARRAY_HANDLE.getOpaque(blockData, byteIndex));
|
||||
// >>> moves the target 2-bit index to the bottom, and & keeps only those 2 bits.
|
||||
return (packedByte >>> shift) & PALETTE_MASK;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPaletteIndex(int packed, int paletteIndex) {
|
||||
// >>> 2 divides the packed block index by 4 to select the byte containing this block's 2-bit palette index.
|
||||
int byteIndex = packed >>> 2;
|
||||
// packed & 0b11 gets the block's position inside that byte, then * 2 converts it to a bit offset.
|
||||
int shift = (packed & 0b11) * BITS_PER_ENTRY;
|
||||
// PALETTE_MASK << shift creates 1s over the old 2-bit index; ~ flips that to 0s over only the target index.
|
||||
int clearMask = ~(PALETTE_MASK << shift);
|
||||
int packedByte = Byte.toUnsignedInt((byte) BYTE_ARRAY_HANDLE.getOpaque(blockData, byteIndex));
|
||||
// & clearMask clears the old index, then | writes the new 2-bit palette index into the cleared slot.
|
||||
int updated = (packedByte & clearMask) | ((paletteIndex & PALETTE_MASK) << shift);
|
||||
BYTE_ARRAY_HANDLE.setOpaque(blockData, byteIndex, (byte) updated);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockChunkData upgrade() {
|
||||
return SixteenBlockChunkData.upgradeFromFourBlock(this);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
|
||||
// If it is air, just use a null reference
|
||||
public class SingleBlockChunkData implements BlockChunkData {
|
||||
final char blockID;
|
||||
private final boolean occluding;
|
||||
|
||||
public SingleBlockChunkData(char blockID, boolean occluding) {
|
||||
this.blockID = blockID;
|
||||
this.occluding = occluding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getBlockID(int x, int y, int z) {
|
||||
ChunkData.packLocalChecked(x, y, z);
|
||||
return blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockChunkData setBlockID(int x, int y, int z, char newBlockID, BlockInfoResolver blockInfoResolver) {
|
||||
ChunkData.packLocalChecked(x, y, z);
|
||||
if (newBlockID == this.blockID) {
|
||||
return this; // Chunk data did not change, no need to resize
|
||||
}
|
||||
return TwoBlockChunkData.upgradeFromSingleBlock(this, newBlockID, x, y, z, blockInfoResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccludingLocal(int x, int y, int z) {
|
||||
ChunkData.packLocalChecked(x, y, z);
|
||||
return occluding;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.BYTE_ARRAY_HANDLE;
|
||||
|
||||
public class SixteenBlockChunkData extends AbstractPalettedBlockChunkData {
|
||||
private static final int ENTRIES_PER_BYTE = 2;
|
||||
private static final int BITS_PER_ENTRY = 4;
|
||||
private static final int PALETTE_MASK = 0b1111;
|
||||
|
||||
private final byte[] blockData = new byte[ChunkData.BLOCK_COUNT / ENTRIES_PER_BYTE];
|
||||
|
||||
public SixteenBlockChunkData(char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
super(blockID, 16, blockInfoResolver);
|
||||
}
|
||||
|
||||
SixteenBlockChunkData(char[] palette, int paletteSize, IntUnaryOperator indexAtPacked, BlockInfoResolver blockInfoResolver) {
|
||||
super(palette, paletteSize, 16, new long[ChunkData.WORD_COUNT]);
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
int paletteIndex = indexAtPacked.applyAsInt(packed);
|
||||
setPaletteIndex(packed, paletteIndex);
|
||||
setOccludingPacked(packed, blockInfoResolver.isOccluding(palette[paletteIndex]));
|
||||
}
|
||||
}
|
||||
|
||||
private SixteenBlockChunkData(FourBlockChunkData old) {
|
||||
super(old, 16);
|
||||
for (int packed = 0; packed < ChunkData.BLOCK_COUNT; packed++) {
|
||||
setPaletteIndex(packed, old.getPaletteIndex(packed));
|
||||
}
|
||||
}
|
||||
|
||||
static SixteenBlockChunkData upgradeFromFourBlock(FourBlockChunkData old) {
|
||||
return new SixteenBlockChunkData(old);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPaletteIndex(int packed) {
|
||||
// >>> 1 divides the packed block index by 2 to select the byte containing this block's 4-bit palette index.
|
||||
int byteIndex = packed >>> 1;
|
||||
// packed & 1 selects the low or high nibble, then * 4 converts it to a bit offset.
|
||||
int shift = (packed & 1) * BITS_PER_ENTRY;
|
||||
int packedByte = Byte.toUnsignedInt((byte) BYTE_ARRAY_HANDLE.getOpaque(blockData, byteIndex));
|
||||
// >>> moves the target nibble to the bottom, and & keeps only those 4 bits.
|
||||
return (packedByte >>> shift) & PALETTE_MASK;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPaletteIndex(int packed, int paletteIndex) {
|
||||
// >>> 1 divides the packed block index by 2 to select the byte containing this block's 4-bit palette index.
|
||||
int byteIndex = packed >>> 1;
|
||||
// packed & 1 selects the low or high nibble, then * 4 converts it to a bit offset.
|
||||
int shift = (packed & 1) * BITS_PER_ENTRY;
|
||||
// PALETTE_MASK << shift creates 1s over the old nibble; ~ flips that to 0s over only the target nibble.
|
||||
int clearMask = ~(PALETTE_MASK << shift);
|
||||
int packedByte = Byte.toUnsignedInt((byte) BYTE_ARRAY_HANDLE.getOpaque(blockData, byteIndex));
|
||||
// & clearMask clears the old nibble, then | writes the new 4-bit palette index into the cleared slot.
|
||||
int updated = (packedByte & clearMask) | ((paletteIndex & PALETTE_MASK) << shift);
|
||||
BYTE_ARRAY_HANDLE.setOpaque(blockData, byteIndex, (byte) updated);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockChunkData upgrade() {
|
||||
return ByteArrayBlockChunkData.upgradeFromSixteenBlock(this);
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.packLocalChecked;
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.packUncheckedGuarded;
|
||||
import static games.cubi.raycastedantiesp.core.utils.VarHandler.LONG_ARRAY_HANDLE;
|
||||
|
||||
//functionally a bitset
|
||||
public class TwoBlockChunkData implements BlockChunkData {
|
||||
// Plain reads/writes would probably be fine as occluding state being stale for a few seconds causes no issues, and tearing is a non-issue as this is a bitset, so only a single bit value matters at a time.
|
||||
// However, plain reads can technically be cached indefinitely, so opaque reads are more correct.
|
||||
|
||||
private final char trueBitBlock;
|
||||
private final char falseBitBlock;
|
||||
private final boolean trueBitBlockIsOccluding;
|
||||
private final boolean falseBitBlockIsOccluding;
|
||||
private final long[] blockData;
|
||||
|
||||
TwoBlockChunkData(char trueBitBlock, char falseBitBlock, boolean trueBitBlockIsOccluding, boolean falseBitBlockIsOccluding, long[] blockData) {
|
||||
this.trueBitBlock = trueBitBlock;
|
||||
this.falseBitBlock = falseBitBlock;
|
||||
this.trueBitBlockIsOccluding = trueBitBlockIsOccluding;
|
||||
this.falseBitBlockIsOccluding = falseBitBlockIsOccluding;
|
||||
if (blockData.length != ChunkData.WORD_COUNT) {
|
||||
throw new IllegalArgumentException("blockData must have length " + ChunkData.WORD_COUNT + ", but has length " + blockData.length);
|
||||
}
|
||||
this.blockData = Arrays.copyOf(blockData, blockData.length);
|
||||
}
|
||||
|
||||
static TwoBlockChunkData upgradeFromSingleBlock(SingleBlockChunkData old, char newBlockID, int newX, int newY, int newZ, BlockInfoResolver blockInfoResolver) {
|
||||
long[] blockData = new long[ChunkData.WORD_COUNT];
|
||||
TwoBlockChunkData upgraded = new TwoBlockChunkData(newBlockID, old.blockID, blockInfoResolver.isOccluding(newBlockID), blockInfoResolver.isOccluding(old.blockID), blockData);
|
||||
upgraded.setBit(packLocalChecked(newX, newY, newZ), true);
|
||||
return upgraded;
|
||||
}
|
||||
|
||||
public static TwoBlockChunkData upgradeFromAir(char newBlockID, int newXGlobal, int newYGlobal, int newZGlobal, BlockInfoResolver blockInfoResolver) {
|
||||
long[] blockData = new long[ChunkData.WORD_COUNT];
|
||||
TwoBlockChunkData upgraded = new TwoBlockChunkData(newBlockID, (char) 0, blockInfoResolver.isOccluding(newBlockID), blockInfoResolver.isOccluding(0), blockData);
|
||||
upgraded.setBit(packUncheckedGuarded(newXGlobal, newYGlobal, newZGlobal), true);
|
||||
return upgraded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getBlockID(int x, int y, int z) {
|
||||
return bitIsSet(packLocalChecked(x, y, z)) ? trueBitBlock : falseBitBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccludingLocal(int x, int y, int z) {
|
||||
return bitIsSet(packLocalChecked(x, y, z)) ? trueBitBlockIsOccluding : falseBitBlockIsOccluding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockChunkData setBlockID(int x, int y, int z, char blockID, BlockInfoResolver blockInfoResolver) {
|
||||
int packed = packLocalChecked(x, y, z);
|
||||
if (blockID == trueBitBlock) {
|
||||
setBit(packed, true);
|
||||
return this;
|
||||
}
|
||||
if (blockID == falseBitBlock) {
|
||||
setBit(packed, false);
|
||||
return this;
|
||||
}
|
||||
return FourBlockChunkData.upgradeFromTwoBlock(this).setBlockID(x, y, z, blockID, blockInfoResolver);
|
||||
}
|
||||
|
||||
char trueBitBlock() {
|
||||
return trueBitBlock;
|
||||
}
|
||||
|
||||
char falseBitBlock() {
|
||||
return falseBitBlock;
|
||||
}
|
||||
|
||||
long[] copyOcclusionData() {
|
||||
long[] copied = new long[ChunkData.WORD_COUNT];
|
||||
if (trueBitBlockIsOccluding == falseBitBlockIsOccluding) {
|
||||
if (trueBitBlockIsOccluding) {
|
||||
Arrays.fill(copied, -1L);
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
for (int wordIndex = 0; wordIndex < blockData.length; wordIndex++) {
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(blockData, wordIndex);
|
||||
copied[wordIndex] = trueBitBlockIsOccluding ? word : ~word;
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
boolean bitIsSet(int packed) {
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long.
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask with only the packed block's bit set.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(blockData, wordIndex);
|
||||
// & keeps only the target bit; non-zero means that bit is set.
|
||||
return (word & mask) != 0;
|
||||
}
|
||||
|
||||
private void setBit(int packed, boolean value) {
|
||||
// >>> 6 divides the packed block index by 64 to select the containing long. Avoids signed division; probably an unnecessary optimisation but why not
|
||||
int wordIndex = packed >>> 6;
|
||||
// 1L << packed creates a mask for only the packed block's bit.
|
||||
long mask = 1L << packed;
|
||||
long word = (long) LONG_ARRAY_HANDLE.getOpaque(blockData, wordIndex);
|
||||
long updated = value ? word | mask : word & ~mask;
|
||||
LONG_ARRAY_HANDLE.setOpaque(blockData, wordIndex, updated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record BlockProcessorConfig(BlockProcessorMode mode, boolean trackAllBlocks) implements Config {
|
||||
public static BlockProcessorConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "block-processor");
|
||||
String modeName = ConfigReader.string(ConfigReader.node(node, "mode"), "block-processor.mode");
|
||||
BlockProcessorMode mode = BlockProcessorMode.fromString(modeName);
|
||||
if (mode == null) {
|
||||
throw new ConfigLoadException("block-processor.mode has unsupported value '" + modeName + "'");
|
||||
}
|
||||
return new BlockProcessorConfig(
|
||||
mode,
|
||||
ConfigReader.bool(ConfigReader.node(node, "track-all-blocks"), "block-processor.track-all-blocks")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum BlockProcessorMode implements ConfigEnum {
|
||||
PACKETEVENTS("packetevents");
|
||||
|
||||
private final String configName;
|
||||
|
||||
BlockProcessorMode(String configName) {
|
||||
this.configName = configName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return configName;
|
||||
}
|
||||
|
||||
public static @Nullable BlockProcessorMode fromString(String name) {
|
||||
for (BlockProcessorMode mode : values()) {
|
||||
if (mode.configName.equalsIgnoreCase(name)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues() {
|
||||
return new String[] {configName};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.ChunkSectionConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.SoundEffectsConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.TileEntityConfig;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record ChecksConfig(PlayerConfig playerConfig, EntityConfig entityConfig, TileEntityConfig tileEntityConfig, SoundEffectsConfig soundEffectsConfig, ChunkSectionConfig chunkSectionConfig) implements Config {
|
||||
public static ChecksConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode checks = ConfigReader.node(root, "checks");
|
||||
return new ChecksConfig(
|
||||
PlayerConfig.load(ConfigReader.node(checks, "player"), "checks.player"),
|
||||
EntityConfig.load(ConfigReader.node(checks, "entity"), "checks.entity"),
|
||||
TileEntityConfig.load(ConfigReader.node(checks, "tile-entity"), "checks.tile-entity"),
|
||||
SoundEffectsConfig.load(ConfigReader.node(checks, "sound-effects"), "checks.sound-effects"),
|
||||
ChunkSectionConfig.load(ConfigReader.node(checks, "chunk-section"), "checks.chunk-section")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean hasEnabledStatusChanges(ChecksConfig startup) {
|
||||
return playerConfig.enabled() != startup.playerConfig.enabled()
|
||||
|| entityConfig.enabled() != startup.entityConfig.enabled()
|
||||
|| chunkSectionConfig.enabled() != startup.chunkSectionConfig.enabled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public interface Config {
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ConfigEnum {
|
||||
String[] getValues();
|
||||
|
||||
Registry REGISTRY = new Registry();
|
||||
|
||||
default void register() {
|
||||
REGISTRY.add(this.getClass());
|
||||
}
|
||||
|
||||
static String[] getAllValues() {
|
||||
return REGISTRY.getAllValues();
|
||||
}
|
||||
|
||||
final class Registry {
|
||||
private final Set<Class<? extends ConfigEnum>> enums = new HashSet<>();
|
||||
|
||||
void add(Class<? extends ConfigEnum> e) {
|
||||
enums.add(e);
|
||||
}
|
||||
|
||||
String[] getAllValues() {
|
||||
return enums.stream()
|
||||
.flatMap(e -> Arrays.stream(e.getEnumConstants()[0].getValues()))
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public interface ConfigExtension<T extends Config> {
|
||||
Class<T> type();
|
||||
|
||||
T load(ConfigurationNode config, BlockProcessorConfig blockProcessorConfig);
|
||||
|
||||
default boolean requiresRestart(T startupConfig, T nextConfig) {
|
||||
return !startupConfig.equals(nextConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public class ConfigLoadException extends RuntimeException {
|
||||
public ConfigLoadException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ConfigLoadException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.engine.EngineConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.ChunkSectionConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.SoundEffectsConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.TileEntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ConfigManager {
|
||||
private static final String REQUIRED_CONFIG_VERSION = "2.0";
|
||||
private static ConfigManager instance;
|
||||
|
||||
private final Supplier<InputStream> resourceSupplier;
|
||||
private final Path dataFolder;
|
||||
private final Path configPath;
|
||||
private final YamlConfigurationLoader loader;
|
||||
private final List<ConfigExtension<? extends Config>> extensions;
|
||||
|
||||
private ConfigurationNode config;
|
||||
private RootConfig startupConfig;
|
||||
private volatile RootConfig activeConfig; private static final VarHandle ACTIVE_CONFIG = VarHandler.get(ConfigManager.class, "activeConfig", RootConfig.class);
|
||||
|
||||
private ConfigManager(Supplier<InputStream> resourceSupplier, Path dataFolder, List<ConfigExtension<? extends Config>> extensions) {
|
||||
this.resourceSupplier = resourceSupplier;
|
||||
this.dataFolder = dataFolder;
|
||||
this.extensions = List.copyOf(extensions);
|
||||
this.configPath = dataFolder.resolve("config.yml");
|
||||
this.loader = YamlConfigurationLoader.builder()
|
||||
.path(configPath)
|
||||
.nodeStyle(NodeStyle.BLOCK)
|
||||
.build();
|
||||
load();
|
||||
}
|
||||
|
||||
public static ConfigManager initialiseConfigManager(Supplier<InputStream> resourceSupplier, Path dataFolder, List<ConfigExtension<? extends Config>> extensions) {
|
||||
if (instance == null) {
|
||||
instance = new ConfigManager(resourceSupplier, dataFolder, extensions);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ConfigManager get() {
|
||||
if (instance == null) {
|
||||
Logger.errorAndReturn(new RuntimeException("ConfigManager accessed before being initiated. Please report this."), 2, ConfigManager.class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void load() {
|
||||
ensureConfigFileExists();
|
||||
ConfigurationNode loaded = loadConfigNode();
|
||||
ConfigurationNode defaults = loadBundledDefaults();
|
||||
if (defaults != null && mergeMissing(defaults, loaded)) {
|
||||
saveConfigNode(loaded);
|
||||
}
|
||||
RootConfig parsed = parse(loaded);
|
||||
validateReload(parsed);
|
||||
config = loaded;
|
||||
if (startupConfig == null) {
|
||||
startupConfig = parsed;
|
||||
}
|
||||
ACTIVE_CONFIG.setOpaque(this, parsed);
|
||||
}
|
||||
|
||||
public SetConfigResult setConfigValue(String path, String rawValue) {
|
||||
ConfigurationNode candidate = loadConfigNode();
|
||||
ConfigurationNode target = node(candidate, path);
|
||||
if (target.virtual()) {
|
||||
return SetConfigResult.invalid("Unknown config path: " + path);
|
||||
}
|
||||
|
||||
ConfigReader.setRaw(target, ConfigReader.parseRawValue(rawValue));
|
||||
|
||||
return applyCandidate(candidate, false);
|
||||
}
|
||||
|
||||
public SetConfigResult addConfigListValue(String path, String rawValue) {
|
||||
return mutateConfigListValue(path, rawValue, ListMutation.ADD);
|
||||
}
|
||||
|
||||
public SetConfigResult removeConfigListValue(String path, String rawValue) {
|
||||
return mutateConfigListValue(path, rawValue, ListMutation.REMOVE);
|
||||
}
|
||||
|
||||
private SetConfigResult mutateConfigListValue(String path, String rawValue, ListMutation mutation) {
|
||||
ConfigurationNode candidate = loadConfigNode();
|
||||
ConfigurationNode target = node(candidate, path);
|
||||
if (target.virtual()) {
|
||||
return SetConfigResult.invalid("Unknown config path: " + path);
|
||||
}
|
||||
if (!target.childrenMap().isEmpty()) {
|
||||
return SetConfigResult.invalid(path + " is not a list path");
|
||||
}
|
||||
|
||||
List<Object> values = new ArrayList<>(target.childrenList().stream().map(ConfigurationNode::raw).toList());
|
||||
if (values.isEmpty() && target.raw() != null && !(target.raw() instanceof List<?>)) {
|
||||
return SetConfigResult.invalid(path + " is not a list path");
|
||||
}
|
||||
|
||||
Object parsedValue = ConfigReader.parseRawValue(rawValue);
|
||||
boolean changed = switch (mutation) {
|
||||
case ADD -> {
|
||||
if (values.contains(parsedValue)) {
|
||||
yield false;
|
||||
}
|
||||
values.add(parsedValue);
|
||||
yield true;
|
||||
}
|
||||
case REMOVE -> values.remove(parsedValue);
|
||||
};
|
||||
|
||||
if (!changed) {
|
||||
return SetConfigResult.invalid("No change made for " + path);
|
||||
}
|
||||
|
||||
ConfigReader.setRaw(target, values);
|
||||
return applyCandidate(candidate, true);
|
||||
}
|
||||
|
||||
private SetConfigResult applyCandidate(ConfigurationNode candidate, boolean allowRestartRequired) {
|
||||
RootConfig parsed;
|
||||
try {
|
||||
parsed = parse(candidate);
|
||||
validateReload(parsed);
|
||||
} catch (RestartRequiredException e) {
|
||||
if (!allowRestartRequired) {
|
||||
return SetConfigResult.invalid(e.getMessage());
|
||||
}
|
||||
config = candidate;
|
||||
saveConfigNode(candidate);
|
||||
return SetConfigResult.restartRequired(e.getMessage());
|
||||
} catch (ConfigLoadException e) {
|
||||
return SetConfigResult.invalid(e.getMessage());
|
||||
}
|
||||
|
||||
config = candidate;
|
||||
ACTIVE_CONFIG.setOpaque(this, parsed);
|
||||
saveConfigNode(candidate);
|
||||
return SetConfigResult.ok();
|
||||
}
|
||||
|
||||
public PlayerConfig getPlayerConfig() {
|
||||
return activeConfig().checksConfig().playerConfig();
|
||||
}
|
||||
|
||||
public EntityConfig getEntityConfig() {
|
||||
return activeConfig().checksConfig().entityConfig();
|
||||
}
|
||||
|
||||
public TileEntityConfig getTileEntityConfig() {
|
||||
return activeConfig().checksConfig().tileEntityConfig();
|
||||
}
|
||||
|
||||
public SoundEffectsConfig getSoundEffectsConfig() {
|
||||
return activeConfig().checksConfig().soundEffectsConfig();
|
||||
}
|
||||
|
||||
public ChunkSectionConfig getChunkSectionConfig() {
|
||||
return activeConfig().checksConfig().chunkSectionConfig();
|
||||
}
|
||||
|
||||
public DebugConfig getDebugConfig() {
|
||||
RootConfig current = activeConfig();
|
||||
return current == null ? null : current.debugConfig();
|
||||
}
|
||||
|
||||
public UpdateConfig getUpdateConfig() {
|
||||
return activeConfig().updateConfig();
|
||||
}
|
||||
|
||||
public EngineConfig getEngineConfig() {
|
||||
return activeConfig().engineConfig();
|
||||
}
|
||||
|
||||
public BlockProcessorConfig getBlockProcessorConfig() {
|
||||
return activeConfig().blockProcessorConfig();
|
||||
}
|
||||
|
||||
public <T extends Config> T getExtensionConfig(Class<T> type) {
|
||||
return activeConfig().extensionConfig(type);
|
||||
}
|
||||
|
||||
private RootConfig activeConfig() {
|
||||
return (RootConfig) ACTIVE_CONFIG.getOpaque(this);
|
||||
}
|
||||
|
||||
public ConfigurationNode getConfigFile() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Map<String, Object> getConfigValues() {
|
||||
Map<String, Object> values = new LinkedHashMap<>();
|
||||
collectConfigValues(config, "", values);
|
||||
return values;
|
||||
}
|
||||
|
||||
private RootConfig parse(ConfigurationNode loaded) {
|
||||
String version = ConfigReader.string(ConfigReader.node(loaded, "config-version"), "config-version");
|
||||
if (!REQUIRED_CONFIG_VERSION.equals(version)) {
|
||||
throw new ConfigLoadException("Unsupported config-version '" + version + "'. RaycastedAntiESP requires config-version '2.0'.");
|
||||
}
|
||||
|
||||
ChecksConfig checksConfig = ChecksConfig.load(loaded);
|
||||
EngineConfig engineConfig = EngineConfig.load(loaded);
|
||||
BlockProcessorConfig blockProcessorConfig = BlockProcessorConfig.load(loaded);
|
||||
DebugConfig debugConfig = DebugConfig.load(loaded);
|
||||
UpdateConfig updateConfig = UpdateConfig.load(loaded);
|
||||
Map<Class<? extends Config>, Config> extensionConfigs = new LinkedHashMap<>();
|
||||
for (ConfigExtension<? extends Config> extension : extensions) {
|
||||
extensionConfigs.put(extension.type(), extension.load(loaded, blockProcessorConfig));
|
||||
}
|
||||
|
||||
if (!blockProcessorConfig.trackAllBlocks() && checksConfig.chunkSectionConfig().enabled()) {
|
||||
throw new ConfigLoadException("checks.chunk-section.enabled must be false when block-processor.track-all-blocks is false");
|
||||
}
|
||||
|
||||
return new RootConfig(version, checksConfig, engineConfig, blockProcessorConfig, debugConfig, updateConfig, Map.copyOf(extensionConfigs));
|
||||
}
|
||||
|
||||
private void validateReload(RootConfig next) {
|
||||
if (startupConfig == null) {
|
||||
return;
|
||||
}
|
||||
if (next.engineConfig().mode() != startupConfig.engineConfig().mode()) {
|
||||
throw new RestartRequiredException("engine.mode cannot be changed without a restart.");
|
||||
}
|
||||
if (!next.blockProcessorConfig().equals(startupConfig.blockProcessorConfig())) {
|
||||
throw new RestartRequiredException("block-processor cannot be changed without a restart.");
|
||||
}
|
||||
if (!next.checksConfig().entityConfig().excludedTypes().equals(startupConfig.checksConfig().entityConfig().excludedTypes())) {
|
||||
throw new RestartRequiredException("excluded entity types cannot be changed without a restart.");
|
||||
}
|
||||
if (next.checksConfig().hasEnabledStatusChanges(startupConfig.checksConfig())) {
|
||||
throw new RestartRequiredException("player and entity checks cannot be enabled or disabled without a restart.");
|
||||
}
|
||||
for (ConfigExtension<? extends Config> extension : extensions) {
|
||||
validateExtensionReload(extension, next);
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Config> void validateExtensionReload(ConfigExtension<T> extension, RootConfig next) {
|
||||
T startupExtensionConfig = startupConfig.extensionConfig(extension.type());
|
||||
T nextExtensionConfig = next.extensionConfig(extension.type());
|
||||
if (extension.requiresRestart(startupExtensionConfig, nextExtensionConfig)) {
|
||||
throw new RestartRequiredException("block-processor." + extension.type().getSimpleName() + " cannot be changed without a restart");
|
||||
}
|
||||
}
|
||||
|
||||
private void collectConfigValues(ConfigurationNode node, String path, Map<String, Object> values) {
|
||||
if (node.childrenMap().isEmpty() && node.childrenList().isEmpty()) {
|
||||
if (!path.isEmpty() && !node.virtual()) {
|
||||
values.put(path, node.raw());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node.childrenList().isEmpty()) {
|
||||
values.put(path, node.childrenList().stream().map(ConfigurationNode::raw).toList());
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> entry : node.childrenMap().entrySet()) {
|
||||
String key = String.valueOf(entry.getKey());
|
||||
String nextPath = path.isEmpty() ? key : path + "." + key;
|
||||
collectConfigValues(entry.getValue(), nextPath, values);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureConfigFileExists() {
|
||||
try {
|
||||
Files.createDirectories(dataFolder);
|
||||
if (!Files.exists(configPath)) {
|
||||
InputStream resource = resourceSupplier.get();
|
||||
if (resource != null) {
|
||||
try (resource) {
|
||||
Files.copy(resource, configPath);
|
||||
}
|
||||
} else {
|
||||
Files.createFile(configPath);
|
||||
}
|
||||
}
|
||||
ConfigMigrations.prependConfigDocumentationHeaderIfMissing(configPath);
|
||||
ConfigMigrations.migrateSoundEffectsEnabled(configPath);
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to create config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode loadConfigNode() {
|
||||
try {
|
||||
return loader.load();
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to load config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode loadBundledDefaults() {
|
||||
InputStream resource = resourceSupplier.get();
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
try (resource) {
|
||||
return YamlConfigurationLoader.builder()
|
||||
.source(() -> new BufferedReader(new InputStreamReader(resource)))
|
||||
.build()
|
||||
.load();
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to load bundled config defaults", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mergeMissing(ConfigurationNode defaults, ConfigurationNode target) {
|
||||
if (target.virtual()) {
|
||||
target.from(defaults);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
if (!defaults.childrenMap().isEmpty()) {
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> entry : defaults.childrenMap().entrySet()) {
|
||||
changed |= mergeMissing(entry.getValue(), target.node(entry.getKey()));
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void saveConfigNode(ConfigurationNode node) {
|
||||
try {
|
||||
loader.save(node);
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to save config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary text-level config mutations. Remove this class when these migrations are no longer needed.
|
||||
*/
|
||||
private static final class ConfigMigrations {
|
||||
private static final Pattern YAML_KEY = Pattern.compile("^([ \\t]*)([^:#\\s][^:]*):.*$");
|
||||
private static final Pattern SOUND_EFFECTS_ENABLED_TRUE = Pattern.compile("^([ \\t]*enabled[ \\t]*:[ \\t]*)true([ \\t]*(?:#.*)?)$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private ConfigMigrations() {
|
||||
}
|
||||
|
||||
private static void prependConfigDocumentationHeaderIfMissing(Path configPath) {
|
||||
try {
|
||||
String content = Files.readString(configPath);
|
||||
|
||||
if (content.startsWith("#")) {
|
||||
Logger.debug("Config starts with comment");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.debug("no starting comment");
|
||||
Files.writeString(configPath, "# An explanation of this configuration file and what all the options do can be found at https://raycastedantiesp.cubi.games/config/" + System.lineSeparator() + content);
|
||||
} catch (Exception e) {
|
||||
Logger.warning(e,3, ConfigManager.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Temporary(forRemovalIn = "0.8.0")
|
||||
private static void migrateSoundEffectsEnabled(Path configPath) {
|
||||
try {
|
||||
String content = Files.readString(configPath, StandardCharsets.UTF_8);
|
||||
String migrated = replaceSoundEffectsEnabled(content);
|
||||
if (!content.equals(migrated)) {
|
||||
Files.writeString(configPath, migrated, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to migrate sound-effects.enabled in config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String replaceSoundEffectsEnabled(String content) {
|
||||
StringBuilder migrated = new StringBuilder(content.length());
|
||||
int lineStart = 0;
|
||||
int checksIndent = -1;
|
||||
int soundEffectsIndent = -1;
|
||||
boolean changed = false;
|
||||
|
||||
while (lineStart < content.length()) {
|
||||
int lineEnd = content.indexOf('\n', lineStart);
|
||||
boolean hasLineEnding = lineEnd >= 0;
|
||||
int contentEnd = hasLineEnding ? lineEnd : content.length();
|
||||
int lineContentEnd = contentEnd > lineStart && content.charAt(contentEnd - 1) == '\r'
|
||||
? contentEnd - 1 : contentEnd;
|
||||
String line = content.substring(lineStart, lineContentEnd);
|
||||
String lineEnding = content.substring(lineContentEnd, contentEnd) + (hasLineEnding ? "\n" : "");
|
||||
|
||||
Matcher key = YAML_KEY.matcher(line);
|
||||
if (key.matches()) {
|
||||
int indent = key.group(1).length();
|
||||
String name = key.group(2).trim();
|
||||
|
||||
if (checksIndent < 0) {
|
||||
if (name.equals("checks")) {
|
||||
checksIndent = indent;
|
||||
}
|
||||
} else if (indent <= checksIndent) {
|
||||
checksIndent = name.equals("checks") ? indent : -1;
|
||||
soundEffectsIndent = -1;
|
||||
} else if (soundEffectsIndent < 0) {
|
||||
if (name.equals("sound-effects")) {
|
||||
soundEffectsIndent = indent;
|
||||
}
|
||||
} else if (indent <= soundEffectsIndent) {
|
||||
soundEffectsIndent = name.equals("sound-effects") ? indent : -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (soundEffectsIndent >= 0 && key.matches()
|
||||
&& key.group(2).trim().equals("enabled")
|
||||
&& key.group(1).length() > soundEffectsIndent) {
|
||||
Matcher enabled = SOUND_EFFECTS_ENABLED_TRUE.matcher(line);
|
||||
if (enabled.matches()) {
|
||||
line = enabled.group(1) + "false" + enabled.group(2);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
migrated.append(line).append(lineEnding);
|
||||
if (!hasLineEnding) {
|
||||
break;
|
||||
}
|
||||
lineStart = contentEnd + 1;
|
||||
}
|
||||
|
||||
return changed ? migrated.toString() : content;
|
||||
}
|
||||
|
||||
@Documented
|
||||
private @interface Temporary {
|
||||
String forRemovalIn();
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode node(ConfigurationNode root, String path) {
|
||||
String[] parts = path.split("\\.");
|
||||
return ConfigReader.node(root, parts);
|
||||
}
|
||||
|
||||
private enum ListMutation {
|
||||
ADD,
|
||||
REMOVE
|
||||
}
|
||||
|
||||
private static final class RestartRequiredException extends ConfigLoadException {
|
||||
private RestartRequiredException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public record SetConfigResult(boolean success, boolean restartRequired, String message) {
|
||||
public static SetConfigResult ok() {
|
||||
return new SetConfigResult(true, false, "Config value updated.");
|
||||
}
|
||||
|
||||
public static SetConfigResult restartRequired(String message) {
|
||||
return new SetConfigResult(true, true, message);
|
||||
}
|
||||
|
||||
public static SetConfigResult invalid(String message) {
|
||||
return new SetConfigResult(false, false, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ConfigReader {
|
||||
private ConfigReader() {}
|
||||
|
||||
public static ConfigurationNode node(ConfigurationNode parent, String... path) {
|
||||
return parent.node((Object[]) path);
|
||||
}
|
||||
|
||||
public static String string(ConfigurationNode node, String path) {
|
||||
Object raw = node.raw();
|
||||
if (raw instanceof String value) {
|
||||
return value;
|
||||
}
|
||||
throw invalid(path, "string", raw);
|
||||
}
|
||||
|
||||
public static int integer(ConfigurationNode node, String path) {
|
||||
Object raw = node.raw();
|
||||
if (raw instanceof Number value) {
|
||||
return exactInteger(value, path, "integer");
|
||||
}
|
||||
throw invalid(path, "integer", raw);
|
||||
}
|
||||
|
||||
public static boolean bool(ConfigurationNode node, String path) {
|
||||
Object raw = node.raw();
|
||||
if (raw instanceof Boolean value) {
|
||||
return value;
|
||||
}
|
||||
throw invalid(path, "boolean", raw);
|
||||
}
|
||||
|
||||
public static List<String> stringList(ConfigurationNode node, String path) {
|
||||
if (node.virtual() || node.raw() == null) {
|
||||
return List.of();
|
||||
}
|
||||
if (node.childrenList().isEmpty()) {
|
||||
Object raw = node.raw();
|
||||
if (raw instanceof List<?> list && list.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
throw invalid(path, "list of strings", raw);
|
||||
}
|
||||
List<String> values = new ArrayList<>();
|
||||
for (ConfigurationNode child : node.childrenList()) {
|
||||
Object raw = child.raw();
|
||||
if (!(raw instanceof String value)) {
|
||||
throw invalid(path, "list of strings", raw);
|
||||
}
|
||||
values.add(value);
|
||||
}
|
||||
return List.copyOf(values);
|
||||
}
|
||||
|
||||
public static List<Integer> integerList(ConfigurationNode node, String path) {
|
||||
if (node.virtual() || node.raw() == null) {
|
||||
return List.of();
|
||||
}
|
||||
if (node.childrenList().isEmpty()) {
|
||||
Object raw = node.raw();
|
||||
if (raw instanceof List<?> list && list.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
throw invalid(path, "list of integers", raw);
|
||||
}
|
||||
List<Integer> values = new ArrayList<>();
|
||||
for (ConfigurationNode child : node.childrenList()) {
|
||||
Object raw = child.raw();
|
||||
if (!(raw instanceof Number value)) {
|
||||
throw invalid(path, "list of integers", raw);
|
||||
}
|
||||
int id = exactInteger(value, path, "list of integers");
|
||||
if (id < 0) {
|
||||
throw new ConfigLoadException(path + " cannot contain negative block state IDs: " + id);
|
||||
}
|
||||
values.add(id);
|
||||
}
|
||||
return List.copyOf(values);
|
||||
}
|
||||
|
||||
public static Object parseRawValue(String rawValue) {
|
||||
try {
|
||||
ConfigurationNode parsed = org.spongepowered.configurate.yaml.YamlConfigurationLoader.builder()
|
||||
.source(() -> new java.io.BufferedReader(new java.io.StringReader("value: " + rawValue)))
|
||||
.build()
|
||||
.load();
|
||||
return parsed.node("value").raw();
|
||||
} catch (java.io.IOException e) {
|
||||
throw new ConfigLoadException("Invalid YAML value: " + rawValue, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setRaw(ConfigurationNode node, Object value) {
|
||||
try {
|
||||
node.set(value);
|
||||
} catch (SerializationException e) {
|
||||
throw new ConfigLoadException("Failed to set config value", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static ConfigLoadException invalid(String path, String expected, Object raw) {
|
||||
String actual = raw == null ? "null" : raw.getClass().getSimpleName();
|
||||
return new ConfigLoadException(path + " must be a " + expected + " but was " + actual);
|
||||
}
|
||||
|
||||
private static int exactInteger(Number value, String path, String expected) {
|
||||
try {
|
||||
return switch (value) {
|
||||
case Byte ignored -> value.intValue();
|
||||
case Short ignored -> value.intValue();
|
||||
case Integer ignored -> value.intValue();
|
||||
case Long longValue -> {
|
||||
if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) {
|
||||
throw invalid(path, expected, value);
|
||||
}
|
||||
yield longValue.intValue();
|
||||
}
|
||||
case BigInteger bigInteger -> bigInteger.intValueExact();
|
||||
case BigDecimal bigDecimal -> bigDecimal.intValueExact();
|
||||
default -> exactIntegerFromFloatingPoint(value, path, expected);
|
||||
};
|
||||
} catch (ArithmeticException e) {
|
||||
throw invalid(path, expected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static int exactIntegerFromFloatingPoint(Number value, String path, String expected) {
|
||||
double doubleValue = value.doubleValue();
|
||||
if (!Double.isFinite(doubleValue)
|
||||
|| Math.rint(doubleValue) != doubleValue
|
||||
|| doubleValue < Integer.MIN_VALUE
|
||||
|| doubleValue > Integer.MAX_VALUE) {
|
||||
throw invalid(path, expected, value);
|
||||
}
|
||||
return (int) doubleValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record DebugConfig(byte infoLevel, List<String> infoExemptedClasses, byte warnLevel, List<String> warnExemptedClasses,
|
||||
byte errorLevel, List<String> errorExemptedClasses, boolean debugParticles, boolean timings) implements Config {
|
||||
|
||||
public static DebugConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "debug");
|
||||
return new DebugConfig(
|
||||
level(ConfigReader.node(node, "info-level"), "debug.info-level"),
|
||||
ConfigReader.stringList(ConfigReader.node(node, "info-exempted-classes"), "debug.info-exempted-classes"),
|
||||
level(ConfigReader.node(node, "warn-level"), "debug.warn-level"),
|
||||
ConfigReader.stringList(ConfigReader.node(node, "warn-exempted-classes"), "debug.warn-exempted-classes"),
|
||||
level(ConfigReader.node(node, "error-level"), "debug.error-level"),
|
||||
ConfigReader.stringList(ConfigReader.node(node, "error-exempted-classes"), "debug.error-exempted-classes"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "particles"), "debug.particles"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "timings"), "debug.timings")
|
||||
);
|
||||
}
|
||||
|
||||
public byte getInfoLevel() {
|
||||
return infoLevel;
|
||||
}
|
||||
|
||||
public byte getWarnLevel() {
|
||||
return warnLevel;
|
||||
}
|
||||
|
||||
public byte getErrorLevel() {
|
||||
return errorLevel;
|
||||
}
|
||||
|
||||
public boolean showDebugParticles() {
|
||||
return debugParticles;
|
||||
}
|
||||
|
||||
public boolean recordTimings() {
|
||||
return timings;
|
||||
}
|
||||
|
||||
public boolean isExempted(Severity severity, Class<?>... sources) {
|
||||
List<String> exempted = switch (severity) {
|
||||
case INFO -> infoExemptedClasses;
|
||||
case WARN -> warnExemptedClasses;
|
||||
case ERROR -> errorExemptedClasses;
|
||||
};
|
||||
if (sources == null || exempted.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (Class<?> source : sources) {
|
||||
if (source == null) {
|
||||
continue;
|
||||
}
|
||||
if (exempted.contains(source.getSimpleName()) || exempted.contains(source.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static byte level(ConfigurationNode node, String path) {
|
||||
int level = ConfigReader.integer(node, path);
|
||||
if (level < 0 || level > 10) {
|
||||
throw new ConfigLoadException(path + " must be between 0 and 10");
|
||||
}
|
||||
return (byte) level;
|
||||
}
|
||||
|
||||
public enum Severity {
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.engine.EngineConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public record RootConfig(String configVersion, ChecksConfig checksConfig, EngineConfig engineConfig, BlockProcessorConfig blockProcessorConfig, DebugConfig debugConfig, UpdateConfig updateConfig, Map<Class<? extends Config>, Config> extensionConfigs) implements Config {
|
||||
public <T extends Config> T extensionConfig(Class<T> type) {
|
||||
Config config = extensionConfigs.get(type);
|
||||
return type.cast(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record UpdateConfig(boolean checkRelease, boolean checkBeta, boolean checkAlpha, boolean notifyInGame) implements Config {
|
||||
|
||||
public static UpdateConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "updates");
|
||||
return new UpdateConfig(
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-release"), "updates.check-release"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-beta"), "updates.check-beta"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-alpha"), "updates.check-alpha"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "notify-in-game"), "updates.notify-in-game")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean anyChannelEnabled() {
|
||||
return checkRelease || checkBeta || checkAlpha;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigLoadException;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record AsyncEngineConfig(int asyncProcessingThreads) implements Config {
|
||||
public static AsyncEngineConfig load(ConfigurationNode node) {
|
||||
int threads = ConfigReader.integer(ConfigReader.node(node, "processing-threads"), "engine.async.processing-threads");
|
||||
if (threads < 1) {
|
||||
throw new ConfigLoadException("engine.async.processing-threads must be at least 1");
|
||||
}
|
||||
return new AsyncEngineConfig(threads);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigLoadException;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record EngineConfig(EngineMode mode, AsyncEngineConfig asyncConfig) implements Config {
|
||||
public static EngineConfig load(ConfigurationNode root) {
|
||||
ConfigurationNode node = ConfigReader.node(root, "engine");
|
||||
String modeName = ConfigReader.string(ConfigReader.node(node, "mode"), "engine.mode");
|
||||
EngineMode mode = EngineMode.fromString(modeName);
|
||||
if (mode == null) {
|
||||
throw new ConfigLoadException("engine.mode has unsupported value '" + modeName + "'");
|
||||
}
|
||||
return new EngineConfig(mode, AsyncEngineConfig.load(ConfigReader.node(node, "async")));
|
||||
}
|
||||
|
||||
public EngineMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigEnum;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum EngineMode implements ConfigEnum {
|
||||
ASYNC("async", "simple"),
|
||||
NETTY("netty");
|
||||
|
||||
private final String configName;
|
||||
private final @Nullable String aliasName;
|
||||
|
||||
EngineMode(String configName) {
|
||||
this.configName = configName;
|
||||
aliasName = null;
|
||||
}
|
||||
|
||||
EngineMode(String configName, @NotNull String aliasName) {
|
||||
this.configName = configName;
|
||||
this.aliasName = aliasName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return configName;
|
||||
}
|
||||
|
||||
public static @Nullable EngineMode fromString(String name) {
|
||||
for (EngineMode mode : values()) {
|
||||
if (mode.configName.equalsIgnoreCase(name) || name.equalsIgnoreCase(mode.aliasName)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValues() {
|
||||
return new String[] {NETTY.configName, ASYNC.configName};
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record ChunkSectionConfig(boolean enabled, int maxOccludingCount, int alwaysShowRadiusChunks, int visibleRecheckIntervalTicks) implements Config {
|
||||
public static ChunkSectionConfig load(ConfigurationNode node, String path) {
|
||||
return new ChunkSectionConfig(
|
||||
ConfigReader.bool(ConfigReader.node(node, "enabled"), path + ".enabled"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "max-occluding-count"), path + ".max-occluding-count"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "always-show-radius-chunks"), path + ".always-show-radius-chunks"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "visible-recheck-interval-ticks"), path + ".visible-recheck-interval-ticks")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EntityConfig extends RaycastConfig {
|
||||
private final Set<String> excludedTypes;
|
||||
|
||||
private EntityConfig(RaycastConfig config, List<String> excludedTypes) {
|
||||
super(config.enabled(), config.hideSoundsWhenHidden(), config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks(),
|
||||
config.keepClientEntityWhenHidden());
|
||||
this.excludedTypes = Set.copyOf(excludedTypes);
|
||||
}
|
||||
|
||||
public static EntityConfig load(ConfigurationNode node, String path) {
|
||||
RaycastConfig config = RaycastConfig.load(node, path, true, true);
|
||||
List<String> excludedTypes = ConfigReader.stringList(ConfigReader.node(node, "excluded-types"), path + ".excluded-types");
|
||||
return new EntityConfig(config, excludedTypes);
|
||||
}
|
||||
|
||||
public Set<String> excludedTypes() {
|
||||
return excludedTypes;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSets;
|
||||
|
||||
/**
|
||||
* Immutable entity-type exclusion policy resolved during plugin startup.
|
||||
*/
|
||||
public final class EntityTypeExclusions {
|
||||
public static volatile IntSet volatileExclusionSet = null;
|
||||
|
||||
// Is this sort of an insane approach? Yes. But it works.
|
||||
static class FakeLazyConstant {
|
||||
private static final IntSet finalEntityTypeExclusions = init();
|
||||
|
||||
private static IntSet init() {
|
||||
IntSet set = volatileExclusionSet;
|
||||
if (set == null) {
|
||||
Logger.error(new RuntimeException("Exclusion set was not initialised before being read"), 4, EntityTypeExclusions.class);
|
||||
return IntSets.emptySet();
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean excludes(int entityType) {
|
||||
return FakeLazyConstant.finalEntityTypeExclusions.contains(entityType);
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return FakeLazyConstant.finalEntityTypeExclusions.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class PlayerConfig extends RaycastConfig {
|
||||
private final boolean onlyCheckSneaking;
|
||||
|
||||
private PlayerConfig(RaycastConfig config, boolean onlyCheckSneaking) {
|
||||
super(config.enabled(), config.hideSoundsWhenHidden(), config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks(),
|
||||
config.keepClientEntityWhenHidden());
|
||||
this.onlyCheckSneaking = onlyCheckSneaking;
|
||||
}
|
||||
|
||||
public static PlayerConfig load(ConfigurationNode node, String path) {
|
||||
return new PlayerConfig(
|
||||
RaycastConfig.load(node, path, true, true),
|
||||
ConfigReader.bool(ConfigReader.node(node, "only-check-sneaking"), path + ".only-check-sneaking")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean onlyCheckSneaking() {
|
||||
return onlyCheckSneaking;
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class RaycastConfig implements Config {
|
||||
private final boolean enabled;
|
||||
private final boolean hideSoundsWhenHidden;
|
||||
private final byte maxOccludingCount;
|
||||
private final short alwaysShowRadius;
|
||||
private final short raycastRadius;
|
||||
private final short hideOnSpawnDistance;
|
||||
private final short visibleRecheckIntervalTicks;
|
||||
private final boolean keepClientEntityWhenHidden;
|
||||
|
||||
public RaycastConfig(boolean enabled, boolean hideSoundsWhenHidden, int maxOccludingCount, int alwaysShowRadius,
|
||||
int raycastRadius, int hideOnSpawnDistance, int visibleRecheckIntervalTicks) {
|
||||
this(enabled, hideSoundsWhenHidden, maxOccludingCount, alwaysShowRadius, raycastRadius, hideOnSpawnDistance,
|
||||
visibleRecheckIntervalTicks, false);
|
||||
}
|
||||
|
||||
public RaycastConfig(boolean enabled, boolean hideSoundsWhenHidden, int maxOccludingCount, int alwaysShowRadius,
|
||||
int raycastRadius, int hideOnSpawnDistance, int visibleRecheckIntervalTicks,
|
||||
boolean keepClientEntityWhenHidden) {
|
||||
this.enabled = enabled;
|
||||
this.hideSoundsWhenHidden = hideSoundsWhenHidden;
|
||||
this.maxOccludingCount = (byte) maxOccludingCount;
|
||||
this.alwaysShowRadius = (short) alwaysShowRadius;
|
||||
this.raycastRadius = (short) raycastRadius;
|
||||
this.hideOnSpawnDistance = (short) hideOnSpawnDistance;
|
||||
this.visibleRecheckIntervalTicks = (short) visibleRecheckIntervalTicks;
|
||||
this.keepClientEntityWhenHidden = keepClientEntityWhenHidden;
|
||||
}
|
||||
|
||||
protected static RaycastConfig load(ConfigurationNode node, String path, boolean hasHideSoundsWhenHidden) {
|
||||
return load(node, path, hasHideSoundsWhenHidden, false);
|
||||
}
|
||||
|
||||
protected static RaycastConfig load(ConfigurationNode node, String path, boolean hasHideSoundsWhenHidden,
|
||||
boolean hasKeepClientEntityWhenHidden) {
|
||||
int maxOccludingCount = ConfigReader.integer(ConfigReader.node(node, "max-occluding-count"), path + ".max-occluding-count");
|
||||
if (maxOccludingCount < 0 || maxOccludingCount > Byte.MAX_VALUE) {
|
||||
Logger.warning(path + ".max-occluding-count must be between 0 and " + Byte.MAX_VALUE + " but was " + maxOccludingCount +". Defaulting to 3.", 4, RaycastConfig.class);
|
||||
maxOccludingCount = 3;
|
||||
}
|
||||
int alwaysShowRadius = ConfigReader.integer(ConfigReader.node(node, "always-show-radius"), path + ".always-show-radius");
|
||||
if (alwaysShowRadius < 0 || alwaysShowRadius > Short.MAX_VALUE) {
|
||||
Logger.warning(path + ".always-show-radius must be between 0 and " + Short.MAX_VALUE + " but was " + alwaysShowRadius +". Defaulting to 8.", 4, RaycastConfig.class);
|
||||
alwaysShowRadius = 8;
|
||||
}
|
||||
int raycastRadius = ConfigReader.integer(ConfigReader.node(node, "raycast-radius"), path + ".raycast-radius");
|
||||
if (raycastRadius < 0 || raycastRadius > Short.MAX_VALUE) {
|
||||
Logger.warning(path + ".raycast-radius must be between 0 and " + Short.MAX_VALUE + " but was " + raycastRadius +". Defaulting to 48.", 4, RaycastConfig.class);
|
||||
raycastRadius = 48;
|
||||
}
|
||||
int hideOnSpawnDistance = ConfigReader.integer(ConfigReader.node(node, "hide-on-spawn-distance"), path + ".hide-on-spawn-distance");
|
||||
if (hideOnSpawnDistance < 0 || hideOnSpawnDistance > Short.MAX_VALUE) {
|
||||
Logger.warning(path + ".hide-on-spawn-distance must be between 0 and " + Short.MAX_VALUE + " but was " + hideOnSpawnDistance +". Defaulting to 32.", 4, RaycastConfig.class);
|
||||
hideOnSpawnDistance = 32;
|
||||
}
|
||||
int visibleRecheckIntervalTicks = ConfigReader.integer(ConfigReader.node(node, "visible-recheck-interval-ticks"), path + ".visible-recheck-interval-ticks");
|
||||
if (visibleRecheckIntervalTicks < -1 || visibleRecheckIntervalTicks > Short.MAX_VALUE) {
|
||||
Logger.warning(path + ".visible-recheck-interval-ticks must be between -1 and " + Short.MAX_VALUE + " but was " + visibleRecheckIntervalTicks +". Defaulting to 5.", 4, RaycastConfig.class);
|
||||
visibleRecheckIntervalTicks = 5;
|
||||
}
|
||||
return new RaycastConfig(
|
||||
ConfigReader.bool(ConfigReader.node(node, "enabled"), path + ".enabled"),
|
||||
hasHideSoundsWhenHidden && ConfigReader.bool(ConfigReader.node(node, "hide-sounds-when-hidden"), path + ".hide-sounds-when-hidden"),
|
||||
maxOccludingCount,
|
||||
alwaysShowRadius,
|
||||
raycastRadius,
|
||||
hideOnSpawnDistance,
|
||||
visibleRecheckIntervalTicks,
|
||||
hasKeepClientEntityWhenHidden && ConfigReader.bool(ConfigReader.node(node, "keep-client-entity-when-hidden"), path + ".keep-client-entity-when-hidden")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public boolean hideSoundsWhenHidden() {
|
||||
return hideSoundsWhenHidden;
|
||||
}
|
||||
|
||||
public byte getMaxOccludingCount() {
|
||||
return maxOccludingCount;
|
||||
}
|
||||
|
||||
public short getAlwaysShowRadius() {
|
||||
return alwaysShowRadius;
|
||||
}
|
||||
|
||||
public short getRaycastRadius() {
|
||||
return raycastRadius;
|
||||
}
|
||||
|
||||
public short hideOnSpawnDistance() {
|
||||
return hideOnSpawnDistance;
|
||||
}
|
||||
|
||||
public short getVisibleRecheckIntervalTicks() {
|
||||
return visibleRecheckIntervalTicks;
|
||||
}
|
||||
|
||||
public boolean keepClientEntityWhenHidden() {
|
||||
return keepClientEntityWhenHidden;
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public record SoundEffectsConfig(
|
||||
boolean enabled,
|
||||
int maxOccludingCount,
|
||||
int alwaysPlayRadius,
|
||||
int raycastRadius
|
||||
) implements Config {
|
||||
public static SoundEffectsConfig load(ConfigurationNode node, String path) {
|
||||
return new SoundEffectsConfig(
|
||||
ConfigReader.bool(ConfigReader.node(node, "enabled"), path + ".enabled"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "max-occluding-count"), path + ".max-occluding-count"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "always-play-radius"), path + ".always-play-radius"),
|
||||
ConfigReader.integer(ConfigReader.node(node, "raycast-radius"), path + ".raycast-radius")
|
||||
);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class TileEntityConfig extends RaycastConfig {
|
||||
private TileEntityConfig(RaycastConfig config) {
|
||||
super(config.enabled(), false, config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks());
|
||||
}
|
||||
|
||||
public static TileEntityConfig load(ConfigurationNode node, String path) {
|
||||
return new TileEntityConfig(RaycastConfig.load(node, path, false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigManager;
|
||||
import games.cubi.raycastedantiesp.core.config.DebugConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.TileEntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.entity.EntityBypassRegistry;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerRegistry;
|
||||
import games.cubi.raycastedantiesp.core.raycast.ParticleSpawner;
|
||||
import games.cubi.raycastedantiesp.core.raycast.RaycastUtil;
|
||||
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
|
||||
import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
import games.cubi.raycastedantiesp.core.view.EntityView;
|
||||
import games.cubi.utils.events.CancellableEvent;
|
||||
import games.cubi.utils.events.CancellableEventRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public abstract class AsyncEngine implements Engine {
|
||||
private static final long SLOW_TICK_NANOS = 40 * 1_000_000L;
|
||||
//Literally just magic numbers I made by keyboard mashing
|
||||
private static final int TICK_IDLE = 1872;
|
||||
private static final int TICK_PENDING = -129;
|
||||
private static final int TICK_RUNNING = 34892;
|
||||
|
||||
private final ConfigManager config;
|
||||
private final ParticleSpawner particleSpawner;
|
||||
private final IntSupplier currentTickSupplier;
|
||||
private final AtomicInteger tickThreadsRunning = new AtomicInteger(0);
|
||||
private final AtomicInteger runningTick = new AtomicInteger(-1);
|
||||
private final AtomicInteger tickState = new AtomicInteger(TICK_IDLE);
|
||||
private final AtomicLong tickNanos = new AtomicLong(0);
|
||||
private final AsyncRunner asyncRunner;
|
||||
private final TimingStatsSelector timingStatsSelector = new TimingStatsSelector();
|
||||
|
||||
public AsyncEngine(ConfigManager config, ParticleSpawner particleSpawner, IntSupplier currentTickSupplier, AsyncRunner asyncRunner) {
|
||||
this.config = config;
|
||||
this.particleSpawner = particleSpawner;
|
||||
this.currentTickSupplier = currentTickSupplier;
|
||||
this.asyncRunner = asyncRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserves the next engine tick before it is handed to the async scheduler.
|
||||
*
|
||||
* @return true if the caller now owns the only pending tick slot; false if an existing pending
|
||||
* or running tick should cover this attempt.
|
||||
*/
|
||||
public boolean markTickRunning() {
|
||||
if (tickState.compareAndSet(TICK_IDLE, TICK_PENDING)) {
|
||||
return true;
|
||||
}
|
||||
recordSkippedTick(-1, System.nanoTime());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a pending tick reservation when async scheduling fails before {@link #tick(int, long)}
|
||||
* can claim it.
|
||||
*/
|
||||
public void cancelPendingTickReservation() {
|
||||
if (!tickState.compareAndSet(TICK_PENDING, TICK_IDLE)) {
|
||||
Logger.warning("Attempted to cancel a pending tick reservation, but the tick was no longer pending.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the tick which was reserved using {@link #markTickRunning} and, if the engine falls behind the server clock, keeps the
|
||||
* same worker on the latest tick instead of yielding back to the scheduler.
|
||||
*
|
||||
* @param scheduledTick the server tick captured before async handoff.
|
||||
* @param scheduledNanos the time captured before async handoff, used to separate queue delay from engine work.
|
||||
*/
|
||||
@Override
|
||||
public void tick(int scheduledTick, long scheduledNanos) {
|
||||
boolean runTick = true;
|
||||
boolean expectPending = true;
|
||||
int startTick = currentTickSupplier.getAsInt();
|
||||
while (runTick) {
|
||||
if (!startTickState(scheduledTick, expectPending)) {
|
||||
return;
|
||||
}
|
||||
if (!dispatchTick(scheduledTick, startTick, scheduledNanos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int latestTick = currentTickSupplier.getAsInt();
|
||||
if (latestTick > startTick) {
|
||||
// If running behind, don't yield the thread, just run the next tick immediately
|
||||
Logger.warning("Tick thread completed tick #" + startTick + " after tick #" + latestTick + " had already begun. Starting next tick immediately instead of yielding thread to scheduler. This is probably safe to ignore but may suggest that your server is overloaded.", 5);
|
||||
startTick = latestTick;
|
||||
scheduledNanos = System.nanoTime();
|
||||
scheduledTick = latestTick;
|
||||
|
||||
if (tickState.get() == TICK_RUNNING) {
|
||||
// This means that there is already a tick running, so we should exit
|
||||
Logger.info("Tick finished behind but another thread had already begun ticking the next tick.", 5, AsyncEngine.class);
|
||||
return;
|
||||
}
|
||||
expectPending = false; //Next call to startTickState should not expect to see status set to pending
|
||||
}
|
||||
else runTick = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EngineTickEvent extends CancellableEvent {}
|
||||
|
||||
public final CancellableEventRegistry<EngineTickEvent> engineTickEventRegistry = new CancellableEventRegistry<>();
|
||||
/**
|
||||
* Claims worker capacity and either runs work immediately or schedules worker batches.
|
||||
*
|
||||
* @return true if at least one sub-tick worker accepted responsibility for completing the tick
|
||||
* lifecycle; false if this attempt was skipped or cleaned up during setup.
|
||||
*/
|
||||
private boolean dispatchTick(int scheduledTick, int startTick, long scheduledNanos) {
|
||||
if (!engineTickEventRegistry.dispatch(EngineTickEvent::new)) {
|
||||
Logger.debug("Skipping tick due to event being cancelled");
|
||||
finishTickState();
|
||||
return false;
|
||||
}
|
||||
int threads = config.getEngineConfig().asyncConfig().asyncProcessingThreads();
|
||||
if (threads < 1) threads = 1;
|
||||
|
||||
DebugConfig debugConfig = config.getDebugConfig();
|
||||
TimingStats tickTimingStats = timingStats(debugConfig);
|
||||
boolean recordTimings = tickTimingStats != TimingStatsNoOp.INSTANCE;
|
||||
|
||||
long startNanos = System.nanoTime();
|
||||
|
||||
int tickAlreadyRunning = runningTick.get();
|
||||
// First guard for the current tick already being processed (can happen if the previous tick ran overtime and thus didn't yield the thread)
|
||||
if (scheduledTick == tickAlreadyRunning) {
|
||||
logAggregateReport(tickTimingStats.recordSkipped(threads, startNanos));
|
||||
Logger.info("RaycastedAntiESP is already processing this tick; skipping duplicate same-tick attempt."
|
||||
+ " scheduledTick=" + scheduledTick
|
||||
+ " currentServerTick=" + startTick
|
||||
+ " currentRunningTick=" + tickAlreadyRunning, 6, AsyncEngine.class);
|
||||
finishTickState();
|
||||
return false;
|
||||
}
|
||||
|
||||
int runningThreads = tickThreadsRunning.compareAndExchange(0, threads);
|
||||
// Now guard for previous tick still running
|
||||
if (runningThreads != 0) {
|
||||
long queueNanos = Math.max(0, startNanos - scheduledNanos);
|
||||
Logger.warning("RaycastedAntiESP is still ticking from the last tick! Skipping this tick to avoid concurrent modification issues."
|
||||
+ " scheduledTick=" + scheduledTick
|
||||
+ " currentServerTick=" + currentTickSupplier.getAsInt()
|
||||
+ " currentRunningTick=" + tickAlreadyRunning
|
||||
+ " runningThreads=" + runningThreads
|
||||
+ " timeSpentInQueue=" + TickTimingFormatter.formatMillis(queueNanos) + "ms", 5, AsyncEngine.class);
|
||||
logAggregateReport(tickTimingStats.recordSkipped(threads, startNanos));
|
||||
finishTickState();
|
||||
return false;
|
||||
}
|
||||
|
||||
TickTimings timings = null;
|
||||
boolean handedOffToSubTick = false;
|
||||
boolean claimedRunningTick = false;
|
||||
try {
|
||||
tickNanos.set(startNanos);
|
||||
|
||||
final int currentTick = startTick;
|
||||
runningTick.set(currentTick);
|
||||
claimedRunningTick = true;
|
||||
Collection<PlayerData> allPlayers = PlayerRegistry.getInstance().getAllPlayerData();
|
||||
|
||||
EntityConfig entityConfig = config.getEntityConfig();
|
||||
PlayerConfig playerConfig = config.getPlayerConfig();
|
||||
TileEntityConfig tileEntityConfig = config.getTileEntityConfig();
|
||||
if (recordTimings) {
|
||||
timings = new TickTimings(scheduledTick, scheduledNanos, currentTick, startNanos, threads, allPlayers.size());
|
||||
}
|
||||
/*
|
||||
Logger.debug("Tick #" + currentTick);
|
||||
if (currentTick % 1200 == 0) {
|
||||
Logger.debug("Printing player data");
|
||||
for (PlayerData playerData : allPlayers) {
|
||||
Logger.debug("Player " + playerData.getPlayerUUID() + " location=" + playerData.ownLocation());
|
||||
Logger.debug("EntityView:" + playerData.entityView().getStringDataForDebugging());
|
||||
Logger.debug("PlayerView:" + playerData.playerView().getStringDataForDebugging());
|
||||
}
|
||||
}*/
|
||||
|
||||
// If only one thread is configured, just use the current async thread to avoid the overhead of scheduling tasks and context switching.
|
||||
if (threads == 1) {
|
||||
handedOffToSubTick = true;
|
||||
subTick(new ArrayList<>(allPlayers), entityConfig, playerConfig, tileEntityConfig, debugConfig, currentTick, timings, tickTimingStats);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<List<PlayerData>> batches = new ArrayList<>(threads);
|
||||
for (int i = 0; i < threads; i++) {
|
||||
batches.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (PlayerData playerData : allPlayers) {
|
||||
batches.get(index++ % threads).add(playerData);
|
||||
}
|
||||
|
||||
TickTimings tickTimings = timings; // needs to be effectively-final for lambda
|
||||
int scheduledBatches = 0;
|
||||
try {
|
||||
for (List<PlayerData> batch : batches) {
|
||||
asyncRunner.runNow(() -> subTick(batch, entityConfig, playerConfig, tileEntityConfig, debugConfig, currentTick, tickTimings, tickTimingStats));
|
||||
scheduledBatches++;
|
||||
}
|
||||
handedOffToSubTick = true;
|
||||
}
|
||||
finally {
|
||||
if (scheduledBatches < threads) {
|
||||
tickThreadsRunning.addAndGet(-(threads - scheduledBatches));
|
||||
handedOffToSubTick = scheduledBatches > 0;
|
||||
}
|
||||
}
|
||||
return handedOffToSubTick;
|
||||
}
|
||||
finally {
|
||||
if (!handedOffToSubTick) {
|
||||
tickThreadsRunning.set(0);
|
||||
if (claimedRunningTick) {
|
||||
finaliseTick(startTick);
|
||||
} else {
|
||||
finishTickState();
|
||||
}
|
||||
Logger.error("An error occurred during tick scheduling before handing off to sub-tick processing. Resetting tickThreadsRunning to 0 to avoid deadlock. Current tick: " + currentTickSupplier.getAsInt(), 2, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes one worker batch and lets the final batch publish timing data and release the tick reservation.
|
||||
*
|
||||
* @param timingStats the timing sink selected when this tick started, so config changes during
|
||||
* worker execution do not split one tick across sinks.
|
||||
*/
|
||||
private void subTick(List<PlayerData> batch, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig, DebugConfig debugConfig, int currentTick, TickTimings timings, TimingStats timingStats) {
|
||||
TickTimingBatch batchTimings = timings == null ? TickTimingBatchNoOp.INSTANCE : new TickTimingBatch();
|
||||
long batchStartNanos = batchTimings.startBatch();
|
||||
try {
|
||||
processTickForPlayers(batch, entityConfig, playerConfig, tileEntityConfig, debugConfig.showDebugParticles(), currentTick, batchTimings);
|
||||
}
|
||||
finally {
|
||||
if (timings != null) {
|
||||
timings.recordBatch(batchTimings, batchTimings.elapsedSince(batchStartNanos));
|
||||
}
|
||||
int threadsRemaining = tickThreadsRunning.decrementAndGet();
|
||||
if (threadsRemaining < 0) {
|
||||
Logger.error("tickThreadsRunning went below 0! This should never happen. Resetting to 0 to avoid further issues.", 2, AsyncEngine.class);
|
||||
tickThreadsRunning.set(0);
|
||||
finaliseTick(currentTick);
|
||||
}
|
||||
if (threadsRemaining == 0) {
|
||||
try {
|
||||
long completionNanos = System.nanoTime();
|
||||
if (timings != null) {
|
||||
TickTimingSnapshot snapshot = timings.snapshot(currentTickSupplier.getAsInt(), completionNanos);
|
||||
String aggregateReport = timingStats.recordCompleted(snapshot, completionNanos);
|
||||
if (snapshot.wallNanos() > SLOW_TICK_NANOS) {
|
||||
Logger.warning(snapshot.toSlowTickMessage(), 5, AsyncEngine.class);
|
||||
}
|
||||
logAggregateReport(aggregateReport);
|
||||
} else {
|
||||
long elapsedNanos = completionNanos - tickNanos.get();
|
||||
if (elapsedNanos > SLOW_TICK_NANOS) {
|
||||
Logger.warning("Tick completed in " + (elapsedNanos / 1_000_000.0) + " ms. If you see this warning frequently, consider reducing the raycasting load by adjusting the configuration.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
finaliseTick(currentTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the reserved tick into the running state. Catch-up iterations may start from idle
|
||||
* because they are created by the current worker instead of by the server tick event.
|
||||
*
|
||||
* @return true if this thread now owns the running state; false if another pending or running
|
||||
* tick should take precedence.
|
||||
*/
|
||||
private boolean startTickState(int scheduledTick, boolean expectPending) {
|
||||
if (expectPending) {
|
||||
if (tickState.compareAndSet(TICK_PENDING, TICK_RUNNING)) {
|
||||
return true;
|
||||
}
|
||||
if (tickState.compareAndSet(TICK_IDLE, TICK_RUNNING)) {
|
||||
// This means that this tick was dispatched but not marked as such, or was unmarked at some point.
|
||||
Logger.warning("Tick " + scheduledTick + " was dispatched but not marked as pending. This suggests a race condition. Please report this on our GitHub or Discord.", 5, AsyncEngine.class);
|
||||
return true;
|
||||
}
|
||||
} else if (tickState.compareAndSet(TICK_IDLE, TICK_RUNNING)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// This means there is already a tick pending or running, so we should exit.
|
||||
recordSkippedTick(-1, System.nanoTime());
|
||||
Logger.info("Tick " + scheduledTick + " is pending but another tick is already pending or running. Exiting now.", 6, AsyncEngine.class);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases ownership for the tick that completed, without clearing a newer running tick that
|
||||
* may have already taken over.
|
||||
*/
|
||||
private void finaliseTick(int currentTick) {
|
||||
runningTick.compareAndSet(currentTick, -1);
|
||||
finishTickState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reservation state to idle after the active tick has stopped touching shared player visibility data.
|
||||
*/
|
||||
private void finishTickState() {
|
||||
if (!tickState.compareAndSet(TICK_RUNNING, TICK_IDLE)) {
|
||||
// This should never happen as it means the tick was marked as completed before processing was completed
|
||||
Logger.warning("tickState was not running when completing tick! This should never happen. Please report this on our GitHub or Discord.", 5, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processTickForPlayers(List<PlayerData> playerDataList, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig,
|
||||
boolean debugParticles, int currentTick, TickTimingBatch timings) {
|
||||
|
||||
for (PlayerData playerData : playerDataList) {
|
||||
if (!playerData.isConnected()) {
|
||||
continue;
|
||||
}
|
||||
playerData.nettyData().markPendingPostSpawnTasksForEviction();
|
||||
if (playerData.hasBypassPermission()) {
|
||||
timings.incrementBypassSkippedPlayers();
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockView blockView = playerData.blockView();
|
||||
|
||||
Locatable playerLocation = playerData.ownLocation();
|
||||
if (playerLocation == null || playerLocation.world() == null) {
|
||||
timings.incrementNullLocationSkippedPlayers();
|
||||
continue;
|
||||
}
|
||||
int worldEpoch = playerData.tryAcquireWorldEpochFor(playerLocation.world());
|
||||
if (worldEpoch == PlayerData.INVALID_WORLD_EPOCH) {
|
||||
if (tileEntityConfig.enabled()) timings.incrementTileWorldSkipped();
|
||||
continue;
|
||||
}
|
||||
timings.incrementProcessedPlayers();
|
||||
|
||||
try {
|
||||
if (entityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startEntitySection();
|
||||
checkEntities(playerData, playerLocation, entityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishEntitySection(sectionStartNanos);
|
||||
}
|
||||
if (playerConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startPlayerSection();
|
||||
checkPlayers(playerData, playerLocation, playerConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishPlayerSection(sectionStartNanos);
|
||||
}
|
||||
if (tileEntityConfig.enabled()) {
|
||||
long sectionStartNanos = timings.startTileSection();
|
||||
checkTileEntities(playerData, playerLocation, tileEntityConfig, debugParticles, blockView, currentTick, worldEpoch, timings);
|
||||
timings.finishTileSection(sectionStartNanos);
|
||||
}
|
||||
} finally {
|
||||
playerData.entityView().flushPendingTransitions();
|
||||
playerData.playerView().flushPendingTransitions();
|
||||
blockView.flushPendingTransitions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntities(PlayerData player, Locatable playerLocation, EntityConfig entityConfig, boolean debugParticles, BlockView blockView, int currentTick, int worldEpoch, TickTimingBatch timings) {
|
||||
EntityView<?> entityView = player.entityView();
|
||||
|
||||
int checked = entityView.forEachNeedingRecheckEntity(entityConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, entity -> {
|
||||
if (entity.glowing()) {
|
||||
entityView.setVisibility(entity, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, entityView, entity, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timings.incrementEntityRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, entity, entityConfig.getMaxOccludingCount(), entityConfig.getAlwaysShowRadius(), entityConfig.getRaycastRadius(), debugParticles, blockView, entity.getYOffset(), 1, particleSpawner);
|
||||
entityView.setVisibility(entity, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addEntityChecked(checked);
|
||||
}
|
||||
|
||||
private void checkPlayers(PlayerData player, Locatable playerLocation, PlayerConfig playerConfig, boolean debugParticles, BlockView blockView, int currentTick, int worldEpoch, TickTimingBatch timings) {
|
||||
EntityView<?> playerView = player.playerView();
|
||||
|
||||
int checked = playerView.forEachNeedingRecheckEntity(playerConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, otherPlayer -> {
|
||||
if (otherPlayer.glowing() || (playerConfig.onlyCheckSneaking() && !otherPlayer.sneaking())) {
|
||||
playerView.setVisibility(otherPlayer, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, playerView, otherPlayer, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
timings.incrementPlayerRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, otherPlayer, playerConfig.getMaxOccludingCount(), playerConfig.getAlwaysShowRadius(), playerConfig.getRaycastRadius(), debugParticles, blockView, 1.5f, 1, particleSpawner);
|
||||
playerView.setVisibility(otherPlayer, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addPlayerChecked(checked);
|
||||
}
|
||||
|
||||
private boolean attachedToAlwaysVisibleEntityOrSelf(PlayerData player, EntityView<?> view, NettyEntity<?> entity, int currentTick, int worldEpoch) {
|
||||
int selfEntityID = player.nettyData().getSelfEntityID();
|
||||
if (!player.nettyData().isSelfEntityID(entity.leashingEntity())
|
||||
&& !player.nettyData().isSelfEntityID(entity.vehicleID())
|
||||
&& !EntityBypassRegistry.isBypassed(entity.vehicleID())
|
||||
&& !PrimitiveIntArrayList.contains(entity.passengerIDs(), selfEntityID)) {
|
||||
return false;
|
||||
}
|
||||
view.setVisibility(entity, true, currentTick, worldEpoch);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void checkTileEntities(PlayerData player, Locatable playerLocation, TileEntityConfig tileEntityConfig, boolean debugParticles, BlockView blockView, int currentTick, int worldEpoch, TickTimingBatch timings) {
|
||||
long modeToken = blockView.tileEntityCheckModeToken();
|
||||
int checked = blockView.updateVisibilityForEachNeedingRecheck(tileEntityConfig.getVisibleRecheckIntervalTicks(), currentTick, modeToken, worldEpoch, tileEntityLocation -> {
|
||||
|
||||
if (playerLocation.distanceSquared(tileEntityLocation) > (double) tileEntityConfig.getRaycastRadius() * tileEntityConfig.getRaycastRadius()) {
|
||||
timings.incrementTileRadiusSkipped();
|
||||
return BlockView.VisibilityResolver.HIDE;
|
||||
}
|
||||
timings.incrementTileRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, tileEntityLocation, tileEntityConfig.getMaxOccludingCount() + 1, tileEntityConfig.getAlwaysShowRadius(), tileEntityConfig.getRaycastRadius(), debugParticles, blockView, 1, particleSpawner);
|
||||
return canSee ? BlockView.VisibilityResolver.SHOW : BlockView.VisibilityResolver.HIDE;
|
||||
});
|
||||
timings.addTileChecked(checked);
|
||||
}
|
||||
|
||||
private static void logAggregateReport(String aggregateReport) {
|
||||
if (aggregateReport != null) {
|
||||
Logger.info(aggregateReport, 4, AsyncEngine.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts a skipped tick against the currently configured timing sink.
|
||||
*/
|
||||
private void recordSkippedTick(int threads, long nowNanos) {
|
||||
logAggregateReport(timingStats().recordSkipped(threads, nowNanos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the timing sink from the current debug config.
|
||||
*
|
||||
* @return a collecting {@link TimingStats} while timing diagnostics are enabled, otherwise the
|
||||
* no-op singleton.
|
||||
*/
|
||||
private TimingStats timingStats() {
|
||||
return timingStats(config.getDebugConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps disabled timing diagnostics allocation-free and starts a fresh collection window when
|
||||
* diagnostics are re-enabled.
|
||||
*
|
||||
* @return the timing sink that should be used for a newly starting tick or skip record.
|
||||
*/
|
||||
private TimingStats timingStats(DebugConfig debugConfig) {
|
||||
return timingStatsSelector.select(debugConfig.recordTimings());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface AsyncRunner {
|
||||
void runNow(Runnable task);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface Engine {
|
||||
void tick(int scheduledTick, long scheduledNanos);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatch {
|
||||
long entityNanos;
|
||||
long playerNanos;
|
||||
long tileNanos;
|
||||
|
||||
int processedPlayers;
|
||||
int bypassSkippedPlayers;
|
||||
int nullLocationSkippedPlayers;
|
||||
|
||||
int entityChecked;
|
||||
int entityRaycasts;
|
||||
int entityNullTargets;
|
||||
|
||||
int playerChecked;
|
||||
int playerRaycasts;
|
||||
int playerNullTargets;
|
||||
|
||||
int tileChecked;
|
||||
int tileRaycasts;
|
||||
int tileWorldSkipped;
|
||||
int tileRadiusSkipped;
|
||||
|
||||
TickTimingBatch() {}
|
||||
|
||||
public long startBatch() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
public long elapsedSince(long startNanos) {
|
||||
return System.nanoTime() - startNanos;
|
||||
}
|
||||
|
||||
public long startEntitySection() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
public void finishEntitySection(long startNanos) {
|
||||
entityNanos += Math.max(0, System.nanoTime() - startNanos);
|
||||
}
|
||||
|
||||
public long startPlayerSection() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
public void finishPlayerSection(long startNanos) {
|
||||
playerNanos += Math.max(0, System.nanoTime() - startNanos);
|
||||
}
|
||||
|
||||
public long startTileSection() {
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
public void finishTileSection(long startNanos) {
|
||||
tileNanos += Math.max(0, System.nanoTime() - startNanos);
|
||||
}
|
||||
|
||||
public void incrementProcessedPlayers() {
|
||||
processedPlayers++;
|
||||
}
|
||||
|
||||
public void incrementBypassSkippedPlayers() {
|
||||
bypassSkippedPlayers++;
|
||||
}
|
||||
|
||||
public void incrementNullLocationSkippedPlayers() {
|
||||
nullLocationSkippedPlayers++;
|
||||
}
|
||||
|
||||
public void addEntityChecked(int count) {
|
||||
entityChecked += count;
|
||||
}
|
||||
|
||||
public void incrementEntityRaycasts() {
|
||||
entityRaycasts++;
|
||||
}
|
||||
|
||||
public void addPlayerChecked(int count) {
|
||||
playerChecked += count;
|
||||
}
|
||||
|
||||
public void incrementPlayerRaycasts() {
|
||||
playerRaycasts++;
|
||||
}
|
||||
|
||||
public void addTileChecked(int count) {
|
||||
tileChecked += count;
|
||||
}
|
||||
|
||||
public void incrementTileWorldSkipped() {
|
||||
tileWorldSkipped++;
|
||||
}
|
||||
|
||||
public void incrementTileRadiusSkipped() {
|
||||
tileRadiusSkipped++;
|
||||
}
|
||||
|
||||
public void incrementTileRaycasts() {
|
||||
tileRaycasts++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatchNoOp extends TickTimingBatch {
|
||||
public static final TickTimingBatchNoOp INSTANCE = new TickTimingBatchNoOp();
|
||||
public long startBatch() {return 0;}
|
||||
public long elapsedSince(long startNanos) {return 0;}
|
||||
public long startEntitySection() {return 0;}
|
||||
public void finishEntitySection(long startNanos) {}
|
||||
public long startPlayerSection() {return 0;}
|
||||
public void finishPlayerSection(long startNanos) {}
|
||||
public long startTileSection() {return 0;}
|
||||
public void finishTileSection(long startNanos) {}
|
||||
public void incrementProcessedPlayers() {}
|
||||
public void incrementBypassSkippedPlayers() {}
|
||||
public void incrementNullLocationSkippedPlayers() {}
|
||||
public void addEntityChecked(int count) {}
|
||||
public void incrementEntityNullTargets() {}
|
||||
public void incrementEntityRaycasts() {}
|
||||
public void addPlayerChecked(int count) {}
|
||||
public void incrementPlayerNullTargets() {}
|
||||
public void incrementPlayerRaycasts() {}
|
||||
public void addTileChecked(int count) {}
|
||||
public void incrementTileWorldSkipped() {}
|
||||
public void incrementTileRadiusSkipped() {}
|
||||
public void incrementTileRaycasts() {}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
final class TickTimingFormatter {
|
||||
private TickTimingFormatter() {}
|
||||
|
||||
static String formatMillis(long nanos) {
|
||||
return String.format(Locale.ROOT, "%.3f", nanos / 1_000_000.0);
|
||||
}
|
||||
|
||||
static String formatSeconds(long nanos) {
|
||||
return String.format(Locale.ROOT, "%.3f", nanos / 1_000_000_000.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
record TickTimingSnapshot(
|
||||
int scheduledTick,
|
||||
int startTick,
|
||||
int completionTick,
|
||||
int threads,
|
||||
int registeredPlayers,
|
||||
long queueNanos,
|
||||
long wallNanos,
|
||||
long maxBatchNanos,
|
||||
long entityNanos,
|
||||
long playerNanos,
|
||||
long tileNanos,
|
||||
int processedPlayers,
|
||||
int bypassSkippedPlayers,
|
||||
int nullLocationSkippedPlayers,
|
||||
int entityChecked,
|
||||
int entityRaycasts,
|
||||
int playerChecked,
|
||||
int playerRaycasts,
|
||||
int tileChecked,
|
||||
int tileRaycasts,
|
||||
int tileWorldSkipped,
|
||||
int tileRadiusSkipped
|
||||
) {
|
||||
String toSlowTickMessage() {
|
||||
return "Tick completed slowly."
|
||||
+ " scheduledTick=" + scheduledTick
|
||||
+ " startTick=" + startTick
|
||||
+ " completionTick=" + completionTick
|
||||
+ " threads=" + threads
|
||||
+ " wallTimeTaken=" + TickTimingFormatter.formatMillis(wallNanos) + "ms"
|
||||
+ " schedulerWait=" + TickTimingFormatter.formatMillis(queueNanos) + "ms"
|
||||
+ " slowestWorkerBatch=" + TickTimingFormatter.formatMillis(maxBatchNanos) + "ms"
|
||||
+ " entityProcessingTime=" + TickTimingFormatter.formatMillis(entityNanos) + "ms"
|
||||
+ " playerProcessingTime=" + TickTimingFormatter.formatMillis(playerNanos) + "ms"
|
||||
+ " tileProcessingTime=" + TickTimingFormatter.formatMillis(tileNanos) + "ms"
|
||||
+ " playerCount=" + registeredPlayers
|
||||
+ " processedPlayers=" + processedPlayers
|
||||
+ " bypassSkippedPlayers=" + bypassSkippedPlayers
|
||||
+ " nullLocationSkippedPlayers=" + nullLocationSkippedPlayers
|
||||
+ " entityRecheckCandidates=" + entityChecked
|
||||
+ " entityRaycasts=" + entityRaycasts
|
||||
+ " playerRecheckCandidates=" + playerChecked
|
||||
+ " playerRaycasts=" + playerRaycasts
|
||||
+ " tileRecheckCandidates=" + tileChecked
|
||||
+ " tileRaycasts=" + tileRaycasts
|
||||
+ " tileWorldSkipped=" + tileWorldSkipped
|
||||
+ " tileRadiusSkipped=" + tileRadiusSkipped;
|
||||
}
|
||||
|
||||
String toSlowestSummary() {
|
||||
return "scheduledTick=" + scheduledTick
|
||||
+ ", startedAtTick=" + startTick
|
||||
+ ", totalWallTime=" + TickTimingFormatter.formatMillis(wallNanos) + " ms"
|
||||
+ ", schedulerWait=" + TickTimingFormatter.formatMillis(queueNanos) + " ms"
|
||||
+ ", slowestWorkerBatch=" + TickTimingFormatter.formatMillis(maxBatchNanos) + " ms"
|
||||
+ ", processingTime(entity/player/tile)=" + TickTimingFormatter.formatMillis(entityNanos) + "/" + TickTimingFormatter.formatMillis(playerNanos) + "/" + TickTimingFormatter.formatMillis(tileNanos) + " ms"
|
||||
+ ", raycasts(entity/player/tile)=" + entityRaycasts + "/" + playerRaycasts + "/" + tileRaycasts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
final class TickTimings {
|
||||
private final int scheduledTick;
|
||||
private final long scheduledNanos;
|
||||
private final int startTick;
|
||||
private final long startNanos;
|
||||
private final int threads;
|
||||
private final int registeredPlayers;
|
||||
|
||||
private long maxBatchNanos;
|
||||
private long entityNanos;
|
||||
private long playerNanos;
|
||||
private long tileNanos;
|
||||
|
||||
private int processedPlayers;
|
||||
private int bypassSkippedPlayers;
|
||||
private int nullLocationSkippedPlayers;
|
||||
|
||||
private int entityChecked;
|
||||
private int entityRaycasts;
|
||||
|
||||
private int playerChecked;
|
||||
private int playerRaycasts;
|
||||
|
||||
private int tileChecked;
|
||||
private int tileRaycasts;
|
||||
private int tileWorldSkipped;
|
||||
private int tileRadiusSkipped;
|
||||
|
||||
TickTimings(int scheduledTick, long scheduledNanos, int startTick, long startNanos, int threads, int registeredPlayers) {
|
||||
this.scheduledTick = scheduledTick;
|
||||
this.scheduledNanos = scheduledNanos;
|
||||
this.startTick = startTick;
|
||||
this.startNanos = startNanos;
|
||||
this.threads = threads;
|
||||
this.registeredPlayers = registeredPlayers;
|
||||
}
|
||||
|
||||
synchronized void recordBatch(TickTimingBatch batch, long batchNanos) {
|
||||
// Batch-local primitive counters avoid atomic writes in the raycast loop, where the work being measured is sub-microsecond.
|
||||
maxBatchNanos = Math.max(maxBatchNanos, Math.max(0, batchNanos));
|
||||
entityNanos += batch.entityNanos;
|
||||
playerNanos += batch.playerNanos;
|
||||
tileNanos += batch.tileNanos;
|
||||
|
||||
processedPlayers += batch.processedPlayers;
|
||||
bypassSkippedPlayers += batch.bypassSkippedPlayers;
|
||||
nullLocationSkippedPlayers += batch.nullLocationSkippedPlayers;
|
||||
|
||||
entityChecked += batch.entityChecked;
|
||||
entityRaycasts += batch.entityRaycasts;
|
||||
|
||||
playerChecked += batch.playerChecked;
|
||||
playerRaycasts += batch.playerRaycasts;
|
||||
|
||||
tileChecked += batch.tileChecked;
|
||||
tileRaycasts += batch.tileRaycasts;
|
||||
tileWorldSkipped += batch.tileWorldSkipped;
|
||||
tileRadiusSkipped += batch.tileRadiusSkipped;
|
||||
}
|
||||
|
||||
synchronized TickTimingSnapshot snapshot(int completionTick, long completionNanos) {
|
||||
return new TickTimingSnapshot(
|
||||
scheduledTick,
|
||||
startTick,
|
||||
completionTick,
|
||||
threads,
|
||||
registeredPlayers,
|
||||
Math.max(0, startNanos - scheduledNanos),
|
||||
Math.max(0, completionNanos - scheduledNanos),
|
||||
maxBatchNanos,
|
||||
entityNanos,
|
||||
playerNanos,
|
||||
tileNanos,
|
||||
processedPlayers,
|
||||
bypassSkippedPlayers,
|
||||
nullLocationSkippedPlayers,
|
||||
entityChecked,
|
||||
entityRaycasts,
|
||||
playerChecked,
|
||||
playerRaycasts,
|
||||
tileChecked,
|
||||
tileRaycasts,
|
||||
tileWorldSkipped,
|
||||
tileRadiusSkipped
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.longs.LongComparators;
|
||||
import it.unimi.dsi.fastutil.longs.LongIterator;
|
||||
import it.unimi.dsi.fastutil.longs.LongList;
|
||||
|
||||
public class TimingStats {
|
||||
private static final long REPORT_INTERVAL_NANOS = 30_000_000_000L;
|
||||
|
||||
private final LongArrayList wallSamples = new LongArrayList();
|
||||
private final LongArrayList schedulerWaitSamples = new LongArrayList();
|
||||
private final LongArrayList slowestWorkerBatchSamples = new LongArrayList();
|
||||
private final LongArrayList entityWorkerSamples = new LongArrayList();
|
||||
private final LongArrayList playerWorkerSamples = new LongArrayList();
|
||||
private final LongArrayList tileWorkerSamples = new LongArrayList();
|
||||
|
||||
private long intervalStartNanos = 0;
|
||||
private long nextReportNanos = 0;
|
||||
private int completedTicks = 0;
|
||||
private int skippedTicks = 0;
|
||||
private int lastThreads = 0;
|
||||
|
||||
private long entityRaycastsTotal = 0;
|
||||
private long playerRaycastsTotal = 0;
|
||||
private long tileRaycastsTotal = 0;
|
||||
|
||||
private TickTimingSnapshot slowestTick = null;
|
||||
|
||||
/**
|
||||
* Drops the current reporting window so later samples do not mix with data collected under a previous timing configuration.
|
||||
*/
|
||||
synchronized void reset() {
|
||||
wallSamples.clear();
|
||||
schedulerWaitSamples.clear();
|
||||
slowestWorkerBatchSamples.clear();
|
||||
entityWorkerSamples.clear();
|
||||
playerWorkerSamples.clear();
|
||||
tileWorkerSamples.clear();
|
||||
intervalStartNanos = 0;
|
||||
nextReportNanos = 0;
|
||||
completedTicks = 0;
|
||||
skippedTicks = 0;
|
||||
lastThreads = 0;
|
||||
entityRaycastsTotal = 0;
|
||||
playerRaycastsTotal = 0;
|
||||
tileRaycastsTotal = 0;
|
||||
slowestTick = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a completed tick to the active reporting window.
|
||||
*
|
||||
* @return a formatted aggregate report when the reporting interval has elapsed; otherwise null.
|
||||
*/
|
||||
synchronized String recordCompleted(TickTimingSnapshot snapshot, long nowNanos) {
|
||||
ensureInterval(nowNanos);
|
||||
completedTicks++;
|
||||
lastThreads = snapshot.threads();
|
||||
wallSamples.add(snapshot.wallNanos());
|
||||
schedulerWaitSamples.add(snapshot.queueNanos());
|
||||
slowestWorkerBatchSamples.add(snapshot.maxBatchNanos());
|
||||
entityWorkerSamples.add(snapshot.entityNanos());
|
||||
playerWorkerSamples.add(snapshot.playerNanos());
|
||||
tileWorkerSamples.add(snapshot.tileNanos());
|
||||
|
||||
entityRaycastsTotal += snapshot.entityRaycasts();
|
||||
playerRaycastsTotal += snapshot.playerRaycasts();
|
||||
tileRaycastsTotal += snapshot.tileRaycasts();
|
||||
|
||||
if (slowestTick == null || snapshot.wallNanos() > slowestTick.wallNanos()) {
|
||||
slowestTick = snapshot;
|
||||
}
|
||||
return reportIfDue(nowNanos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a skipped tick attempt to the active reporting window without creating worker timing samples.
|
||||
*
|
||||
* @return a formatted aggregate report when the reporting interval has elapsed; otherwise null.
|
||||
*/
|
||||
synchronized String recordSkipped(int threads, long nowNanos) {
|
||||
ensureInterval(nowNanos);
|
||||
skippedTicks++;
|
||||
if (threads != -1) lastThreads = threads;
|
||||
return reportIfDue(nowNanos);
|
||||
}
|
||||
|
||||
private void ensureInterval(long nowNanos) {
|
||||
if (nextReportNanos == 0) {
|
||||
intervalStartNanos = nowNanos;
|
||||
nextReportNanos = nowNanos + REPORT_INTERVAL_NANOS;
|
||||
}
|
||||
}
|
||||
|
||||
private String reportIfDue(long nowNanos) {
|
||||
if (nextReportNanos == 0 || nowNanos < nextReportNanos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String report = buildReport(nowNanos);
|
||||
reset();
|
||||
intervalStartNanos = nowNanos;
|
||||
nextReportNanos = nowNanos + REPORT_INTERVAL_NANOS;
|
||||
return report;
|
||||
}
|
||||
|
||||
private String buildReport(long nowNanos) {
|
||||
long intervalNanos = Math.max(1, nowNanos - intervalStartNanos);
|
||||
String slowestSummary = slowestTick == null ? "n/a" : slowestTick.toSlowestSummary();
|
||||
return "Raycasted Anti-ESP tick timing summary for the last " + TickTimingFormatter.formatSeconds(intervalNanos) + "s:\n"
|
||||
+ "Completed Anti-ESP ticks: " + completedTicks + "\n"
|
||||
+ "Skipped tick attempts: " + skippedTicks + "\n"
|
||||
+ "Configured worker threads: " + lastThreads + "\n\n"
|
||||
+ "Total time from server tick event to Anti-ESP completion (avg / p50 / p95 / max): " + formatStats(wallSamples) + "\n"
|
||||
+ "Time spent waiting in the async scheduler before Anti-ESP work started (avg / p50 / p95 / max): " + formatStats(schedulerWaitSamples) + "\n"
|
||||
+ "Slowest worker batch processing time after work started (avg / p50 / p95 / max): " + formatStats(slowestWorkerBatchSamples) + "\n\n"
|
||||
+ "Worker section times are summed across worker batches for multi-threaded ticks, not wall-clock critical-path time.\n"
|
||||
+ "Worker time spent checking entities per completed tick (avg / p50 / p95 / max): " + formatStats(entityWorkerSamples) + "\n"
|
||||
+ "Worker time spent checking players per completed tick (avg / p50 / p95 / max): " + formatStats(playerWorkerSamples) + "\n"
|
||||
+ "Worker time spent checking tile entities per completed tick (avg / p50 / p95 / max): " + formatStats(tileWorkerSamples) + "\n\n"
|
||||
+ "Total raycasts performed, entity / player / tile: " + entityRaycastsTotal + " / " + playerRaycastsTotal + " / " + tileRaycastsTotal + "\n"
|
||||
+ "Slowest tick in this interval: " + slowestSummary;
|
||||
}
|
||||
|
||||
private String formatStats(LongList samples) {
|
||||
if (samples.isEmpty()) {
|
||||
return "n/a";
|
||||
}
|
||||
LongArrayList sorted = new LongArrayList(samples);
|
||||
sorted.sort(LongComparators.NATURAL_COMPARATOR);
|
||||
long total = 0;
|
||||
LongIterator iterator = sorted.longIterator();
|
||||
while (iterator.hasNext()) {
|
||||
total += iterator.nextLong();
|
||||
}
|
||||
int sampleCount = sorted.size();
|
||||
return TickTimingFormatter.formatMillis(total / sorted.size())
|
||||
+ " / " + TickTimingFormatter.formatMillis(percentile(sorted, 0.50))
|
||||
+ " / " + TickTimingFormatter.formatMillis(percentile(sorted, 0.95))
|
||||
+ " / " + TickTimingFormatter.formatMillis(sorted.getLong(sampleCount - 1))
|
||||
+ " ms";
|
||||
}
|
||||
|
||||
private long percentile(LongList sorted, double percentile) {
|
||||
int index = Math.min(sorted.size() - 1, Math.max(0, (int) Math.ceil(sorted.size() * percentile) - 1));
|
||||
return sorted.getLong(index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TimingStatsNoOp extends TimingStats {
|
||||
static final TimingStatsNoOp INSTANCE = new TimingStatsNoOp();
|
||||
|
||||
private TimingStatsNoOp() {}
|
||||
|
||||
@Override
|
||||
void reset() {}
|
||||
|
||||
@Override
|
||||
String recordCompleted(TickTimingSnapshot snapshot, long nowNanos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
String recordSkipped(int threads, long nowNanos) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/** Lock-free selection of the timing sink used by a newly starting tick or skip record. */
|
||||
final class TimingStatsSelector {
|
||||
private final AtomicReference<TimingStats> current = new AtomicReference<>(TimingStatsNoOp.INSTANCE);
|
||||
|
||||
TimingStats select(boolean enabled) {
|
||||
if (!enabled) {
|
||||
current.set(TimingStatsNoOp.INSTANCE);
|
||||
return TimingStatsNoOp.INSTANCE;
|
||||
}
|
||||
|
||||
TimingStats existing = current.get();
|
||||
if (existing != TimingStatsNoOp.INSTANCE) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
TimingStats created = new TimingStats();
|
||||
TimingStats witness = current.compareAndExchange(TimingStatsNoOp.INSTANCE, created);
|
||||
return witness == TimingStatsNoOp.INSTANCE ? created : witness;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.entity;
|
||||
|
||||
import games.cubi.utils.sets.CopyOnWriteMTIntSet;
|
||||
|
||||
/**
|
||||
* Global registry of entity IDs which RaycastedAntiESP must ignore.
|
||||
*/
|
||||
public final class EntityBypassRegistry {
|
||||
private static final CopyOnWriteMTIntSet BYPASSED_ENTITY_IDS = CopyOnWriteMTIntSet.get();
|
||||
// Technically, (26.2+) Minecraft only guarantees that an entity ID corresponds to one-and-only-one entity within a single world, and entities in different worlds can have the same ID.
|
||||
// (26.1.2-) Minecraft does not guarantee that an entity ID is unique.
|
||||
// However, this requires the int id counter to overflow from Integer.MAX_VALUE all the way back to 0. This is unlikely to occur, and even if it does occur, it is unlikely that the original entities are still alive.
|
||||
private EntityBypassRegistry() {
|
||||
}
|
||||
|
||||
public static void addEntity(int entityID) {
|
||||
BYPASSED_ENTITY_IDS.add(entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* For use when an entity is despawned/killed, or in other words completely gone from the server.
|
||||
*/
|
||||
public static boolean markEntityDespawned(int entityID) {
|
||||
return BYPASSED_ENTITY_IDS.remove(entityID);
|
||||
}
|
||||
|
||||
public static boolean isBypassed(int entityID) {
|
||||
return BYPASSED_ENTITY_IDS.contains(entityID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.*;
|
||||
import games.cubi.raycastedantiesp.core.utils.Packet.Packets;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_LEASHER;
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_VEHICLE;
|
||||
|
||||
/**
|
||||
* Per-player mutable state intended for Netty-side packet tracking and deferred reconciliation.
|
||||
*/
|
||||
public class NettyData implements Clearable {
|
||||
private static final int DEFAULT_MAP_SIZE = 16;
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START Leash tracking:
|
||||
//
|
||||
private final Int2ObjectArrayMap<int[]> unresolvedLeashedEntityIDsByHolderID = new Int2ObjectArrayMap<>(DEFAULT_MAP_SIZE);
|
||||
private final Int2IntArrayMap unresolvedHolderIDsByLeashedEntityID = new Int2IntArrayMap(DEFAULT_MAP_SIZE);
|
||||
|
||||
public void addUnresolvedLeash(int holderEntityID, int leashedEntityID) {
|
||||
int previousHolderEntityID = unresolvedHolderIDsByLeashedEntityID.put(leashedEntityID, holderEntityID);
|
||||
if (previousHolderEntityID != NO_LEASHER && previousHolderEntityID != holderEntityID) {
|
||||
removeLeashedEntityFromUnresolvedHolder(previousHolderEntityID, leashedEntityID);
|
||||
}
|
||||
unresolvedLeashedEntityIDsByHolderID.compute(holderEntityID, (ignored, existing) -> {
|
||||
if (PrimitiveIntArrayList.contains(existing, leashedEntityID)) {
|
||||
return existing;
|
||||
}
|
||||
return PrimitiveIntArrayList.add(existing, leashedEntityID);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean removeUnresolvedLeash(int holderEntityID, int leashedEntityID) {
|
||||
if (unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID) != holderEntityID) {
|
||||
return false;
|
||||
}
|
||||
unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
removeLeashedEntityFromUnresolvedHolder(holderEntityID, leashedEntityID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getUnresolvedHolderForLeashedEntity(int leashedEntityID) {
|
||||
return unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID);
|
||||
}
|
||||
|
||||
public int[] getUnresolvedLeashes(int holderEntityID) {
|
||||
return PrimitiveIntArrayList.getCopyOrNull(unresolvedLeashedEntityIDsByHolderID.get(holderEntityID));
|
||||
}
|
||||
|
||||
public int[] consumeUnresolvedLeashes(int holderEntityID) {
|
||||
int[] existing = unresolvedLeashedEntityIDsByHolderID.remove(holderEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(existing)) {
|
||||
return existing;
|
||||
}
|
||||
for (int leashedEntityID : existing) {
|
||||
if (unresolvedHolderIDsByLeashedEntityID.get(leashedEntityID) == holderEntityID) {
|
||||
unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
}
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
public int consumeUnresolvedHolderForLeashedEntity(int leashedEntityID) {
|
||||
int holderEntityID = unresolvedHolderIDsByLeashedEntityID.remove(leashedEntityID);
|
||||
if (holderEntityID == NO_LEASHER) {
|
||||
return NO_LEASHER;
|
||||
}
|
||||
removeLeashedEntityFromUnresolvedHolder(holderEntityID, leashedEntityID);
|
||||
return holderEntityID;
|
||||
}
|
||||
|
||||
private void removeLeashedEntityFromUnresolvedHolder(int holderEntityID, int leashedEntityID) {
|
||||
unresolvedLeashedEntityIDsByHolderID.computeIfPresent(holderEntityID, (ignored, existing) -> {
|
||||
int[] updated = PrimitiveIntArrayList.remove(existing, leashedEntityID);
|
||||
return PrimitiveIntArrayList.isEmpty(updated) ? null : updated;
|
||||
});
|
||||
}
|
||||
//
|
||||
// END Leash tracking.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START Passenger tracking:
|
||||
//
|
||||
/**
|
||||
* Latest full passenger list for a vehicle that is not represented by a tracked entity.
|
||||
* Normally this is temporary reconciliation state while a vehicle or passenger is waiting to spawn.
|
||||
* Bypassed vehicles remain untracked, so their authoritative passenger list stays here until it is
|
||||
* replaced by another passenger packet or cleared by the vehicle's destroy packet.
|
||||
*/
|
||||
private final Int2ObjectArrayMap<int[]> unresolvedPassengerIDsByVehicleID = new Int2ObjectArrayMap<>(DEFAULT_MAP_SIZE);
|
||||
/**
|
||||
* Reverse lookup for passenger relationships stored above.
|
||||
* Lets a later passenger spawn discover which untracked vehicle most recently claimed it as a passenger.
|
||||
* This may grow larger than {@link #unresolvedPassengerIDsByVehicleID} if vehicles have several passengers, so it's an open hash map.
|
||||
*/
|
||||
private final Int2IntOpenHashMap unresolvedVehicleIDsByPassengerID = new Int2IntOpenHashMap(DEFAULT_MAP_SIZE);
|
||||
|
||||
{
|
||||
unresolvedHolderIDsByLeashedEntityID.defaultReturnValue(NO_LEASHER);
|
||||
unresolvedVehicleIDsByPassengerID.defaultReturnValue(NO_VEHICLE);
|
||||
}
|
||||
|
||||
public int[] getUnresolvedPassengers(int vehicleEntityID) {
|
||||
return PrimitiveIntArrayList.getCopyOrNull(unresolvedPassengerIDsByVehicleID.get(vehicleEntityID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any previous unresolved passenger state for this vehicle.
|
||||
* The passenger packet is authoritative, so the latest packet wins.
|
||||
*/
|
||||
public void setUnresolvedPassengers(int vehicleEntityID, int[] passengerIDs) {
|
||||
consumeUnresolvedPassengers(vehicleEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(passengerIDs)) {
|
||||
return;
|
||||
}
|
||||
int[] copiedPassengerIDs = passengerIDs.clone();
|
||||
unresolvedPassengerIDsByVehicleID.put(vehicleEntityID, copiedPassengerIDs);
|
||||
for (int passengerID : copiedPassengerIDs) {
|
||||
int previousVehicleID = unresolvedVehicleIDsByPassengerID.put(passengerID, vehicleEntityID);
|
||||
if (previousVehicleID != NO_VEHICLE && previousVehicleID != vehicleEntityID) {
|
||||
removePassengerFromUnresolvedVehicle(previousVehicleID, passengerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int[] consumeUnresolvedPassengers(int vehicleEntityID) {
|
||||
int[] existing = unresolvedPassengerIDsByVehicleID.remove(vehicleEntityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(existing)) {
|
||||
return existing;
|
||||
}
|
||||
for (int passengerID : existing) {
|
||||
if (unresolvedVehicleIDsByPassengerID.get(passengerID) == vehicleEntityID) {
|
||||
unresolvedVehicleIDsByPassengerID.remove(passengerID);
|
||||
}
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
public int getUnresolvedVehicleForPassenger(int passengerEntityID) {
|
||||
return unresolvedVehicleIDsByPassengerID.get(passengerEntityID);
|
||||
}
|
||||
|
||||
public boolean removeUnresolvedPassengerLink(int passengerEntityID, int vehicleEntityID) {
|
||||
if (unresolvedVehicleIDsByPassengerID.get(passengerEntityID) != vehicleEntityID) {
|
||||
return false;
|
||||
}
|
||||
unresolvedVehicleIDsByPassengerID.remove(passengerEntityID);
|
||||
removePassengerFromUnresolvedVehicle(vehicleEntityID, passengerEntityID);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int consumeUnresolvedVehicleForPassenger(int passengerEntityID) {
|
||||
int vehicleEntityID = unresolvedVehicleIDsByPassengerID.remove(passengerEntityID);
|
||||
if (vehicleEntityID == NO_VEHICLE) {
|
||||
return NO_VEHICLE;
|
||||
}
|
||||
removePassengerFromUnresolvedVehicle(vehicleEntityID, passengerEntityID);
|
||||
return vehicleEntityID;
|
||||
}
|
||||
|
||||
private void removePassengerFromUnresolvedVehicle(int vehicleEntityID, int passengerEntityID) {
|
||||
unresolvedPassengerIDsByVehicleID.computeIfPresent(vehicleEntityID, (ignored, existing) -> {
|
||||
if (!PrimitiveIntArrayList.contains(existing, passengerEntityID)) {
|
||||
return existing;
|
||||
}
|
||||
int[] updated = PrimitiveIntArrayList.remove(existing, passengerEntityID);
|
||||
return PrimitiveIntArrayList.isEmpty(updated) ? null : updated;
|
||||
});
|
||||
}
|
||||
//
|
||||
// END Passenger tracking.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START Netty entity spawn task queue:
|
||||
//
|
||||
private final Int2ObjectArrayMap<EntitySpawnTask> pendingPostEntitySpawnTasksByEntityID = new Int2ObjectArrayMap<>(16); // shot in the dark guess at capacity here. Can't be the more generic Int2ObjectMap because that doesn't expose a fast iterator.
|
||||
private volatile boolean evictPendingPostSpawnTasksOnNextPacket; private static final VarHandle EVICT_PENDING_POST_SPAWN_TASKS_ON_NEXT_PACKET_HANDLE = VarHandler.get(NettyData.class, "evictPendingPostSpawnTasksOnNextPacket", boolean.class);
|
||||
/**
|
||||
* This is intended for reconciliation tasks due to Minecraft sending packets out of order. For example, {@link Packets#ENTITY_EQUIPMENT} is sent before the corresponding {@link Packets#SPAWN_ENTITY} packet, so caching of the equipment packet must await the spawn packet.
|
||||
* @param entityID The entity ID to associate the task with. Immediately after a {@link Packets#SPAWN_ENTITY} packet is processed for this entity ID, the task will be consumed and run.
|
||||
* @param task The task to run.
|
||||
*/
|
||||
public void addPostEntitySpawnTask(int entityID, EntitySpawnTask task) {
|
||||
if (task.getNext() != null) {
|
||||
Logger.errorAndReturn(new IllegalArgumentException("Pending netty task was chained before queueing. Task=" + task), 4, NettyData.class);
|
||||
}
|
||||
EntitySpawnTask existing = pendingPostEntitySpawnTasksByEntityID.get(entityID);
|
||||
if (existing == null) {
|
||||
pendingPostEntitySpawnTasksByEntityID.put(entityID, task);
|
||||
return;
|
||||
}
|
||||
existing.appendLinkedTask(task);
|
||||
}
|
||||
|
||||
public void runPendingPostSpawnTaskForEntity(int entityID) {
|
||||
EntitySpawnTask pendingTasks = consumePendingPostSpawnTasksForEntity(entityID);
|
||||
if (pendingTasks != null) {
|
||||
pendingTasks.runLinkedTasks();
|
||||
}
|
||||
}
|
||||
|
||||
public void evictPendingPostSpawnTasksIfRequired(int currentTick) {
|
||||
if ((boolean) EVICT_PENDING_POST_SPAWN_TASKS_ON_NEXT_PACKET_HANDLE.getOpaque(this)
|
||||
&& (boolean) EVICT_PENDING_POST_SPAWN_TASKS_ON_NEXT_PACKET_HANDLE.compareAndExchangeAcquire(this, true, false)) evictOldPendingPostSpawnTasks(currentTick);
|
||||
}
|
||||
|
||||
public void markPendingPostSpawnTasksForEviction() {
|
||||
EVICT_PENDING_POST_SPAWN_TASKS_ON_NEXT_PACKET_HANDLE.setOpaque(this, true);
|
||||
}
|
||||
|
||||
public EntitySpawnTask consumePendingPostSpawnTasksForEntity(int entityID) {
|
||||
return pendingPostEntitySpawnTasksByEntityID.remove(entityID);
|
||||
}
|
||||
|
||||
public void clearPendingPostSpawnTasksForEntity(int entityID) {
|
||||
pendingPostEntitySpawnTasksByEntityID.remove(entityID);
|
||||
}
|
||||
|
||||
public void evictOldPendingPostSpawnTasks(int currentTick) {
|
||||
ObjectIterator<Int2ObjectMap.Entry<EntitySpawnTask>> iterator = pendingPostEntitySpawnTasksByEntityID.int2ObjectEntrySet().fastIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Int2ObjectMap.Entry<EntitySpawnTask> entry = iterator.next();
|
||||
EntitySpawnTask survivingHead = entry.getValue().trimExpiredTasks(currentTick);
|
||||
if (survivingHead == null) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
entry.setValue(survivingHead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Netty entity spawn task queue.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START Self entity tracking:
|
||||
//
|
||||
private final NettyEntity<?> selfEntity;
|
||||
private final int selfEntityID;
|
||||
|
||||
public NettyData(NettyEntity<?> selfEntity) {
|
||||
this.selfEntity = selfEntity;
|
||||
this.selfEntityID = selfEntity.entityID();
|
||||
}
|
||||
|
||||
public NettyEntity<?> getSelfEntity() {
|
||||
return selfEntity;
|
||||
}
|
||||
|
||||
public int getSelfEntityID() {
|
||||
return selfEntityID;
|
||||
}
|
||||
|
||||
public boolean isSelfEntityID(int entityID) {
|
||||
return entityID == selfEntityID;
|
||||
}
|
||||
//
|
||||
// END Self entity tracking.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START World-transition destroy tracking:
|
||||
//
|
||||
private int @IntArrayListMarker [] expectedWorldTransitionDestroyEntityIDs;
|
||||
|
||||
/**
|
||||
* When changing worlds, the server sends destroy packets for all the entities in the old world, but we want to clear the view. Tracking them here allows those destroy packets to be handled correctly.
|
||||
*/
|
||||
public void setExpectedWorldTransitionDestroyEntityIDs(int[] expectedEntityIDs) {
|
||||
expectedWorldTransitionDestroyEntityIDs = PrimitiveIntArrayList.isEmpty(expectedEntityIDs) ? null : expectedEntityIDs.clone();
|
||||
}
|
||||
|
||||
public boolean consumeExpectedWorldTransitionDestroyEntityID(int entityID) {
|
||||
if (!PrimitiveIntArrayList.contains(expectedWorldTransitionDestroyEntityIDs, entityID)) {
|
||||
return false;
|
||||
}
|
||||
expectedWorldTransitionDestroyEntityIDs = PrimitiveIntArrayList.remove(expectedWorldTransitionDestroyEntityIDs, entityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(expectedWorldTransitionDestroyEntityIDs)) {
|
||||
expectedWorldTransitionDestroyEntityIDs = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//
|
||||
// END World-transition destroy tracking.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// START World tracking:
|
||||
//
|
||||
|
||||
private int currentWorldMinHeight = Integer.MIN_VALUE; // Netty thread access only
|
||||
private String currentWorldName = null; // Netty thread access only
|
||||
|
||||
public int getCurrentWorldMinHeight() {
|
||||
if (currentWorldMinHeight == Integer.MIN_VALUE) {
|
||||
Logger.error(new IllegalStateException("Current world min height was requested before it was set"), 3, NettyData.class);
|
||||
return -64;
|
||||
}
|
||||
return currentWorldMinHeight;
|
||||
}
|
||||
|
||||
public NettyData setCurrentWorldMinHeight(int currentWorldMinHeight) {
|
||||
this.currentWorldMinHeight = currentWorldMinHeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The current world name, or null if the player is still in the process of joining the server.
|
||||
*/
|
||||
public @Nullable String getCurrentWorldName() {
|
||||
return currentWorldName;
|
||||
}
|
||||
|
||||
public NettyData setCurrentWorldName(String currentWorldName) {
|
||||
this.currentWorldName = currentWorldName;
|
||||
return this;
|
||||
}
|
||||
|
||||
//
|
||||
// END World tracking.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
public void clearPendingReconciliationState() {
|
||||
unresolvedLeashedEntityIDsByHolderID.clear();
|
||||
unresolvedHolderIDsByLeashedEntityID.clear();
|
||||
unresolvedPassengerIDsByVehicleID.clear();
|
||||
unresolvedVehicleIDsByPassengerID.clear();
|
||||
pendingPostEntitySpawnTasksByEntityID.clear();
|
||||
evictPendingPostSpawnTasksOnNextPacket = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
clearPendingReconciliationState();
|
||||
expectedWorldTransitionDestroyEntityIDs = null;
|
||||
if (selfEntity != null) {
|
||||
selfEntity.clear();
|
||||
}
|
||||
currentWorldMinHeight = Integer.MIN_VALUE;
|
||||
currentWorldName = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.implementations.ThreadSafeLocatable;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
import games.cubi.raycastedantiesp.core.view.EntityView;
|
||||
import games.cubi.raycastedantiesp.core.view.ViewRegistry;
|
||||
import games.cubi.raycastedantiesp.core.view.controller.PacketEntityViewController;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public class PlayerData {
|
||||
public static final int INVALID_WORLD_EPOCH = -1;
|
||||
|
||||
private final UUID playerUUID;
|
||||
private final int joinTick;
|
||||
private volatile boolean hasBypassPermission;
|
||||
private volatile boolean connected;
|
||||
private final ThreadSafeLocatable ownLocation;
|
||||
|
||||
private final BlockView blockView;
|
||||
private final EntityView<?> entityView;
|
||||
private final EntityView<?> playerView;
|
||||
private final NettyData nettyData;
|
||||
// Even positive values are stable world sessions; odd values mean the views are being replaced.
|
||||
private volatile int worldEpoch; private static final VarHandle WORLD_EPOCH = VarHandler.get(PlayerData.class, "worldEpoch", int.class);
|
||||
private UUID viewWorld;
|
||||
|
||||
PlayerData(UUID player, boolean hasBypassPermission, int joinTick, int selfEntityID, PlayerRegistry.SelfEntityCreator selfEntityCreator) {
|
||||
this.joinTick = joinTick;
|
||||
this.playerUUID = player;
|
||||
this.hasBypassPermission = hasBypassPermission;
|
||||
connected = true;
|
||||
|
||||
IntSupplier worldEpochSupplier = this::acquireWorldEpoch;
|
||||
blockView = ViewRegistry.createBlockView(worldEpochSupplier);
|
||||
entityView = ViewRegistry.createEntityView(worldEpochSupplier);
|
||||
playerView = ViewRegistry.createPlayerEntityView(worldEpochSupplier);
|
||||
ownLocation = new ThreadSafeLocatable(null, 0, 0, 0);
|
||||
NettyEntity<?> selfEntity = Logger.requireNonNull(
|
||||
selfEntityCreator.createSelfEntity(this, selfEntityID, player),
|
||||
"Self entity creator returned null",
|
||||
3,
|
||||
PlayerData.class
|
||||
);
|
||||
nettyData = new NettyData(selfEntity);
|
||||
}
|
||||
|
||||
public EntityView<?> entityView() {
|
||||
return entityView;
|
||||
}
|
||||
|
||||
public EntityView<?> playerView() {
|
||||
return playerView;
|
||||
}
|
||||
|
||||
public NettyData nettyData() {
|
||||
return nettyData;
|
||||
}
|
||||
|
||||
public BlockView blockView() {
|
||||
return blockView;
|
||||
}
|
||||
|
||||
/** Acquire-reads the current player-wide view epoch. */
|
||||
public int acquireWorldEpoch() {
|
||||
return (int) WORLD_EPOCH.getAcquire(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stable epoch for {@code expectedWorld}, or {@link #INVALID_WORLD_EPOCH} when the world session is not usable.
|
||||
*/
|
||||
public int tryAcquireWorldEpochFor(UUID expectedWorld) {
|
||||
int before = acquireWorldEpoch();
|
||||
if (!isStableWorldEpoch(before)) {
|
||||
return INVALID_WORLD_EPOCH;
|
||||
}
|
||||
UUID currentWorld = viewWorld;
|
||||
int after = acquireWorldEpoch();
|
||||
if (before != after || !Objects.equals(currentWorld, expectedWorld)) {
|
||||
return INVALID_WORLD_EPOCH;
|
||||
}
|
||||
return before;
|
||||
}
|
||||
|
||||
public static boolean isStableWorldEpoch(int epoch) {
|
||||
return epoch != 0 && (epoch & 1) == 0;
|
||||
}
|
||||
|
||||
/** Structural-writer operation performed before clearing all world-scoped views. */
|
||||
public void beginWorldTransition() {
|
||||
int current = acquireWorldEpoch();
|
||||
if ((current & 1) != 0) { //current is odd
|
||||
throw new IllegalStateException("World transition already in progress");
|
||||
}
|
||||
WORLD_EPOCH.setRelease(this, current + 1);
|
||||
// Keep subsequent view-clearing writes behind the invalidating odd epoch.
|
||||
VarHandle.releaseFence();
|
||||
viewWorld = null;
|
||||
}
|
||||
|
||||
/** Structural-writer operation performed after all world-scoped views have been cleared. */
|
||||
public void completeWorldTransition(UUID world) {
|
||||
int current = acquireWorldEpoch();
|
||||
if ((current & 1) == 0) { //current is even
|
||||
throw new IllegalStateException("No world transition in progress");
|
||||
}
|
||||
viewWorld = world;
|
||||
WORLD_EPOCH.setRelease(this, current + 1);
|
||||
}
|
||||
|
||||
public void updateOwnLocation(UUID world, double x, double y, double z) {
|
||||
ownLocation.set(x, y, z, world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a live, thread-safe view of the player's current location.
|
||||
* Casting the result to a mutable type and modifying it is unsupported.
|
||||
*/
|
||||
public Locatable ownLocation() {
|
||||
return ownLocation;
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public boolean hasBypassPermission() {
|
||||
return hasBypassPermission;
|
||||
}
|
||||
|
||||
public int getJoinTick() {
|
||||
return joinTick;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public void markDisconnected() {
|
||||
connected = false;
|
||||
int current = acquireWorldEpoch();
|
||||
if ((current & 1) == 0) {
|
||||
WORLD_EPOCH.setRelease(this, current + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Either the entity or player view for this player, depending on the entity ID
|
||||
*/
|
||||
public EntityView<?> viewFromEntityID(int entityID) {
|
||||
if (entityView.exists(entityID)) {
|
||||
return entityView;
|
||||
}
|
||||
if (playerView.exists(entityID)) {
|
||||
return playerView;
|
||||
}
|
||||
Logger.warning("Could not find view for entityID=" + entityID + " uuid=" + playerUUID, 6, PacketEntityViewController.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable NettyEntity<?> entityFromID(int entityID) {
|
||||
if (nettyData.isSelfEntityID(entityID)) {
|
||||
return nettyData.getSelfEntity();
|
||||
}
|
||||
EntityView<?> entityView = viewFromEntityID(entityID);
|
||||
if (entityView == null) {
|
||||
return null;
|
||||
}
|
||||
return (NettyEntity<?>) entityView.getEntity(entityID);
|
||||
}
|
||||
|
||||
public void setBypassPermission(boolean hasBypassPermission) {
|
||||
this.hasBypassPermission = hasBypassPermission;
|
||||
} //todo: need to link up
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlayerData{" +
|
||||
"playerUUID=" + playerUUID +
|
||||
", joinTick=" + joinTick +
|
||||
", hasBypassPermission=" + hasBypassPermission() +
|
||||
", ownLocation=" + ownLocation +
|
||||
", blockView=" + blockView +
|
||||
", entityView=" + entityView +
|
||||
", playerView=" + playerView +
|
||||
", nettyData=" + nettyData +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.api.FloatingLocatableEquality;
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.MutableFloatingLocatable;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A mutable, thread-safe location and view state for a player.
|
||||
*
|
||||
* <p>Mutations are serialized because platform and packet lifecycle callbacks
|
||||
* may write from different threads. World and scalar reads use relaxed
|
||||
* per-field access: a read may combine values from adjacent updates.</p>
|
||||
* <p></p>
|
||||
* Reads of several fields are not coherently published. This is acceptable
|
||||
* since players typically move in small increments, so an old x and new z
|
||||
* still closely approximate the player's actual position. In less-frequent
|
||||
* cases such as teleports or dimension switches, raycasts may use the incorrect
|
||||
* position briefly. This does not matter, as incorrect state will be fixed by next tick's raycast.
|
||||
*/
|
||||
public final class PlayerLocatable implements MutableFloatingLocatable, FloatingLocatableEquality {
|
||||
private final Object writerMonitor = new Object();
|
||||
|
||||
private volatile UUID world; private static final VarHandle WORLD = VarHandler.get(PlayerLocatable.class, "world", UUID.class);
|
||||
private volatile double x; private static final VarHandle X = VarHandler.get(PlayerLocatable.class, "x", double.class);
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(PlayerLocatable.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(PlayerLocatable.class, "z", double.class);
|
||||
private volatile float yaw; private static final VarHandle YAW = VarHandler.get(PlayerLocatable.class, "yaw", float.class);
|
||||
private volatile float pitch; private static final VarHandle PITCH = VarHandler.get(PlayerLocatable.class, "pitch", float.class);
|
||||
private volatile PlayerPose pose; private static final VarHandle POSE = VarHandler.get(PlayerLocatable.class, "pose", PlayerPose.class);
|
||||
|
||||
public PlayerLocatable() {
|
||||
}
|
||||
|
||||
/** Initialises or replaces the complete valid player state. */
|
||||
public void initialise(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the complete state for a world change. */
|
||||
public void worldChange(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's foot position while retaining rotation and pose. */
|
||||
public void updateFoot(double footX, double footY, double footZ) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's rotation while retaining position and pose. */
|
||||
public void updateRotation(float yaw, float pitch) {
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's pose while retaining position and rotation. */
|
||||
public void updatePose(PlayerPose pose) {
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
synchronized (writerMonitor) {
|
||||
POSE.setOpaque(this, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates position and rotation in one logical operation. */
|
||||
public void updateFootAndRotation(double footX, double footY, double footZ, float yaw, float pitch) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Invalidates and clears the complete player state. */
|
||||
public void invalidate() {
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, 0.0);
|
||||
Y.setOpaque(this, 0.0);
|
||||
Z.setOpaque(this, 0.0);
|
||||
YAW.setOpaque(this, 0.0f);
|
||||
PITCH.setOpaque(this, 0.0f);
|
||||
POSE.setOpaque(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID world() {
|
||||
return (UUID) WORLD.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double x() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double y() {
|
||||
return (double) Y.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double z() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public float yaw() {
|
||||
return (float) YAW.getOpaque(this);
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return (float) PITCH.getOpaque(this);
|
||||
}
|
||||
|
||||
public PlayerPose pose() {
|
||||
return (PlayerPose) POSE.getOpaque(this);
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentPose == null ? 0.0f : currentPose.cameraYOffset();
|
||||
}
|
||||
|
||||
public double cameraX() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraY() {
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset());
|
||||
}
|
||||
|
||||
public double cameraZ() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraDistanceSquared(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
double targetX = spatial.x();
|
||||
double targetY = spatial.y();
|
||||
double targetZ = spatial.z();
|
||||
double currentX = (double) X.getOpaque(this);
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
double currentZ = (double) Z.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
double dx = currentX - targetX;
|
||||
double dy = currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset()) - targetY;
|
||||
double dz = currentZ - targetZ;
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setX(double x) {
|
||||
validateFinite(x);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setY(double y) {
|
||||
validateFinite(y);
|
||||
synchronized (writerMonitor) {
|
||||
Y.setOpaque(this, y);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setZ(double z) {
|
||||
validateFinite(z);
|
||||
synchronized (writerMonitor) {
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
return setPosition(spatial.x(), spatial.y(), spatial.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setWorld(UUID world) {
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(Locatable locatable) {
|
||||
Objects.requireNonNull(locatable, "locatable");
|
||||
return setLocation(locatable.world(), locatable.x(), locatable.y(), locatable.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(UUID world, double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(Locatable locatable) {
|
||||
return setLocation(locatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(int x, int y, int z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z, UUID world) {
|
||||
return setLocation(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatableType getType() {
|
||||
return LocatableType.ThreadSafe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return isEqualTo(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return makeHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean strictlyEquals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof PlayerLocatable that)) {
|
||||
return false;
|
||||
}
|
||||
UUID thisWorld = world();
|
||||
double thisX = x();
|
||||
double thisY = y();
|
||||
double thisZ = z();
|
||||
return Objects.equals(thisWorld, that.world())
|
||||
&& Double.doubleToLongBits(thisX) == Double.doubleToLongBits(that.x())
|
||||
&& Double.doubleToLongBits(thisY) == Double.doubleToLongBits(that.y())
|
||||
&& Double.doubleToLongBits(thisZ) == Double.doubleToLongBits(that.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringForm();
|
||||
}
|
||||
|
||||
/** This method must only be called while holding {@link #writerMonitor}. */
|
||||
private void writeFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
POSE.setOpaque(this, pose);
|
||||
WORLD.setOpaque(this, world);
|
||||
}
|
||||
|
||||
private static void validateFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
Objects.requireNonNull(world, "world");
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
}
|
||||
|
||||
private static void validateFinite(double x, double y, double z) {
|
||||
if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)) {
|
||||
throw new IllegalArgumentException("Coordinates must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateFinite(double value) {
|
||||
if (!Double.isFinite(value)) {
|
||||
throw new IllegalArgumentException("Coordinate must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRotation(float yaw, float pitch) {
|
||||
if (!Float.isFinite(yaw) || !Float.isFinite(pitch) || pitch < -90.0f || pitch > 90.0f) {
|
||||
throw new IllegalArgumentException("Rotation must be finite and pitch must be between -90 and 90 degrees");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
/** Player body poses and the corresponding camera height above the feet. */
|
||||
public enum PlayerPose {
|
||||
UNKNOWN(1.62f),
|
||||
STANDING(1.62f),
|
||||
SNEAKING(1.27f),
|
||||
SWIMMING(0.40f),
|
||||
FALL_FLYING(0.40f),
|
||||
SPIN_ATTACK(0.40f),
|
||||
SLEEPING(0.20f),
|
||||
DYING(0.20f);
|
||||
|
||||
private final float cameraYOffset;
|
||||
|
||||
PlayerPose(float cameraYOffset) {
|
||||
this.cameraYOffset = cameraYOffset;
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
return cameraYOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerRegistry {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SelfEntityCreator {
|
||||
NettyEntity<?> createSelfEntity(PlayerData playerData, int selfEntityID, UUID playerUUID);
|
||||
}
|
||||
|
||||
private static final PlayerRegistry instance = new PlayerRegistry();
|
||||
|
||||
private PlayerRegistry() {}
|
||||
|
||||
public static PlayerRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<UUID, PlayerData> playerDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
/** Forcefully registers a player and returns the new PlayerData, even if they were already registered.**/
|
||||
public PlayerData registerAndGetPlayer(UUID playerUUID, int joinTick, int selfEntityID, SelfEntityCreator selfEntityCreator) {
|
||||
PlayerData newData = new PlayerData(playerUUID, false, joinTick, selfEntityID, selfEntityCreator);
|
||||
PlayerData old = playerDataMap.put(playerUUID, newData);
|
||||
if (old != null) old.markDisconnected();
|
||||
return newData;
|
||||
}
|
||||
|
||||
public void unregisterPlayer(UUID playerUUID) {
|
||||
PlayerData unregisteredPlayer = playerDataMap.remove(playerUUID);
|
||||
if (unregisteredPlayer == null) {
|
||||
return;
|
||||
}
|
||||
unregisteredPlayer.markDisconnected();
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(UUID playerUUID) {
|
||||
return playerDataMap.get(playerUUID);
|
||||
}
|
||||
|
||||
public boolean isPlayerRegistered(UUID playerUUID) {
|
||||
return playerDataMap.containsKey(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Live, mutable collection of all PlayerData instances.
|
||||
* **/
|
||||
public Collection<PlayerData> getAllPlayerData() {
|
||||
return playerDataMap.values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ParticleSpawner {
|
||||
|
||||
enum Colour {
|
||||
RED, GREEN, BLUE,
|
||||
}
|
||||
|
||||
void spawnParticleAt(Locatable locatable, Colour colour);
|
||||
|
||||
void spawnParticleAt(UUID world, Spatial spatial, Colour colour);
|
||||
|
||||
void spawnParticleAt(UUID world, double x, double y, double z, Colour colour);
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.*;
|
||||
import games.cubi.locatables.implementations.MutableChunkSection;
|
||||
import games.cubi.locatables.implementations.MutableSpatialImpl;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
|
||||
public class RaycastUtil {
|
||||
|
||||
//True: Has line-of-sight
|
||||
//This is deliberately a ray-stepping algorithm rather than DDA as it is much faster (2x in benchmarking)
|
||||
//Missing blocks is acceptable, as it will be assumed the player can see past those corners.
|
||||
//While this uses objects, JHM and in-game profiling have both shown that all objects used here are consistently scalarised by the JVM.
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, float stepSize, ParticleSpawner particleSpawner) {
|
||||
//return raycastCubiNoAllocUnrolledLongBitsAccumulated(maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, 1, snap, start.x(), start.y(), start.z(), end.x(), end.y(), end.z());
|
||||
|
||||
//return raycastUnrolledAccumulated(maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, 1, snap, start, end);
|
||||
return raycast(start, end, maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, snap, 0f, stepSize, particleSpawner);
|
||||
}
|
||||
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, float yOffsetEnd, float stepSize, ParticleSpawner particleSpawner) {
|
||||
double endOffset = end instanceof BlockSpatial ? 0.5 : 0.0;
|
||||
MutableFloatingSpatial clonedEnd = new MutableSpatialImpl(end.x() + endOffset, end.y() + endOffset + yOffsetEnd, end.z() + endOffset);
|
||||
//Equivalent to end.cloneAndIfBlockThenCentre(); but not used since the JVM was not reliably scalarising that method (probably due to the polymorphic overriding?). This causes 0 object allocations.
|
||||
float total = (float) (start.distance(clonedEnd) - stepSize); //benchmarking shows that calling distance() is faster than distanceSquared() then checking distanceSquared < stepSize*stepSize every time despite the latter replacing a square root with multiplication
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
if (debug && particleSpawner == null) {
|
||||
Logger.errorAndReturn(new RuntimeException("raycast called with debug enabled but no ParticleSpawner supplied"), 2, RaycastUtil.class);
|
||||
}
|
||||
|
||||
Spatial dir = clonedEnd.subtract(start).normalise().scalarMultiply(stepSize);
|
||||
|
||||
MutableFloatingSpatial current = new MutableSpatialImpl(start.x(),start.y(),start.z());
|
||||
MutableChunkSection currentChunk = new MutableChunkSection().updateFrom(current);
|
||||
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(currentChunk);
|
||||
|
||||
for (float traveled = 0; traveled < total; traveled += stepSize) {
|
||||
current.add(dir);
|
||||
if (!ChunkSectionEquality.equals(currentChunk, current)) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = snap.getChunkOcclusionView(currentChunk);
|
||||
}
|
||||
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(current.blockX(), current.blockY(), current.blockZ())) {
|
||||
maxOccluding--;
|
||||
if (debug) particleSpawner.spawnParticleAt(start.world(), current, ParticleSpawner.Colour.RED);
|
||||
if (maxOccluding < 1) return false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (debug) particleSpawner.spawnParticleAt(start.world(), current, ParticleSpawner.Colour.GREEN);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
public static boolean raycastCubiNoAllocUnrolledLongBitsAccumulated(int maxOccluding, final int alwaysShowRadius, final int maxRaycastRadius, boolean debug, final int stepSize, BlockView snap,
|
||||
final double startX, final double startY, final double startZ, final double endX, final double endY, final double endZ) {
|
||||
if (maxOccluding <= 0) return false;
|
||||
|
||||
double total = Math.sqrt(((endX - startX) * (endX - startX)) + ((endY - startY) * (endY - startY)) + ((endZ - startZ) * (endZ - startZ)));
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
double finalDist = total - stepSize;
|
||||
|
||||
final double dirX = (endX - startX) / total * stepSize;
|
||||
final double dirY = (endY - startY) / total * stepSize;
|
||||
final double dirZ = (endZ - startZ) / total * stepSize;
|
||||
|
||||
double currentX = startX;
|
||||
double currentY = startY;
|
||||
double currentZ = startZ;
|
||||
|
||||
int chunkX = ((int) currentX) >> 4;
|
||||
int chunkY = ((int) currentY) >> 4;
|
||||
int chunkZ = ((int) currentZ) >> 4;
|
||||
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
|
||||
int occluded = 0;
|
||||
|
||||
double traveled = 0;
|
||||
final double fourSteps = stepSize * 4.0;
|
||||
while (traveled + fourSteps <= finalDist) {
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
int blockX = (int) Math.floor(currentX);
|
||||
int blockY = (int) Math.floor(currentY);
|
||||
int blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
blockX = (int) Math.floor(currentX);
|
||||
blockY = (int) Math.floor(currentY);
|
||||
blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
|
||||
if (occluded >= maxOccluding) return false;
|
||||
|
||||
traveled += fourSteps;
|
||||
}
|
||||
|
||||
for (; traveled < finalDist; traveled += stepSize) {
|
||||
currentX += dirX;
|
||||
currentY += dirY;
|
||||
currentZ += dirZ;
|
||||
|
||||
int blockX = (int) Math.floor(currentX);
|
||||
int blockY = (int) Math.floor(currentY);
|
||||
int blockZ = (int) Math.floor(currentZ);
|
||||
if (blockX >> 4 != chunkX || blockY >> 4 != chunkY || blockZ >> 4 != chunkZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
currentOcclusionView = snap.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded ++;
|
||||
}
|
||||
|
||||
return occluded < maxOccluding;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* The local spatial and chunk-section objects do not escape this method, so the JVM
|
||||
* should be able to scalarise them while keeping the ray-stepping code easier to follow.
|
||||
*/
|
||||
public static boolean raycastUnrolledAccumulated(int maxOccluding, final int alwaysShowRadius, final int maxRaycastRadius, boolean debug,
|
||||
final float stepSize, final BlockView snap, final Spatial start, final Spatial end) {
|
||||
RayPosition current = RayPosition.from(start);
|
||||
RayDirection direction = RayDirection.from(end, current);
|
||||
double total = direction.getLengthAndNormalise(stepSize);
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
float finalDist = (float) (total - stepSize);
|
||||
|
||||
final RayAdvancer rayAdvancer = new RayAdvancer(current, direction, snap);
|
||||
|
||||
float traveled = 0;
|
||||
final float fourSteps = stepSize * 4.0f;
|
||||
while (traveled + fourSteps <= finalDist) {
|
||||
rayAdvancer.advance();
|
||||
|
||||
rayAdvancer.advance();
|
||||
|
||||
rayAdvancer.advance();
|
||||
|
||||
rayAdvancer.advance();
|
||||
|
||||
if (rayAdvancer.occluded >= maxOccluding) return false;
|
||||
|
||||
traveled += fourSteps;
|
||||
}
|
||||
|
||||
for (; traveled < finalDist; traveled += stepSize) {
|
||||
rayAdvancer.advance();
|
||||
}
|
||||
|
||||
return rayAdvancer.occluded < maxOccluding;
|
||||
}
|
||||
|
||||
private static final class RayAdvancer {
|
||||
private final RayPosition current;
|
||||
private final RayDirection direction;
|
||||
private final RayChunkSection currentChunk;
|
||||
private final BlockView blockView;
|
||||
|
||||
private ChunkOcclusionView currentOcclusionView;
|
||||
private int occluded = 0;
|
||||
|
||||
private RayAdvancer(RayPosition rayPosition, RayDirection rayDirection, BlockView blockView) {
|
||||
current = rayPosition;
|
||||
direction = rayDirection;
|
||||
currentChunk = new RayChunkSection().updateFrom(current);
|
||||
currentOcclusionView = blockView.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
this.blockView = blockView;
|
||||
}
|
||||
|
||||
private void advance() {
|
||||
current.advance(direction);
|
||||
int blockX = current.blockX();
|
||||
int blockY = current.blockY();
|
||||
int blockZ = current.blockZ();
|
||||
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
|
||||
currentChunk.updateFrom(current);
|
||||
currentOcclusionView = blockView.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
|
||||
}
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayPosition {
|
||||
private double x, y, z;
|
||||
|
||||
private void advance(RayDirection direction) {
|
||||
x += direction.x;
|
||||
y += direction.y;
|
||||
z += direction.z;
|
||||
}
|
||||
|
||||
private int blockX() {
|
||||
return (int) Math.floor(x);
|
||||
}
|
||||
|
||||
private int blockY() {
|
||||
return (int) Math.floor(y);
|
||||
}
|
||||
|
||||
private int blockZ() {
|
||||
return (int) Math.floor(z);
|
||||
}
|
||||
|
||||
private int chunkX() {
|
||||
return blockX() >> 4;
|
||||
}
|
||||
|
||||
private int chunkY() {
|
||||
return blockY() >> 4;
|
||||
}
|
||||
|
||||
private int chunkZ() {
|
||||
return blockZ() >> 4;
|
||||
}
|
||||
|
||||
private RayPosition(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static RayPosition from(Spatial spatial) {
|
||||
return new RayPosition(spatial.x(), spatial.y(), spatial.z());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayDirection {
|
||||
private double x, y, z;
|
||||
|
||||
private RayDirection(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static RayDirection from(Spatial end, RayPosition start) {
|
||||
return new RayDirection(end.x() - start.x, end.y() - start.y, end.z() - start.z);
|
||||
}
|
||||
|
||||
private double getLengthAndNormalise(float stepSize) {
|
||||
double len = Math.sqrt(x * x + y * y + z * z);
|
||||
x = (x / len) * stepSize;
|
||||
y = (y / len) * stepSize;
|
||||
z = (z / len) * stepSize;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayChunkSection {
|
||||
private int chunkX, chunkY, chunkZ;
|
||||
|
||||
private RayChunkSection updateFrom(RayPosition other) {
|
||||
this.chunkX = other.chunkX();
|
||||
this.chunkY = other.chunkY();
|
||||
this.chunkZ = other.chunkZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
|
||||
import games.cubi.raycastedantiesp.core.utils.IntArrayListMarker;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Designed for use with netty-based systems, where entity data updates only ever come from one thread, but reads may come from multiple threads. This is however not enforced, and must be kept in mind when using this class.
|
||||
* A representation of an entity for a specific player.
|
||||
*/
|
||||
public abstract class NettyEntity<PacketReplayData extends Clearable> implements TrackedEntity<PacketReplayData> {
|
||||
// immutable fields
|
||||
private final int entityID; // Note that, while rare, entity ids will be negative once the entity id counter overflows.
|
||||
private final UUID entityUUID;
|
||||
private final boolean isSelfEntity;
|
||||
private final int entityType;
|
||||
private final PlayerData owningPlayer;
|
||||
|
||||
// Netty mutatable fields. Should NEVER be mutated from the engine thread, but reads are fine.
|
||||
private volatile double x; private static final VarHandle X = VarHandler.get(NettyEntity.class, "x", double.class);
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(NettyEntity.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(NettyEntity.class, "z", double.class);
|
||||
|
||||
// Packet-derived state shared with the engine.
|
||||
private static final byte FLAG_SNEAKING = 1;
|
||||
private static final byte FLAG_GLOWING = 1 << 1;
|
||||
private volatile byte trackedFlags; private static final VarHandle TRACKED_FLAGS = VarHandler.get(NettyEntity.class, "trackedFlags", byte.class);
|
||||
|
||||
// Packet-thread-only replay and client state.
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
private float headYaw;
|
||||
private double velocityX;
|
||||
private double velocityY;
|
||||
private double velocityZ;
|
||||
private boolean onGround = true;
|
||||
private int@IntArrayListMarker[] leashedIDs;
|
||||
|
||||
// Netty-written attachment state shared with the engine thread.
|
||||
private volatile int leasherID = NO_LEASHER; private static final VarHandle LEASHER_ID = VarHandler.get(NettyEntity.class, "leasherID", int.class);
|
||||
private volatile int[] passengerIDs; private static final VarHandle PASSENGER_IDS = VarHandler.get(NettyEntity.class, "passengerIDs", int[].class);
|
||||
private volatile int vehicleID = NO_VEHICLE; private static final VarHandle VEHICLE_ID = VarHandler.get(NettyEntity.class, "vehicleID", int.class);
|
||||
|
||||
|
||||
private int entityData;
|
||||
private PacketReplayData packetReplayData; // For use storing the packets we can't be bothered to directly store, with all cached packets being sent back out to the client when entity is visible again.
|
||||
|
||||
// Mutable by the engine and packet threads.
|
||||
private volatile int lastChecked; private static final VarHandle LAST_CHECKED = VarHandler.get(NettyEntity.class, "lastChecked", int.class);
|
||||
private boolean clientVisible = true;
|
||||
|
||||
// engine thread mutable, reads from netty and engine.
|
||||
private volatile boolean visible;
|
||||
|
||||
// Constants
|
||||
public static final int NEVER_CHECKED = Integer.MIN_VALUE;
|
||||
public static final int NO_VEHICLE = -1;
|
||||
public static final int NO_LEASHER = -2;
|
||||
public static final int SELF_ENTITY_TYPE = -29;
|
||||
|
||||
public NettyEntity(PlayerData owningPlayer, double x, double y, double z, int entityID, UUID entityUUID, boolean isSelfEntity, int entityType, boolean visible) {
|
||||
X.set(this, x); Y.set(this, y); Z.set(this, z);
|
||||
|
||||
this.entityID = entityID;
|
||||
this.entityUUID = entityUUID;
|
||||
this.isSelfEntity = isSelfEntity;
|
||||
this.entityType = entityType;
|
||||
|
||||
this.visible = visible;
|
||||
|
||||
this.owningPlayer = owningPlayer;
|
||||
}
|
||||
|
||||
// For creating the self entity, where we don't have access to its position. Always visible.
|
||||
protected NettyEntity(PlayerData selfData, int selfPlayerID, UUID ownUUID) {
|
||||
entityID = selfPlayerID;
|
||||
entityUUID = ownUUID;
|
||||
owningPlayer = selfData;
|
||||
isSelfEntity = true;
|
||||
entityType = SELF_ENTITY_TYPE;
|
||||
visible = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int entityID() {
|
||||
return entityID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID entityUUID() {
|
||||
return entityUUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wherever possible, effort should be made to only call this from the engine thread, for thread safety reasons.
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean glowing() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_GLOWING) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sneaking() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_SNEAKING) != 0;
|
||||
}
|
||||
|
||||
public boolean setGlowing(boolean glowing) {
|
||||
return setTrackedFlag(FLAG_GLOWING, glowing);
|
||||
}
|
||||
|
||||
public boolean setSneaking(boolean sneaking) {
|
||||
return setTrackedFlag(FLAG_SNEAKING, sneaking);
|
||||
}
|
||||
|
||||
private boolean setTrackedFlag(byte mask, boolean enabled) {
|
||||
byte previous = enabled
|
||||
? (byte) TRACKED_FLAGS.getAndBitwiseOrRelease(this, mask)
|
||||
: (byte) TRACKED_FLAGS.getAndBitwiseAndRelease(this, (byte) ~mask);
|
||||
boolean changed = (previous & mask) != (enabled ? mask : 0);
|
||||
if (changed) {
|
||||
// A concurrent engine check may overwrite this marker. Hidden entities retry next tick; visible entities
|
||||
// may wait for their configured recheck or remain visible if rechecks are disabled.
|
||||
// This is acceptable and not considered an issue.
|
||||
LAST_CHECKED.setOpaque(this, NEVER_CHECKED);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastChecked() {
|
||||
return (int) LAST_CHECKED.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setLastChecked(int lastChecked) {
|
||||
LAST_CHECKED.setOpaque(this, lastChecked);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientVisible() {
|
||||
return clientVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setClientVisible(boolean clientVisible) {
|
||||
this.clientVisible = clientVisible;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelfEntity() {
|
||||
return isSelfEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float yaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float pitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float headYaw() {
|
||||
return headYaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setHeadYaw(float headYaw) {
|
||||
this.headYaw = headYaw;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double velocityX() {
|
||||
return velocityX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double velocityY() {
|
||||
return velocityY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double velocityZ() {
|
||||
return velocityZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setVelocity(double velocityX, double velocityY, double velocityZ) {
|
||||
this.velocityX = velocityX;
|
||||
this.velocityY = velocityY;
|
||||
this.velocityZ = velocityZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGround() {
|
||||
return onGround;
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS METHOD IS ONLY SAFE TO CALL FROM THE PLAYER's NETTY THREAD
|
||||
*/
|
||||
@Override
|
||||
public TrackedEntity<?> setOnGround(boolean onGround) {
|
||||
this.onGround = onGround;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int entityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int entityData() {
|
||||
return entityData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setEntityData(int entityData) {
|
||||
this.entityData = entityData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] passengerIDs() {
|
||||
int[] current = passengerIDsAcquire();
|
||||
return current == null ? null : current.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setPassengerIDs(int[] passengerIDs) {
|
||||
PASSENGER_IDS.setRelease(this, passengerIDs == null ? new int[0] : passengerIDs.clone());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVehicleID(int vehicleID) {
|
||||
VEHICLE_ID.setOpaque(this, vehicleID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int vehicleID() {
|
||||
return (int) VEHICLE_ID.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLeashedEntity(int leashedEntityID) {
|
||||
if (PrimitiveIntArrayList.contains(leashedIDs, leashedEntityID)) {
|
||||
return;
|
||||
}
|
||||
leashedIDs = PrimitiveIntArrayList.add(leashedIDs, leashedEntityID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLeashedEntity(int leashedEntityID) {
|
||||
leashedIDs = PrimitiveIntArrayList.remove(leashedIDs, leashedEntityID);
|
||||
}
|
||||
|
||||
public int@Nullable[] leashedEntityIDsOrNull() {
|
||||
return PrimitiveIntArrayList.getCopyOrNull(leashedIDs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leashingEntity() {
|
||||
return (int) LEASHER_ID.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeashingEntity(int leashingEntityID) {
|
||||
LEASHER_ID.setOpaque(this, leashingEntityID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketReplayData packetReplayData() {
|
||||
return packetReplayData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setPacketReplayData(PacketReplayData packetReplayData) {
|
||||
this.packetReplayData = packetReplayData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYOffset() {
|
||||
return 0.5f; //todo: move away from hardcoded offset
|
||||
}
|
||||
|
||||
@Override
|
||||
public double x() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double y() {
|
||||
return (double) Y.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double z() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableFloatingSpatial setX(double x) {
|
||||
X.setOpaque(this, x);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableFloatingSpatial setY(double y) {
|
||||
Y.setOpaque(this, y);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableFloatingSpatial setZ(double z) {
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableFloatingSpatial setPosition(double x, double y, double z) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
updatePassengerPositions();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableFloatingSpatial add(double x, double y, double z) {
|
||||
X.setOpaque(this, x() + x);
|
||||
Y.setOpaque(this, y() + y);
|
||||
Z.setOpaque(this, z() + z);
|
||||
updatePassengerPositions();
|
||||
return this;
|
||||
}
|
||||
|
||||
// This does not correctly set the passenger position, as the passenger is above the vehicle. It is however close enough to minimise annoying interpolation on show.
|
||||
private void updatePassengerPositions() {
|
||||
int[] currentPassengerIDs = passengerIDsAcquire();
|
||||
if (currentPassengerIDs == null || currentPassengerIDs.length == 0) return;
|
||||
double currentX = x();
|
||||
double currentY = y();
|
||||
double currentZ = z();
|
||||
for (int passengerID : currentPassengerIDs) {
|
||||
NettyEntity<?> passenger = owningPlayer.entityFromID(passengerID);
|
||||
if (passenger != null) {
|
||||
passenger.setVehicleID(entityID);
|
||||
passenger.setX(currentX);
|
||||
passenger.setY(currentY);
|
||||
passenger.setZ(currentZ);
|
||||
passenger.updatePassengerPositions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (packetReplayData != null) packetReplayData.clear();
|
||||
packetReplayData = null;
|
||||
|
||||
TRACKED_FLAGS.setOpaque(this, (byte) 0);
|
||||
VEHICLE_ID.setOpaque(this, NO_VEHICLE);
|
||||
PASSENGER_IDS.setRelease(this, null);
|
||||
leashedIDs = null;
|
||||
LEASHER_ID.setOpaque(this, NO_LEASHER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NettyEntity{" +
|
||||
"entityID=" + entityID +
|
||||
", entityUUID=" + entityUUID +
|
||||
", isSelfEntity=" + isSelfEntity +
|
||||
", entityType=" + entityType +
|
||||
", x=" + x() +
|
||||
", y=" + y() +
|
||||
", z=" + z() +
|
||||
", yaw=" + yaw() +
|
||||
", pitch=" + pitch() +
|
||||
", headYaw=" + headYaw() +
|
||||
", velocityX=" + velocityX() +
|
||||
", velocityY=" + velocityY() +
|
||||
", velocityZ=" + velocityZ() +
|
||||
", onGround=" + onGround() +
|
||||
", leashedIDs=" + nullableArrayToString(leashedIDs) +
|
||||
", leasherID=" + leashingEntity() +
|
||||
", passengerIDs=" + nullableArrayToString(passengerIDsAcquire()) +
|
||||
", vehicleID=" + vehicleID() +
|
||||
", entityData=" + entityData() +
|
||||
'}';
|
||||
}
|
||||
|
||||
private int[] passengerIDsAcquire() {
|
||||
return (int[]) PASSENGER_IDS.getAcquire(this);
|
||||
}
|
||||
|
||||
private static String nullableArrayToString(int[] values) {
|
||||
return values == null ? null : PrimitiveIntArrayList.toString(values);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.raycastedantiesp.core.utils.InvasivelyLinkedSWMRList;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
/** Tile visibility and lifecycle are shared with the engine; block and replay data are packet-thread-only. */
|
||||
public abstract class NettyTileEntity<PacketReplayData extends Clearable> extends InvasivelyLinkedSWMRList<NettyTileEntity<PacketReplayData>> implements TrackedTileEntity<PacketReplayData> {
|
||||
private volatile boolean visible;
|
||||
private volatile int lastChecked; private static final VarHandle LAST_CHECKED = VarHandler.get(NettyTileEntity.class, "lastChecked", int.class);
|
||||
private char blockID;
|
||||
private PacketReplayData extraData;
|
||||
|
||||
private static final int REMOVED = Integer.MIN_VALUE + 11;
|
||||
|
||||
private final int x, y, z;
|
||||
public NettyTileEntity(BlockSpatial position, boolean visible, int lastChecked, char blockID) {
|
||||
x = position.blockX();
|
||||
y = position.blockY();
|
||||
z = position.blockZ();
|
||||
|
||||
this.blockID = blockID;
|
||||
this.visible = visible;
|
||||
LAST_CHECKED.set(this, lastChecked);
|
||||
}
|
||||
|
||||
public NettyTileEntity(int x, int y, int z, boolean visible, char blockID) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.visible = visible;
|
||||
this.blockID = blockID;
|
||||
LAST_CHECKED.set(this, NEVER_CHECKED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedTileEntity<PacketReplayData> setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastChecked() {
|
||||
return (int) LAST_CHECKED.getAcquire(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedTileEntity<PacketReplayData> setLastChecked(int checkedTick) {
|
||||
int current = (int) LAST_CHECKED.getAcquire(this);
|
||||
while (current != REMOVED) {
|
||||
if (LAST_CHECKED.weakCompareAndSetRelease(this, current, checkedTick)) {
|
||||
break;
|
||||
}
|
||||
current = (int) LAST_CHECKED.getAcquire(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Marks this allocation as detached. This state is absorbing because removed nodes are never reused. */
|
||||
public final void markRemoved() {
|
||||
LAST_CHECKED.setRelease(this, REMOVED);
|
||||
}
|
||||
|
||||
/** Consumer-side lifecycle check performed immediately before emitting a queued transition. */
|
||||
public final boolean isRemoved() {
|
||||
return (int) LAST_CHECKED.getAcquire(this) == REMOVED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blockID() {
|
||||
return blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedTileEntity<PacketReplayData> setBlockID(char blockID) {
|
||||
this.blockID = blockID;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketReplayData extraData() {
|
||||
return extraData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedTileEntity<PacketReplayData> setExtraData(PacketReplayData extraData) {
|
||||
this.extraData = extraData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearExtraData() {
|
||||
if (extraData != null) {
|
||||
//extraData.clear(); probs not needed
|
||||
extraData = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blockX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blockY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blockZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (extraData != null) {
|
||||
extraData.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringForm();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Per-player platform-independent representation of an entity
|
||||
*/
|
||||
public interface TrackedEntity<PacketReplayData> extends MutableFloatingSpatial {
|
||||
|
||||
int entityID();
|
||||
|
||||
UUID entityUUID();
|
||||
|
||||
boolean visible();
|
||||
TrackedEntity<?> setVisible(boolean visible);
|
||||
|
||||
boolean glowing();
|
||||
|
||||
boolean sneaking();
|
||||
|
||||
int lastChecked();
|
||||
TrackedEntity<?> setLastChecked(int lastChecked);
|
||||
|
||||
/** Packet-thread-only client state. */
|
||||
boolean clientVisible();
|
||||
TrackedEntity<?> setClientVisible(boolean clientVisible);
|
||||
|
||||
boolean isSelfEntity();
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float yaw();
|
||||
TrackedEntity<?> setYaw(float yaw);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float pitch();
|
||||
TrackedEntity<?> setPitch(float pitch);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
float headYaw();
|
||||
TrackedEntity<?> setHeadYaw(float headYaw);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
double velocityX();
|
||||
double velocityY();
|
||||
double velocityZ();
|
||||
TrackedEntity<?> setVelocity(double velocityX, double velocityY, double velocityZ);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
boolean onGround();
|
||||
TrackedEntity<?> setOnGround(boolean onGround);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
int entityData();
|
||||
TrackedEntity<?> setEntityData(int entityData);
|
||||
|
||||
int[] passengerIDs();
|
||||
TrackedEntity<?> setPassengerIDs(int[] passengerIDs);
|
||||
|
||||
void setVehicleID(int vehicleID);
|
||||
int vehicleID();
|
||||
|
||||
/** Packet-thread-only holder-side relationship state. */
|
||||
void addLeashedEntity(int leashedEntityID);
|
||||
void removeLeashedEntity(int leashedEntityID);
|
||||
int@Nullable[] leashedEntityIDsOrNull();
|
||||
int leashingEntity();
|
||||
void setLeashingEntity(int leashingEntityID);
|
||||
|
||||
/** Packet-thread-only cached packet state. */
|
||||
PacketReplayData packetReplayData();
|
||||
TrackedEntity<?> setPacketReplayData(PacketReplayData packetReplayData);
|
||||
|
||||
float getYOffset();
|
||||
|
||||
/**
|
||||
* For use when the player disconnects, clears all data.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
default <T> T cast() {
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableBlockSpatial;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
public interface TrackedTileEntity<T> extends ImmutableBlockSpatial, Clearable {
|
||||
int NEVER_CHECKED = Integer.MIN_VALUE;
|
||||
|
||||
boolean visible();
|
||||
TrackedTileEntity<T> setVisible(boolean visible);
|
||||
|
||||
int lastChecked();
|
||||
TrackedTileEntity<T> setLastChecked(int lastChecked);
|
||||
|
||||
/** Packet-thread-only structural state. */
|
||||
int blockID();
|
||||
TrackedTileEntity<T> setBlockID(char blockID);
|
||||
|
||||
/** Packet-thread-only replay state. */
|
||||
T extraData();
|
||||
TrackedTileEntity<T> setExtraData(T extraData);
|
||||
void clearExtraData();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BaseEntitySpawnTask implements EntitySpawnTask {
|
||||
protected final int submittedTick;
|
||||
private @Nullable EntitySpawnTask next;
|
||||
|
||||
protected BaseEntitySpawnTask(int submittedTick) {
|
||||
this.submittedTick = submittedTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getSubmittedTick() {
|
||||
return submittedTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @Nullable EntitySpawnTask getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setNext(@Nullable EntitySpawnTask next) {
|
||||
if (next == this) {
|
||||
Logger.errorAndReturn(new IllegalArgumentException("A FutureNettyTask cannot link to itself: " + this), 1, BaseEntitySpawnTask.class);
|
||||
}
|
||||
if (this.next != null && next != null) {
|
||||
Logger.errorAndReturn(new IllegalStateException("FutureNettyTask already has a next task. Existing next=" + this.next + ", attempted next=" + next + ", task=" + this), 1, BaseEntitySpawnTask.class);
|
||||
}
|
||||
this.next = next;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
// Not specific to RaycastedAntiESP, could be moved to a more general utils package if needed
|
||||
@NullMarked
|
||||
public record BuildProperties(String gitHashLong, String gitHashShort, String buildTime, Version version) {
|
||||
public static final BuildProperties CORE = fromResource("build-properties/core.yml");
|
||||
public static final BuildProperties PLATFORM = fromResource("build-properties/platform.yml");
|
||||
public static final BuildProperties LOGGER = fromResource("build-properties/logging.yml");
|
||||
public static final BuildProperties LOCATABLES = fromResource("build-properties/locatable-lib.yml");
|
||||
|
||||
public static BuildProperties fromResource(String resourcePath) {
|
||||
try (InputStream inputStream = BuildProperties.class.getClassLoader().getResourceAsStream(resourcePath)) {
|
||||
if (inputStream == null) {
|
||||
Logger.error(new IllegalArgumentException("BuildProperties resource not found: " + resourcePath), 2, BuildProperties.class);
|
||||
return error();
|
||||
}
|
||||
|
||||
String shortGit = null;
|
||||
String longGit = null;
|
||||
String buildTime = null;
|
||||
Version version = null;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String trimmedLine = line.trim();
|
||||
if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) continue;
|
||||
|
||||
String[] parts = trimmedLine.split(":", 2);
|
||||
if (parts.length != 2) continue;
|
||||
|
||||
String key = parts[0].trim();
|
||||
String value = parts[1].trim();
|
||||
|
||||
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.substring(1, value.length() - 1);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case "short-git" -> shortGit = value;
|
||||
case "long-git" -> longGit = value;
|
||||
case "build-time" -> buildTime = value;
|
||||
case "version" -> version = Version.parse(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shortGit == null || longGit == null || buildTime == null || version == null) {
|
||||
Logger.error(new IllegalArgumentException("Missing required build properties in resource: " + resourcePath + ". Found shortGit=" + shortGit + ", longGit=" + longGit + ", buildTime=" + buildTime + ", version=" + version), 2, BuildProperties.class);
|
||||
return error();
|
||||
}
|
||||
return new BuildProperties(longGit, shortGit, buildTime, version);
|
||||
} catch (Exception e) {
|
||||
Logger.error(new IllegalArgumentException("Failed to parse BuildProperties resource: " + resourcePath, e), 2, BuildProperties.class);
|
||||
return error();
|
||||
}
|
||||
}
|
||||
|
||||
private static BuildProperties error() {
|
||||
return new BuildProperties("unknown", "unknown", "unknown", new Version(-1, -1, -1, true));
|
||||
}
|
||||
|
||||
public record Version(short major, short minor, short patch, boolean snapshot) implements Comparable<Version> {
|
||||
public Version(int major, int minor, int patch, boolean snapshot) {
|
||||
this((short) major, (short) minor, (short) patch, snapshot);
|
||||
}
|
||||
|
||||
public static Version parse(String versionString) {
|
||||
String[] parts = versionString.replaceFirst("[+-].*$", "").split("\\.");
|
||||
if (parts.length != 3) {
|
||||
throw new IllegalArgumentException("Version string must be in the format 'major.minor.patch'. Attempted: " + versionString);
|
||||
}
|
||||
try {
|
||||
short major = Short.parseShort(parts[0]);
|
||||
short minor = Short.parseShort(parts[1]);
|
||||
short patch = Short.parseShort(parts[2]);
|
||||
boolean snapshot = versionString.contains("SNAPSHOT");
|
||||
return new Version(major, minor, patch, snapshot);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Version parts must be valid short integers. Attempted: " + versionString, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version other) {
|
||||
int majorDifference = Short.compare(major, other.major);
|
||||
if (majorDifference != 0) return majorDifference;
|
||||
|
||||
int minorDifference = Short.compare(minor, other.minor);
|
||||
if (minorDifference != 0) return minorDifference;
|
||||
|
||||
return Short.compare(patch, other.patch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* A Set-like data structure that stores canonical instances of key values.
|
||||
* Any compatible key type with {@code equals} and {@code hashcode} implemented identically to the value type may be used for lookup,
|
||||
* but only canonical values of type {@code V} may be stored.
|
||||
*
|
||||
* @param <K> key type used for lookup
|
||||
* @param <V> stored canonical value type
|
||||
*/
|
||||
public interface CanonicalSet<K, V extends K> {
|
||||
int size();
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
boolean contains(K keyValue);
|
||||
|
||||
@Nullable V get(K keyValue);
|
||||
|
||||
@Nullable V add(V keyValue);
|
||||
|
||||
void addAll(Set<? extends V> keyValues);
|
||||
|
||||
@Nullable V computeIfAbsent(K keyValue, @NotNull Function<? super K, ? extends V> mappingFunction);
|
||||
|
||||
@Nullable V remove(K keyValue);
|
||||
|
||||
void clear();
|
||||
|
||||
@NotNull Set<V> keySet();
|
||||
|
||||
@NotNull Collection<V> values();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public interface Clearable {
|
||||
/**
|
||||
* Dereferences all internal references to other objects, allowing them to be garbage collected. In theory this isn't needed but idk what's causing the memory leak so we're covering all bases.
|
||||
*/
|
||||
void clear();
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ConcurrentSelfMap<K, V extends K> implements CanonicalSet<K, V> {
|
||||
private final ConcurrentHashMap<V, V> backingMap = new ConcurrentHashMap<>();
|
||||
|
||||
public ConcurrentSelfMap() {}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return backingMap.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return backingMap.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(K keyValue) {
|
||||
return backingMap.containsKey(keyValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable V get(K keyValue) {
|
||||
return backingMap.get(keyValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable V add(V keyValue) {
|
||||
return backingMap.put(keyValue, keyValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(Set<? extends V> keyValues) {
|
||||
for (V keyValue : keyValues) {
|
||||
backingMap.put(keyValue, keyValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable V computeIfAbsent(
|
||||
K keyValue,
|
||||
@NotNull Function<? super K, ? extends V> mappingFunction
|
||||
) {
|
||||
V existing = backingMap.get(keyValue);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
V canonicalValue = mappingFunction.apply(keyValue);
|
||||
if (canonicalValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!canonicalValue.equals(keyValue)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Computed canonical value must be equal to the key value."
|
||||
);
|
||||
}
|
||||
|
||||
V racedValue = backingMap.putIfAbsent(canonicalValue, canonicalValue);
|
||||
return racedValue != null ? racedValue : canonicalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable V remove(K keyValue) {
|
||||
return backingMap.remove(keyValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
backingMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<V> keySet() {
|
||||
return backingMap.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<V> values() {
|
||||
return backingMap.values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* For runnable tasks which should be run immediately after an entity is spawned.
|
||||
*/
|
||||
public interface EntitySpawnTask extends Runnable {
|
||||
int TICKS_BEFORE_EVICTION = 16;
|
||||
|
||||
int getSubmittedTick();
|
||||
|
||||
default boolean thisShouldBeEvicted(int currentTick) {
|
||||
return ( currentTick - getSubmittedTick() ) >= TICKS_BEFORE_EVICTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the provided task to the end of this linked task chain.
|
||||
*/
|
||||
default void appendLinkedTask(EntitySpawnTask task) {
|
||||
EntitySpawnTask current = this;
|
||||
while (current.getNext() != null) {
|
||||
current = current.getNext();
|
||||
}
|
||||
current.setNext(task);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the first task in this chain that should not be evicted yet, or null if all tasks should be evicted.
|
||||
*/
|
||||
@Nullable
|
||||
default EntitySpawnTask trimExpiredTasks(int currentTick) {
|
||||
EntitySpawnTask current = this;
|
||||
while (current != null && current.thisShouldBeEvicted(currentTick)) {
|
||||
Logger.warning("A task was evicted from the Netty task queue due to being too old! This should not happen under normal circumstances and may indicate a problem with the system being overloaded or tasks taking too long to execute. Current tick=" + currentTick + " Task=" + current, 3, EntitySpawnTask.class);
|
||||
EntitySpawnTask next = current.getNext();
|
||||
current.setNext(null);
|
||||
try {
|
||||
current.run(); // perhaps the task is salvageable even if we missed the correct caller
|
||||
} catch (Exception e) {
|
||||
Logger.error("Error while running evicted future netty task " + current, e, 3, EntitySpawnTask.class);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
default void runLinkedTasks() {
|
||||
EntitySpawnTask current = this;
|
||||
while (current != null) {
|
||||
EntitySpawnTask next = current.getNext();
|
||||
current.setNext(null);
|
||||
try {
|
||||
current.run();
|
||||
} catch (Exception e) {
|
||||
Logger.error("Error while running future netty task " + current, e, 3, EntitySpawnTask.class);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows linking of tasks into lists for each entity, so that when an entity is processed, all pending tasks for that entity can be processed at once.
|
||||
* @return the next task in the list, or null if this is the end of the list. Order of tasks is guaranteed to be in ascending order of submitted tick.
|
||||
*/
|
||||
@Nullable EntitySpawnTask getNext();
|
||||
|
||||
/**
|
||||
* Sets the next task in the linked task chain.
|
||||
* Passing null is allowed and is used when detaching already-linked tasks before eviction or execution.
|
||||
* <p>
|
||||
* This should generally not be called directly, use {@link #appendLinkedTask} to link tasks together and let the system handle detaching when necessary.
|
||||
*/
|
||||
void setNext(@Nullable EntitySpawnTask next);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.*; /**
|
||||
* {@code int[]} fields annotated with this are backing arrays for {@code IntArrayLists}. {@code IntArrayLists} are not objects directly, instead just an {@code int[]} array, with static operations provided by {@link PrimitiveIntArrayList}.
|
||||
* <p>
|
||||
* This is used to avoid the overhead of an actual object for each {@link PrimitiveIntArrayList}. To further reduce overhead, the field may not be initialised, {@link PrimitiveIntArrayList} is null safe.
|
||||
*
|
||||
* <p> Do not use this array directly, all calls should go through {@link PrimitiveIntArrayList}.
|
||||
*/
|
||||
@Documented @Retention(RetentionPolicy.SOURCE) @Target({ElementType.TYPE_USE, ElementType.FIELD, ElementType.PARAMETER})
|
||||
public @interface IntArrayListMarker {}
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An intrusive doubly linked node designed for a single-writer,
|
||||
* multiple-reader access pattern.
|
||||
*
|
||||
* <h2>Concurrency model</h2>
|
||||
* <ul>
|
||||
* <li>Exactly one writer may modify a list.</li>
|
||||
* <li>Readers may traverse forward concurrently.</li>
|
||||
* <li>Readers must not inspect {@code previousWriterOnly()}.</li>
|
||||
* <li>The writer must not reuse a removed node until all readers that
|
||||
* could still hold that node have quiesced.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Forward links are published with release semantics and read with
|
||||
* acquire semantics. The backward link is plain because only the writer
|
||||
* may access it.</p>
|
||||
*
|
||||
* <p>A common layout uses a permanent sentinel node. Data nodes are placed
|
||||
* after the sentinel, and the sentinel itself is never unlinked.</p>
|
||||
*
|
||||
* @param <T> the concrete node type
|
||||
*/
|
||||
public abstract class InvasivelyLinkedSWMRList<T extends InvasivelyLinkedSWMRList<T>> implements Iterable<T> {
|
||||
|
||||
private T next; private static final VarHandle NEXT = VarHandler.get(InvasivelyLinkedSWMRList.class, "next", InvasivelyLinkedSWMRList.class);
|
||||
private T previous;
|
||||
|
||||
/**
|
||||
* Returns this object with its concrete node type.
|
||||
*
|
||||
* <p>An implementation must return {@code this}:</p>
|
||||
*
|
||||
* <pre>{@code
|
||||
* @Override
|
||||
* protected MyNode self() {
|
||||
* return this;
|
||||
* }
|
||||
* }</pre>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected final T self() {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to private fields {@code next} and {@code previous}. They are only accessible from within this class, not subclasses.
|
||||
*/
|
||||
private static <N extends InvasivelyLinkedSWMRList<N>> InvasivelyLinkedSWMRList<N> linksOf(N node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next node using acquire semantics.
|
||||
*
|
||||
* <p>This is the forward-link operation intended for concurrent
|
||||
* readers.</p>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final T nextAcquire() {
|
||||
return (T) NEXT.getAcquire(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next node without memory ordering.
|
||||
*
|
||||
* <p>Only the single writer may call this method.</p>
|
||||
*/
|
||||
private T nextWriterOnly() {
|
||||
return next;
|
||||
}
|
||||
|
||||
private void setNextRelease(T value) {
|
||||
NEXT.setRelease(this, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preceding node.
|
||||
*
|
||||
* <p>Only the single writer may call this method. Concurrent readers
|
||||
* must not use the backward link.</p>
|
||||
*/
|
||||
public final T previousWriterOnly() {
|
||||
return previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports whether this node has a predecessor.
|
||||
*
|
||||
* <p>Only the single writer may call this method. A permanent sentinel
|
||||
* normally has no predecessor and therefore returns {@code false}.</p>
|
||||
*/
|
||||
public final boolean isLinkedWriterOnly() {
|
||||
return previous != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports whether both intrusive links are clear.
|
||||
*
|
||||
* <p>This does not prove that no reader still holds the node. Node
|
||||
* lifetime and reader quiescence must be managed separately.</p>
|
||||
*/
|
||||
public final boolean isDetachedWriterOnly() {
|
||||
return previous == null && nextWriterOnly() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts {@code node} directly after this node.
|
||||
*
|
||||
* <p>Only the single writer may call this method.</p>
|
||||
*
|
||||
* <p>The inserted node must:</p>
|
||||
* <ul>
|
||||
* <li>not be this node;</li>
|
||||
* <li>have both intrusive links clear;</li>
|
||||
* <li>not be visible to any reader;</li>
|
||||
* <li>not belong to another list.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>The release store to this node's forward link is the insertion
|
||||
* linearisation point. A reader that observes the inserted node through
|
||||
* {@link #nextAcquire()} also observes writes made to the node before
|
||||
* insertion.</p>
|
||||
*
|
||||
* @param node detached node to insert
|
||||
* @throws NullPointerException if {@code node} is null
|
||||
* @throws IllegalArgumentException if asked to insert this node
|
||||
* @throws IllegalStateException if {@code node} appears linked
|
||||
*/
|
||||
public final void linkAfter(T node) {
|
||||
Objects.requireNonNull(node, "node");
|
||||
|
||||
T self = self();
|
||||
|
||||
if (node == self) {
|
||||
throw new IllegalArgumentException("A node cannot be linked after itself");
|
||||
}
|
||||
|
||||
InvasivelyLinkedSWMRList<T> nodeLinks = linksOf(node);
|
||||
|
||||
if (nodeLinks.previous != null || nodeLinks.nextWriterOnly() != null) {
|
||||
throw new IllegalStateException("The node is already linked or is not detached");
|
||||
}
|
||||
|
||||
T oldNext = nextWriterOnly();
|
||||
|
||||
if (node == oldNext) {
|
||||
throw new IllegalStateException("The node is already the current successor");
|
||||
}
|
||||
|
||||
/*
|
||||
* Fully initialise the inserted node before publishing it.
|
||||
*/
|
||||
nodeLinks.previous = self;
|
||||
nodeLinks.next = oldNext;
|
||||
|
||||
if (oldNext != null) {
|
||||
InvasivelyLinkedSWMRList<T> oldNextLinks = linksOf(oldNext);
|
||||
oldNextLinks.previous = node;
|
||||
}
|
||||
|
||||
/*
|
||||
* Publication and insertion linearisation point.
|
||||
*/
|
||||
setNextRelease(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this node from its current list.
|
||||
*
|
||||
* <p>Only the single writer may call this method.</p>
|
||||
*
|
||||
* <p>The node must have a predecessor. This rule prevents accidental
|
||||
* removal of a permanent sentinel and avoids the need to update an
|
||||
* external head reference.</p>
|
||||
*
|
||||
* <p>A concurrent reader may still:</p>
|
||||
* <ul>
|
||||
* <li>return this node after it has been removed;</li>
|
||||
* <li>continue from this node to its former successor;</li>
|
||||
* <li>observe the cleared forward link and stop early.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>The removed node must not be modified, reused, or inserted again
|
||||
* until every reader that could hold it has quiesced.</p>
|
||||
*
|
||||
* @return the node that followed this node, or {@code null}
|
||||
* @throws IllegalStateException if this node has no predecessor
|
||||
*/
|
||||
public final T unlink() {
|
||||
T oldPrevious = previous;
|
||||
|
||||
if (oldPrevious == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot unlink a detached node or sentinel node"
|
||||
);
|
||||
}
|
||||
|
||||
T oldNext = nextWriterOnly();
|
||||
|
||||
/*
|
||||
* Update the writer-only backward link first. The following release
|
||||
* store also publishes this change, though readers must not depend
|
||||
* on it.
|
||||
*/
|
||||
if (oldNext != null) {
|
||||
InvasivelyLinkedSWMRList<T> oldNextLinks = linksOf(oldNext);
|
||||
oldNextLinks.previous = oldPrevious;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bypass this node. This is the removal linearisation point.
|
||||
*/
|
||||
InvasivelyLinkedSWMRList<T> previousLinks = linksOf(oldPrevious);
|
||||
previousLinks.setNextRelease(oldNext);
|
||||
|
||||
/*
|
||||
* Clear this node after it has been bypassed. Release semantics are
|
||||
* stronger than strictly required here, but they keep the ordering
|
||||
* rules simple and explicit.
|
||||
*/
|
||||
previous = null;
|
||||
setNextRelease(null);
|
||||
|
||||
return oldNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches a list head after its owner has published a replacement head.
|
||||
*
|
||||
* <p>Only the single writer may call this method. Concurrent readers that already hold the old head may either
|
||||
* continue to the former successor or stop at the cleared link, matching the weakly-consistent iterator contract.</p>
|
||||
*/
|
||||
public final T detachHeadWriterOnly() {
|
||||
if (previous != null) {
|
||||
throw new IllegalStateException("Only a list head may be detached with this method");
|
||||
}
|
||||
T oldNext = nextWriterOnly();
|
||||
if (oldNext != null) {
|
||||
linksOf(oldNext).previous = null;
|
||||
}
|
||||
setNextRelease(null);
|
||||
return oldNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a weakly consistent forward iterator beginning with this node.
|
||||
*
|
||||
* <p>The iterator does not create a snapshot. During concurrent writes
|
||||
* it may miss inserted nodes, return removed nodes, or stop early after
|
||||
* reaching a removed node. It does not throw
|
||||
* {@link java.util.ConcurrentModificationException}.</p>
|
||||
*/
|
||||
@Override
|
||||
public final @NotNull Iterator<T> iterator() {
|
||||
return new Iterator<>() {
|
||||
private T next = self();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
T result = next;
|
||||
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
next = result.nextAcquire();
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongObjectBiConsumer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongPredicate;
|
||||
|
||||
/**
|
||||
* A small thread-safe utility map for primitive {@code long} keys backed by a {@link StampedLock} and a {@link Long2ObjectOpenHashMap}.
|
||||
*
|
||||
* <p>Reads use optimistic locking where possible. Mutations use the write lock. Tests indicate that
|
||||
* even under heavy read-write contention, optimistic reading works almost all the time.
|
||||
*
|
||||
* <p>Callback-based methods such as {@link #computeIfAbsent(long, LongFunction)}, {@link #forEach(LongObjectBiConsumer)},
|
||||
* and {@link #removeIfKey(LongPredicate)} run their callbacks while holding the write lock, so those
|
||||
* callbacks must not call back into this same map instance or deadlock may occur as StampedLock is not reentrant.
|
||||
*
|
||||
* <p>This class only synchronizes access to the map structure itself. Stored values are returned by
|
||||
* reference and are not made thread-safe by this map.
|
||||
*
|
||||
* @param <V> the type of mapped values
|
||||
*/
|
||||
public class Long2ObjectMTHashMap<V> {
|
||||
private final Long2ObjectOpenHashMap<V> backingMap;
|
||||
private final StampedLock lock = new StampedLock();
|
||||
private final ThreadLocal<Integer> writeLockedCallbackDepth = ThreadLocal.withInitial(() -> 0);
|
||||
|
||||
public Long2ObjectMTHashMap(final int expected, final float loadFactor) {
|
||||
this.backingMap = new Long2ObjectOpenHashMap<>(expected, loadFactor);
|
||||
}
|
||||
|
||||
public Long2ObjectMTHashMap(final int expected) {
|
||||
this(expected, Hash.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public Long2ObjectMTHashMap() {
|
||||
this(Hash.DEFAULT_INITIAL_SIZE, Hash.DEFAULT_LOAD_FACTOR);
|
||||
}
|
||||
|
||||
public V get(final long key) {
|
||||
long stamp = lock.tryOptimisticRead();
|
||||
V value = backingMap.get(key);
|
||||
if (failsValidation(stamp)) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
stamp = lock.readLock();
|
||||
try {
|
||||
value = backingMap.get(key);
|
||||
} finally {
|
||||
lock.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public V getOrDefault(final long key, final V defaultValue) {
|
||||
long stamp = lock.tryOptimisticRead();
|
||||
V value = getOrDefaultInternal(key, defaultValue);
|
||||
if (failsValidation(stamp)) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
stamp = lock.readLock();
|
||||
try {
|
||||
value = getOrDefaultInternal(key, defaultValue);
|
||||
} finally {
|
||||
lock.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean containsKey(final long key) {
|
||||
long stamp = lock.tryOptimisticRead();
|
||||
boolean contains = backingMap.containsKey(key);
|
||||
if (failsValidation(stamp)) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
stamp = lock.readLock();
|
||||
try {
|
||||
contains = backingMap.containsKey(key);
|
||||
} finally {
|
||||
lock.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return contains;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
long stamp = lock.tryOptimisticRead();
|
||||
int size = backingMap.size();
|
||||
if (failsValidation(stamp)) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
stamp = lock.readLock();
|
||||
try {
|
||||
size = backingMap.size();
|
||||
} finally {
|
||||
lock.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
long stamp = lock.tryOptimisticRead();
|
||||
boolean empty = backingMap.isEmpty();
|
||||
if (failsValidation(stamp)) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
stamp = lock.readLock();
|
||||
try {
|
||||
empty = backingMap.isEmpty();
|
||||
} finally {
|
||||
lock.unlockRead(stamp);
|
||||
}
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
public V put(final long key, final V value) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
return backingMap.put(key, value);
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public V putIfAbsent(final long key, final V value) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
if (backingMap.containsKey(key)) {
|
||||
return backingMap.get(key);
|
||||
}
|
||||
backingMap.put(key, value);
|
||||
return null;
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public V replace(final long key, final V value) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
if (!backingMap.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
return backingMap.put(key, value);
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean replace(final long key, final V oldValue, final V value) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
if (!backingMap.containsKey(key) || !Objects.equals(backingMap.get(key), oldValue)) {
|
||||
return false;
|
||||
}
|
||||
backingMap.put(key, value);
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public V remove(final long key) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
return backingMap.remove(key);
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(final long key, final Object value) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
if (!backingMap.containsKey(key) || !Objects.equals(backingMap.get(key), value)) {
|
||||
return false;
|
||||
}
|
||||
backingMap.remove(key);
|
||||
return true;
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
backingMap.clear();
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public V computeIfAbsent(final long key, final LongFunction<? extends V> mappingFunction) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
Objects.requireNonNull(mappingFunction, "mappingFunction");
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
if (backingMap.containsKey(key)) {
|
||||
return backingMap.get(key);
|
||||
}
|
||||
|
||||
V value = invokeWriteLockedCallback(() -> mappingFunction.apply(key));
|
||||
backingMap.put(key, value);
|
||||
return value;
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public void forEach(final LongObjectBiConsumer<? super V> consumer) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
ObjectIterator<Long2ObjectMap.Entry<V>> iterator = backingMap.long2ObjectEntrySet().fastIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Long2ObjectMap.Entry<V> entry = iterator.next();
|
||||
invokeWriteLockedCallback(() -> {
|
||||
consumer.accept(entry.getLongKey(), entry.getValue());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
public int removeIfKey(final LongPredicate predicate) {
|
||||
assertNoWriteLockedCallbackReentry();
|
||||
Objects.requireNonNull(predicate, "predicate");
|
||||
|
||||
long stamp = lock.writeLock();
|
||||
try {
|
||||
int removed = 0;
|
||||
ObjectIterator<Long2ObjectMap.Entry<V>> iterator = backingMap.long2ObjectEntrySet().fastIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Long2ObjectMap.Entry<V> entry = iterator.next();
|
||||
if (invokeWriteLockedCallback(() -> predicate.test(entry.getLongKey()))) {
|
||||
iterator.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
} finally {
|
||||
lock.unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
private V getOrDefaultInternal(final long key, final V defaultValue) {
|
||||
V value = backingMap.get(key);
|
||||
return value != null || backingMap.containsKey(key) ? value : defaultValue;
|
||||
}
|
||||
|
||||
private void assertNoWriteLockedCallbackReentry() {
|
||||
if (writeLockedCallbackDepth.get() > 0) {
|
||||
throw new IllegalStateException(
|
||||
"Callbacks executed under the write lock must not reenter this Long2ObjectMTHashMap instance."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T invokeWriteLockedCallback(final Long2ObjectMTHashMapCallback<T> callback) {
|
||||
writeLockedCallbackDepth.set(writeLockedCallbackDepth.get() + 1);
|
||||
try {
|
||||
return callback.invoke();
|
||||
} finally {
|
||||
int depth = writeLockedCallbackDepth.get() - 1;
|
||||
if (depth == 0) {
|
||||
writeLockedCallbackDepth.remove();
|
||||
} else {
|
||||
writeLockedCallbackDepth.set(depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final AtomicInteger successfulOptimisticReads = new AtomicInteger();
|
||||
final AtomicInteger failedOptimisticReads = new AtomicInteger();
|
||||
|
||||
private boolean failsValidation(long stamp) {
|
||||
boolean valid = lock.validate(stamp);
|
||||
if (!valid) {
|
||||
failedOptimisticReads.incrementAndGet();
|
||||
} else {
|
||||
successfulOptimisticReads.incrementAndGet();
|
||||
}
|
||||
return !valid;
|
||||
|
||||
//return !lock.validate(stamp);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Long2ObjectMTHashMapCallback<T> {
|
||||
T invoke();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Packet {
|
||||
//todo note: spawn living entity and painting are really old and no longer used, delete them from code maybe
|
||||
enum Packets {
|
||||
@Until("1.9")
|
||||
SPAWN_LIVING_ENTITY("N/A", "WrapperPlayServerSpawnEntityLiving"),
|
||||
SPAWN_ENTITY("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Spawn_Entity", "WrapperPlayServerSpawnEntity"), //Note does not fire for self player
|
||||
ENTITY_ANIMATION("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Entity_Animation", "WrapperPlayServerEntityAnimation"),
|
||||
ENTITY_EVENT("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Entity_Event", "WrapperPlayServerEntityStatus"),
|
||||
HURT_ANIMATION("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Hurt_Animation", "WrapperPlayServerHurtAnimation"),
|
||||
UPDATE_ATTRIBUTES("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Update_Attributes", "WrapperPlayServerUpdateAttributes"),
|
||||
LEASH_ENTITY("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Link_Entities", "WrapperPlayServerAttachEntity"), //Note in 1.8 and below this was also used for setting passengers
|
||||
ENTITY_EQUIPMENT("https://minecraft.wiki/w/Java_Edition_protocol/Packets#Set_Equipment", "WrapperPlayServerEntityEquipment"),
|
||||
;
|
||||
|
||||
Packets(String wikiURL, String PEName) {
|
||||
}
|
||||
}
|
||||
|
||||
Packets value();
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface Since {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface Until {
|
||||
String value();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
/**
|
||||
* Static utility class for operations on int arrays annotated with {@link IntArrayListMarker}, which are intended to be used as lists of integers without the overhead of autoboxing.
|
||||
* <p>
|
||||
* {@link IntArrayListMarker} fields may be null or non-initialised to save memory, {@code IntArrayList} methods will treat null or non-initialised arrays as empty lists.
|
||||
* <p>
|
||||
* Arrays expand and contract as needed such that the length of the backing array is always equal to the number of elements in the list, so there is no extra capacity. This means that adding or removing elements from the list will involve creating a new array and copying the existing elements, which can be inefficient for large lists. However, this design choice was made to save memory and avoid the overhead of maintaining a separate size field and capacity management logic.
|
||||
*/
|
||||
public class PrimitiveIntArrayList {
|
||||
private PrimitiveIntArrayList() {}
|
||||
|
||||
public static int size(int@IntArrayListMarker[] array) {
|
||||
return array == null ? 0 : array.length;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(int@IntArrayListMarker[] array) {
|
||||
return array == null || array.length == 0;
|
||||
}
|
||||
|
||||
public static boolean contains(int@IntArrayListMarker[] array, int value) {
|
||||
if (array == null) return false;
|
||||
for (int i : array) {
|
||||
if (i == value) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caller of this method <b>must</b> reassign the returned array to the original array reference, as the original array will not be modified and a new array with the added element will be returned.
|
||||
*/
|
||||
public static int@IntArrayListMarker[] add(int@IntArrayListMarker[] array, int value) {
|
||||
if (array == null) {
|
||||
return new int[]{value};
|
||||
} else {
|
||||
int[] newArray = new int[array.length + 1];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
newArray[array.length] = value;
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Caller of this method <b>must</b> reassign the returned array to the original array reference, as the original array will not be modified and a new array with the added element will be returned.
|
||||
*/
|
||||
public static int@IntArrayListMarker[] remove(int@IntArrayListMarker[] array, int value) {
|
||||
if (array == null) return null;
|
||||
int index = -1;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == value) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == -1) return array; // value not found, return original array
|
||||
int[] newArray = new int[array.length - 1];
|
||||
System.arraycopy(array, 0, newArray, 0, index);
|
||||
System.arraycopy(array, index + 1, newArray, index, array.length - index - 1);
|
||||
return newArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Caller of this method <b>must</b> reassign the returned array to the original array reference, as the original array will not be modified and a new array with the added element will be returned.
|
||||
*/
|
||||
public static int@IntArrayListMarker[] clear(int@IntArrayListMarker[] array) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int get(int@IntArrayListMarker[] array, int index) {
|
||||
if (array == null) Logger.errorAndReturn(new IndexOutOfBoundsException("Attempted to find value at index: " + index + ", for IntArrayList with size: 0"), 3, PrimitiveIntArrayList.class);
|
||||
if (index < 0 || index >= array.length) Logger.errorAndReturn(new IndexOutOfBoundsException("Attempted to find value at index: " + index + ", for IntArrayList with size: " + size(array)), 3, PrimitiveIntArrayList.class);
|
||||
return array[index];
|
||||
}
|
||||
|
||||
public static int@IntArrayListMarker[] set(int@IntArrayListMarker[] array, int index, int value) {
|
||||
array[index] = value;
|
||||
return array;
|
||||
}
|
||||
|
||||
public static int[] getCopyOrNull(int@IntArrayListMarker[] array) {
|
||||
if (size(array) == 0) return null;
|
||||
int[] copy = new int[array.length];
|
||||
System.arraycopy(array, 0, copy, 0, array.length);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static String toString(int@IntArrayListMarker[] array) {
|
||||
if (array == null) return "[]";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
sb.append(array[i]);
|
||||
if (i < array.length - 1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
/**
|
||||
* Classes where specific methods must be called from a single thread can extend this class and call {@link #guardThread()}
|
||||
* at the start of those methods to ensure that they are only called from the permitted thread.
|
||||
*/
|
||||
public abstract class SingleThreadedGuard {
|
||||
private final Thread permittedThread;
|
||||
|
||||
protected SingleThreadedGuard(Thread thread) {
|
||||
permittedThread = thread;
|
||||
}
|
||||
|
||||
protected void guardThread() {
|
||||
if (Thread.currentThread() != permittedThread) {
|
||||
throw new IllegalStateException("Method called from wrong thread. Expected: " + permittedThread + ", actual: " + Thread.currentThread());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public class ThreadGuard {
|
||||
public static final boolean ASSERTIONS_ENABLED = areAssertionsEnabled();
|
||||
|
||||
@SuppressWarnings("PointlessBooleanExpression")
|
||||
/**
|
||||
* @return true if assertions are enabled, false otherwise
|
||||
*/
|
||||
private static boolean areAssertionsEnabled() {
|
||||
try {
|
||||
assert true == false; // can be simplified to assert false but this reads more clearly to me as a statement which will fail.
|
||||
return false;
|
||||
} catch (AssertionError e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
/** Just a shorter alias of useful methods from ConcurrentUtil**/
|
||||
public final class VarHandler {
|
||||
public static final VarHandle BYTE_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(byte[].class);
|
||||
public static final VarHandle CHAR_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(char[].class);
|
||||
public static final VarHandle LONG_ARRAY_HANDLE = ConcurrentUtil.getArrayHandle(long[].class);
|
||||
|
||||
private VarHandler() {}
|
||||
|
||||
public static VarHandle get(Class<?> classOf, String fieldName, Class<?> fieldClass) {
|
||||
return ConcurrentUtil.getVarHandle(classOf, fieldName, fieldClass);
|
||||
}
|
||||
|
||||
public static VarHandle $tatic(Class<?> classOf, String fieldName, Class<?> fieldClass) {
|
||||
return ConcurrentUtil.getStaticVarHandle(classOf, fieldName, fieldClass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRInt2ObjectHashTable;
|
||||
import games.cubi.locatables.api.BlockLocatable;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.raycastedantiesp.core.utils.InvasivelyLinkedSWMRList;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
import games.cubi.raycastedantiesp.core.view.chunks.BlockChunkSectionStore;
|
||||
import games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore;
|
||||
import games.cubi.raycastedantiesp.core.view.chunks.OccludingChunkSectionStore;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.packUncheckedGuarded;
|
||||
|
||||
public abstract class AbstractBlockView<R extends Clearable, T extends NettyTileEntity<R>> implements BlockView {
|
||||
public static final int CHUNK_SIZE = 16;
|
||||
public static final int LOCAL_MASK = CHUNK_SIZE - 1;
|
||||
|
||||
private final ChunkSectionStore chunks;
|
||||
private final boolean trackAllBlocks;
|
||||
/**
|
||||
* The int key represents a packed chunk column bucket, with (signed) 16 bits allocated for x and z respectively. While chunk columns over 60k chunks apart may overlap, this is unlikely to ever actually occur.
|
||||
* <p> {@code NettyTileEntity<R>} is an {@link InvasivelyLinkedSWMRList}, so all tile entities in the column chain from the head entry.
|
||||
* <p> Since direct access to this object outside {@link AbstractBlockView} is impossible, a marker head object is skipped, and head removal is handled separately.
|
||||
* **/
|
||||
private final SWMRInt2ObjectHashTable<NettyTileEntity<R>> knownTileEntitiesByColumnBucket = new SWMRInt2ObjectHashTable<>();
|
||||
private final PackedBlockTransitionQueue transitions = new PackedBlockTransitionQueue();
|
||||
private final IntSupplier worldEpochSupplier;
|
||||
private volatile UUID trackedWorld;
|
||||
// Bit 0 is enabled; higher bits are a generation. The generation prevents enabled -> disabled -> enabled ABA from
|
||||
// accepting an old raycast and also tags transitions that may be drained after their originating mode was replaced.
|
||||
private volatile long tileEntityCheckModeToken; private static final VarHandle TILE_ENTITY_CHECK_MODE_TOKEN = VarHandler.get(AbstractBlockView.class, "tileEntityCheckModeToken", long.class);
|
||||
|
||||
protected AbstractBlockView(BlockInfoResolver blockInfoResolver, boolean trackAllBlocks, IntSupplier worldEpochSupplier) {
|
||||
Logger.requireNonNull(blockInfoResolver, "blockInfoResolver was null", 1, AbstractBlockView.class);
|
||||
Logger.requireNonNull(worldEpochSupplier, "worldEpochSupplier was null", 1, AbstractBlockView.class);
|
||||
this.trackAllBlocks = trackAllBlocks;
|
||||
this.worldEpochSupplier = worldEpochSupplier;
|
||||
this.chunks = trackAllBlocks
|
||||
? new BlockChunkSectionStore(blockInfoResolver)
|
||||
: new OccludingChunkSectionStore(blockInfoResolver);
|
||||
}
|
||||
|
||||
protected abstract T createTrackedTileEntity(BlockSpatial position, char blockID, boolean visible);
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ) {
|
||||
return chunks.getSection(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockOccluding(int x, int y, int z) {
|
||||
return chunks.isOccluding(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockOccluding(BlockLocatable location) {
|
||||
if (location == null || !isTrackedWorld(location.world())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isBlockOccluding(location.blockX(), location.blockY(), location.blockZ());
|
||||
}
|
||||
|
||||
public int loadedChunkCount() {
|
||||
return chunks.loadedSectionCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T updateOrInsertTileEntity(UUID world, BlockSpatial position, char blockID, boolean visibleIfNew) {
|
||||
if (position == null || !ensureTrackedWorld(world)) {
|
||||
return null;
|
||||
}
|
||||
SWMRInt2ObjectHashTable<NettyTileEntity<R>> map = knownTileEntitiesByColumnBucket;
|
||||
int bucketKey = packColumnBucket(position.chunkX(), position.chunkZ());
|
||||
NettyTileEntity<R> head = map.get(bucketKey);
|
||||
T tileEntity = findTileEntityInBucket(head, position);
|
||||
if (tileEntity == null) {
|
||||
tileEntity = createTrackedTileEntity(position, blockID, visibleIfNew);
|
||||
if (tileEntity == null) {
|
||||
Logger.error("createTrackedTileEntity returned null", 3, AbstractBlockView.class);
|
||||
return null;
|
||||
}
|
||||
if (head == null) {
|
||||
map.put(bucketKey, tileEntity);
|
||||
} else {
|
||||
head.linkAfter(tileEntity);
|
||||
}
|
||||
}
|
||||
tileEntity.clearExtraData();
|
||||
tileEntity.setBlockID(blockID);
|
||||
return tileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTileEntity(UUID world, BlockSpatial position) {
|
||||
if (position == null || !isTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
SWMRInt2ObjectHashTable<NettyTileEntity<R>> map = knownTileEntitiesByColumnBucket;
|
||||
int bucketKey = packColumnBucket(position.chunkX(), position.chunkZ());
|
||||
NettyTileEntity<R> head = map.get(bucketKey);
|
||||
T tileEntity = findTileEntityInBucket(head, position);
|
||||
if (tileEntity != null) {
|
||||
removeNode(map, bucketKey, head, tileEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getTrackedTileEntity(UUID world, BlockSpatial position) {
|
||||
if (position == null || !isTrackedWorld(world)) {
|
||||
return null;
|
||||
}
|
||||
return findTileEntityInBucket(knownTileEntitiesByColumnBucket.get(packColumnBucket(position.chunkX(), position.chunkZ())), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible(UUID world, BlockSpatial position, int currentTick) {
|
||||
if (position == null || !isTrackedWorld(world)) {
|
||||
return true;
|
||||
}
|
||||
T state = getTrackedTileEntity(world, position);
|
||||
return state == null || state.visible();
|
||||
}
|
||||
|
||||
private void commitTileEntityVisibilityDecision(T tileEntity, boolean currentVisibility, boolean shouldBeVisible, int currentTick, long modeToken, int expectedWorldEpoch) {
|
||||
if (!isCurrentWorldEpoch(expectedWorldEpoch) || tileEntityCheckModeTokenAcquire() != modeToken) {
|
||||
return;
|
||||
}
|
||||
if (!modeEnabled(modeToken)) {
|
||||
shouldBeVisible = true;
|
||||
}
|
||||
boolean visibilityChanged = currentVisibility != shouldBeVisible;
|
||||
tileEntity.setVisible(shouldBeVisible);
|
||||
tileEntity.setLastChecked(currentTick);
|
||||
if (visibilityChanged) {
|
||||
BlockViewTransition.Type type = shouldBeVisible ? BlockViewTransition.Type.SHOW : BlockViewTransition.Type.HIDE;
|
||||
transitions.add(type, tileEntity, modeToken, expectedWorldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
// Only used on non-mutation paths
|
||||
public void recordOutboundTileEntityVisibility(TrackedTileEntity<?> tileEntity, boolean visible) {
|
||||
if (tileEntity != null) {
|
||||
tileEntity.setVisible(visible);
|
||||
tileEntity.setLastChecked(TrackedTileEntity.NEVER_CHECKED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTileEntityCheckMode(boolean enabled, int currentTick, Consumer<TrackedTileEntity<?>> visibilityRepairConsumer) {
|
||||
long current = tileEntityCheckModeTokenAcquire();
|
||||
if (modeEnabled(current) == enabled) {
|
||||
return;
|
||||
}
|
||||
// Drop the enabled bit, increment the generation, then restore bit 0 below only for enabled mode.
|
||||
long next = ((current >>> 1) + 1L) << 1;
|
||||
if (enabled) {
|
||||
forEachTileEntity(tileEntity -> tileEntity.setLastChecked(TrackedTileEntity.NEVER_CHECKED));
|
||||
TILE_ENTITY_CHECK_MODE_TOKEN.setRelease(this, next | 1L);
|
||||
return;
|
||||
}
|
||||
|
||||
TILE_ENTITY_CHECK_MODE_TOKEN.setRelease(this, next);
|
||||
forEachTileEntity(tileEntity -> {
|
||||
if (!tileEntity.visible()) {
|
||||
tileEntity.setVisible(true);
|
||||
tileEntity.setLastChecked(currentTick);
|
||||
visibilityRepairConsumer.accept(tileEntity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long tileEntityCheckModeToken() {
|
||||
return tileEntityCheckModeTokenAcquire();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentEnabledTileEntityMode(long modeToken) {
|
||||
return modeEnabled(modeToken) && tileEntityCheckModeTokenAcquire() == modeToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TrackedTileEntity<?>> getKnownTileEntities() {
|
||||
ArrayList<TrackedTileEntity<?>> snapshot = new ArrayList<>();
|
||||
forEachTileEntity(snapshot::add);
|
||||
return List.copyOf(snapshot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int forEachNeedingRecheck(int recheckTicks, int currentTick, Consumer<TrackedTileEntity<?>> action) {
|
||||
return knownTileEntitiesByColumnBucket.forEachValueSummed(head -> {
|
||||
int processed = 0;
|
||||
for (NettyTileEntity<R> tileEntity = head; tileEntity != null; tileEntity = tileEntity.nextAcquire()) {
|
||||
int lastChecked = tileEntity.lastChecked();
|
||||
if (tileEntity.visible() && lastChecked != TrackedTileEntity.NEVER_CHECKED && (recheckTicks < 0 || currentTick - lastChecked < recheckTicks)) {
|
||||
continue;
|
||||
}
|
||||
action.accept(tileEntity);
|
||||
processed++;
|
||||
}
|
||||
return processed;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateVisibilityForEachNeedingRecheck(int recheckTicks, int currentTick, long modeToken, int expectedWorldEpoch, VisibilityResolver action) {
|
||||
if (!isCurrentEnabledTileEntityMode(modeToken) || !isCurrentWorldEpoch(expectedWorldEpoch)) {
|
||||
return 0;
|
||||
}
|
||||
return knownTileEntitiesByColumnBucket.forEachValueSummed(head -> {
|
||||
int processed = 0;
|
||||
for (NettyTileEntity<R> tileEntity = head; tileEntity != null; tileEntity = tileEntity.nextAcquire()) {
|
||||
boolean currentVisibility = tileEntity.visible();
|
||||
int lastChecked = tileEntity.lastChecked();
|
||||
if (currentVisibility && lastChecked != TrackedTileEntity.NEVER_CHECKED && (recheckTicks < 0 || currentTick - lastChecked < recheckTicks)) {
|
||||
continue;
|
||||
}
|
||||
byte shouldBeVisible = action.setVisible(tileEntity);
|
||||
if (shouldBeVisible != VisibilityResolver.SKIPPED) {
|
||||
@SuppressWarnings("unchecked") T typed = (T) tileEntity;
|
||||
commitTileEntityVisibilityDecision(typed, currentVisibility, shouldBeVisible == VisibilityResolver.SHOW, currentTick, modeToken, expectedWorldEpoch);
|
||||
}
|
||||
processed++;
|
||||
}
|
||||
return processed;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPendingTransitions() {
|
||||
return transitions.hasPendingTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushPendingTransitions() {
|
||||
transitions.flushPendingTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drainTransitions(BlockView.TransitionConsumer consumer) {
|
||||
transitions.drainTransitions(consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upsertBlock(UUID world, int x, int y, int z, int blockID) {
|
||||
if (!ensureTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
chunks.setBlockID(x, y, z, blockID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChunk(UUID world, int chunkX, int chunkZ) {
|
||||
if (!isTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
chunks.removeColumn(chunkX, chunkZ);
|
||||
removeTileEntitiesInChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChunkSection(UUID world, int chunkX, int chunkY, int chunkZ) {
|
||||
if (!isTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
chunks.removeSection(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pruneTileEntitiesAbsentFromChunkSections(UUID world, int chunkX, int chunkZ, int minimumSectionY, int sectionCount, long[][] presentBySection) {
|
||||
if (!isTrackedWorld(world) || sectionCount < 0 || (presentBySection != null && presentBySection.length != sectionCount)) {
|
||||
return;
|
||||
}
|
||||
SWMRInt2ObjectHashTable<NettyTileEntity<R>> map = knownTileEntitiesByColumnBucket;
|
||||
int bucketKey = packColumnBucket(chunkX, chunkZ);
|
||||
// The wrapped key selects a collision bucket; full chunk coordinates below establish ownership.
|
||||
NettyTileEntity<R> head = map.get(bucketKey);
|
||||
NettyTileEntity<R> currentHead = head;
|
||||
for (NettyTileEntity<R> current = head; current != null; ) {
|
||||
NettyTileEntity<R> next = current.nextAcquire();
|
||||
if (current.chunkX() == chunkX && current.chunkZ() == chunkZ) {
|
||||
int sectionIndex = current.chunkY() - minimumSectionY;
|
||||
long[] present = sectionIndex >= 0 && sectionIndex < sectionCount && presentBySection != null
|
||||
? presentBySection[sectionIndex]
|
||||
: null;
|
||||
if (sectionIndex < 0 || sectionIndex >= sectionCount || present == null) {
|
||||
currentHead = removeNode(map, bucketKey, currentHead, current);
|
||||
} else {
|
||||
int packed = packUncheckedGuarded(current.blockX(), current.blockY(), current.blockZ());
|
||||
// Guarded packing masks the full coordinates to local x/y/z. The high bits choose the 64-bit word;
|
||||
// Java masks the long shift distance to the low six bits, selecting the bit within that word.
|
||||
if ((present[packed >>> 6] & 1L << packed) == 0L) {
|
||||
currentHead = removeNode(map, bucketKey, currentHead, current);
|
||||
}
|
||||
}
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceChunkSection(UUID world, int chunkX, int chunkY, int chunkZ, BlockChunkData data) {
|
||||
if (!ensureTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
chunks.replaceSection(chunkX, chunkY, chunkZ, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceChunkSectionOcclusion(UUID world, int chunkX, int chunkY, int chunkZ, OccludingChunkData data) {
|
||||
if (trackAllBlocks) {
|
||||
throw new UnsupportedOperationException("Block chunk storage requires full block IDs for section replacement");
|
||||
}
|
||||
if (!ensureTrackedWorld(world)) {
|
||||
return;
|
||||
}
|
||||
chunks.replaceSectionOcclusion(chunkX, chunkY, chunkZ, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
trackedWorld = null;
|
||||
clearTrackedState();
|
||||
}
|
||||
|
||||
private boolean isTrackedWorld(UUID world) {
|
||||
UUID current = trackedWorld;
|
||||
return world != null && current != null && current.equals(world);
|
||||
}
|
||||
|
||||
private boolean ensureTrackedWorld(UUID world) {
|
||||
if (world == null) {
|
||||
return false;
|
||||
}
|
||||
if (world.equals(trackedWorld)) {
|
||||
return true;
|
||||
}
|
||||
trackedWorld = null;
|
||||
clearTrackedState();
|
||||
trackedWorld = world;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void clearTrackedState() {
|
||||
chunks.clear();
|
||||
forEachTileEntity(NettyTileEntity::markRemoved);
|
||||
knownTileEntitiesByColumnBucket.clear();
|
||||
transitions.clearPublishedTransitions();
|
||||
}
|
||||
|
||||
private void removeTileEntitiesInChunk(int chunkX, int chunkZ) {
|
||||
SWMRInt2ObjectHashTable<NettyTileEntity<R>> map = knownTileEntitiesByColumnBucket;
|
||||
int bucketKey = packColumnBucket(chunkX, chunkZ);
|
||||
NettyTileEntity<R> head = map.get(bucketKey);
|
||||
if (head == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean collision = false;
|
||||
for (NettyTileEntity<R> current = head; current != null; current = current.nextAcquire()) {
|
||||
if (current.chunkX() != chunkX || current.chunkZ() != chunkZ) {
|
||||
collision = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!collision) {
|
||||
// Removing the map entry publishes removal of the whole bucket. Keep the old chain intact so readers that
|
||||
// already acquired its head can finish their weakly-consistent traversal; detached nodes are never reused.
|
||||
map.remove(bucketKey, head);
|
||||
for (NettyTileEntity<R> current = head; current != null; current = current.nextAcquire()) {
|
||||
current.markRemoved();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.info("Chunk collision occured, failing back to linear scan for tile entity removal in chunk " + chunkX + ", " + chunkZ, 5, AbstractBlockView.class); // I want to see if this occurs frequently
|
||||
|
||||
// Wrapped-key collisions are rare. Remove matching nodes individually while preserving other columns.
|
||||
NettyTileEntity<R> currentHead = head;
|
||||
for (NettyTileEntity<R> current = head; current != null; ) {
|
||||
NettyTileEntity<R> next = current.nextAcquire();
|
||||
if (current.chunkX() == chunkX && current.chunkZ() == chunkZ) {
|
||||
currentHead = removeNode(map, bucketKey, currentHead, current);
|
||||
}
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
|
||||
private NettyTileEntity<R> removeNode(SWMRInt2ObjectHashTable<NettyTileEntity<R>> map, int bucketKey, NettyTileEntity<R> head, NettyTileEntity<R> node) {
|
||||
node.markRemoved();
|
||||
if (node != head) {
|
||||
node.unlink();
|
||||
return head;
|
||||
}
|
||||
NettyTileEntity<R> successor = node.nextAcquire();
|
||||
if (successor == null) {
|
||||
map.remove(bucketKey, node);
|
||||
} else {
|
||||
map.put(bucketKey, successor);
|
||||
}
|
||||
node.detachHeadWriterOnly();
|
||||
return successor;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private T findTileEntityInBucket(NettyTileEntity<R> bucketHead, BlockSpatial position) {
|
||||
for (NettyTileEntity<R> current = bucketHead; current != null; current = current.nextAcquire()) {
|
||||
if (current.blockX() == position.blockX() && current.blockY() == position.blockY() && current.blockZ() == position.blockZ()) {
|
||||
return (T) current;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isCurrentWorldEpoch(int expectedWorldEpoch) {
|
||||
return PlayerData.isStableWorldEpoch(expectedWorldEpoch) && worldEpochSupplier.getAsInt() == expectedWorldEpoch;
|
||||
}
|
||||
|
||||
private long tileEntityCheckModeTokenAcquire() {
|
||||
return (long) TILE_ENTITY_CHECK_MODE_TOKEN.getAcquire(this);
|
||||
}
|
||||
|
||||
private void forEachTileEntity(Consumer<NettyTileEntity<R>> action) {
|
||||
knownTileEntitiesByColumnBucket.forEachValue(head -> {
|
||||
for (NettyTileEntity<R> current = head; current != null; current = current.nextAcquire()) {
|
||||
action.accept(current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static int packColumnBucket(int chunkX, int chunkZ) {
|
||||
// Keep the low 16 bits of X, then put the low 16 bits of Z in the upper half of the int.
|
||||
// Full coordinates on every tile disambiguate columns whose wrapped keys collide.
|
||||
return (chunkX & 0xFFFF) | (chunkZ & 0xFFFF) << 16;
|
||||
}
|
||||
|
||||
private static boolean modeEnabled(long modeToken) {
|
||||
return (modeToken & 1L) != 0L;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.locatables.api.BlockLocatable;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.locatables.api.SpatialChunkSection;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
/**
|
||||
* A per-player block view with one structural writer and concurrent weakly-consistent readers.
|
||||
*
|
||||
* <p>Packet-driven structural mutations, including chunk and tile membership changes, must all be performed by the
|
||||
* same outbound Netty thread. At most one engine worker concurrently traverses a player's view and commits visibility
|
||||
* decisions; visibility fields and the transition queue are safe for that Netty/engine overlap.</p>
|
||||
*/
|
||||
public interface BlockView extends Clearable {
|
||||
/**
|
||||
* Parameters are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
default ChunkOcclusionView getChunkOcclusionView(SpatialChunkSection chunkSection) {
|
||||
return getChunkOcclusionView(chunkSection.chunkX(), chunkSection.chunkY(), chunkSection.chunkZ());
|
||||
}
|
||||
|
||||
boolean isBlockOccluding(BlockLocatable location);
|
||||
|
||||
boolean isBlockOccluding(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Constructs a new tile entity with the provided id and visibility, or updates the block id for an existing tile
|
||||
* entity. This is a structural-writer operation.
|
||||
*
|
||||
* @return the current tracked tile entity, or null when the location cannot be tracked.
|
||||
*/
|
||||
TrackedTileEntity<?> updateOrInsertTileEntity(UUID world, BlockSpatial position, char blockID, boolean visibleIfNew);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void removeTileEntity(UUID world, BlockSpatial position);
|
||||
|
||||
TrackedTileEntity<?> getTrackedTileEntity(UUID world, BlockSpatial position);
|
||||
|
||||
boolean isVisible(UUID world, BlockSpatial position, int currentTick);
|
||||
|
||||
/**
|
||||
* Records visibility established by the current outbound packet without queuing another packet. This also resets
|
||||
* the check timestamp because the transmitted state supersedes the result of any previous visibility check. The
|
||||
* tile entity must be the current state returned by this view's structural-writer operations.
|
||||
*/
|
||||
void recordOutboundTileEntityVisibility(TrackedTileEntity<?> tileEntity, boolean visible);
|
||||
|
||||
/**
|
||||
* Applies a mode change from the structural writer.
|
||||
*
|
||||
* Invokes {@code visibilityRepairConsumer} for each tile entity made visible when checks are disabled. The
|
||||
* structural writer must send their current state directly rather than publishing them to the engine transition
|
||||
* queue.
|
||||
*/
|
||||
void applyTileEntityCheckMode(boolean enabled, int currentTick, Consumer<TrackedTileEntity<?>> visibilityRepairConsumer);
|
||||
|
||||
/** Returns an opaque enabled-state/generation snapshot for rejecting results that cross a mode change. */
|
||||
long tileEntityCheckModeToken();
|
||||
|
||||
/** Returns whether {@code modeToken} is still the current enabled generation. */
|
||||
boolean isCurrentEnabledTileEntityMode(long modeToken);
|
||||
|
||||
Collection<TrackedTileEntity<?>> getKnownTileEntities();
|
||||
|
||||
/**
|
||||
* Iterates currently tracked tile entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of tile entities passed to {@code action}.
|
||||
*/
|
||||
int forEachNeedingRecheck(int recheckTicks, int currentTick, Consumer<TrackedTileEntity<?>> action);
|
||||
|
||||
@FunctionalInterface
|
||||
interface VisibilityResolver {
|
||||
byte SKIPPED = 78;
|
||||
byte HIDE = -23;
|
||||
byte SHOW = 42;
|
||||
|
||||
byte setVisible(TrackedTileEntity<?> tileEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates currently tracked tile entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of tile entities passed to {@code action}.
|
||||
*/
|
||||
int updateVisibilityForEachNeedingRecheck(int recheckTicks, int currentTick, long modeToken, int expectedWorldEpoch, VisibilityResolver action);
|
||||
|
||||
boolean hasPendingTransitions();
|
||||
|
||||
/** Publishes the partial transition batch owned by the current engine producer. */
|
||||
void flushPendingTransitions();
|
||||
|
||||
@FunctionalInterface
|
||||
interface TransitionConsumer {
|
||||
void accept(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch);
|
||||
}
|
||||
|
||||
void drainTransitions(TransitionConsumer consumer);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void upsertBlock(UUID world, int x, int y, int z, int blockID);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void removeChunk(UUID world, int chunkX, int chunkZ);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void removeChunkSection(UUID world, int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
/**
|
||||
* Removes tracked tile entities absent from an authoritative chunk column. A null {@code presentBySection} means
|
||||
* the entire column has no managed tiles; a null entry means that section has none. This is a structural-writer
|
||||
* operation.
|
||||
*/
|
||||
void pruneTileEntitiesAbsentFromChunkSections(UUID world, int chunkX, int chunkZ, int minimumSectionY, int sectionCount, long[][] presentBySection);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void replaceChunkSection(UUID world, int chunkX, int chunkY, int chunkZ, BlockChunkData data);
|
||||
|
||||
/** Structural-writer operation. */
|
||||
void replaceChunkSectionOcclusion(UUID world, int chunkX, int chunkY, int chunkZ, OccludingChunkData data);
|
||||
|
||||
default <T> T cast() {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
interface Factory {
|
||||
BlockView createBlockView(IntSupplier worldEpochSupplier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
|
||||
// Retains the originating object identity so a delayed transition cannot target a replacement at the same coordinates.
|
||||
public record BlockViewTransition(Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch) {
|
||||
public enum Type {
|
||||
SHOW,
|
||||
HIDE,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public interface EntityView<T extends TrackedEntity<?>> extends Clearable {
|
||||
void insertEntity(UUID world, T entity);
|
||||
|
||||
void removeEntity(int entityID, int currentTick);
|
||||
|
||||
void removeEntity(int entityID);
|
||||
|
||||
void removeEntity(UUID entityUUID, int currentTick);
|
||||
|
||||
T getEntity(UUID entityUUID);
|
||||
|
||||
T getEntity(int entityID);
|
||||
|
||||
Spatial getPosition(UUID entityUUID);
|
||||
|
||||
int getEntityID(UUID entityUUID);
|
||||
|
||||
boolean exists(UUID entityUUID);
|
||||
|
||||
boolean exists(int entityID);
|
||||
|
||||
/**
|
||||
* Returns a weakly consistent count of the entities currently tracked by this view.
|
||||
* This operation is safe to call from threads other than the structural writer.
|
||||
*/
|
||||
int size();
|
||||
|
||||
@Deprecated
|
||||
boolean isVisible(UUID entityUUID, int currentTick);
|
||||
|
||||
boolean isVisible(UUID entityUUID);
|
||||
|
||||
boolean isVisible(int entityID);
|
||||
|
||||
void setVisibility(NettyEntity<?> entity, boolean visible, int currentTick, int expectedWorldEpoch);
|
||||
|
||||
/**
|
||||
* Applies visibility from the Netty structural writer without publishing an engine transition.
|
||||
*
|
||||
* @return whether the entity and epoch were current and the visibility was applied
|
||||
*/
|
||||
boolean recordDirectVisibility(NettyEntity<?> entity, boolean visible, int currentTick, int expectedWorldEpoch);
|
||||
|
||||
Collection<UUID> getKnownEntities();
|
||||
|
||||
int[] getKnownEntityIDs();
|
||||
|
||||
/**
|
||||
* Iterates currently tracked entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of entities passed to {@code action}.
|
||||
*/
|
||||
int forEachNeedingRecheck(int visibleRecheckTicks, int currentTick, Consumer<UUID> action);
|
||||
|
||||
/**
|
||||
* Iterates currently tracked entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of entities passed to {@code action}, or 0 if {@code countingActuallyNeeded} is false.
|
||||
*/
|
||||
int forEachNeedingRecheckEntity(int visibleRecheckTicks, int currentTick, boolean countingActuallyNeeded, int expectedWorldEpoch, Consumer<NettyEntity<?>> action);
|
||||
|
||||
boolean hasPendingTransitions();
|
||||
|
||||
/** Publishes the partial transition batch owned by the current engine producer. */
|
||||
void flushPendingTransitions();
|
||||
|
||||
@FunctionalInterface
|
||||
interface TransitionConsumer {
|
||||
void accept(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch);
|
||||
}
|
||||
|
||||
void drainTransitions(TransitionConsumer consumer);
|
||||
|
||||
boolean isPlayerView();
|
||||
|
||||
default <T> T cast() {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
String getStringDataForDebugging();
|
||||
|
||||
interface Factory {
|
||||
EntityView<?> createEntityView(IntSupplier worldEpochSupplier);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
|
||||
// Used to cache visibility changes until the player's netty thread next processes
|
||||
public record EntityViewTransition(Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
public enum Type {
|
||||
SHOW,
|
||||
HIDE,
|
||||
FORGET,
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.utils.IntrusiveSPSCQueue;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Queues tile-entity visibility transitions without allocating a record for every transition.
|
||||
*
|
||||
* <p>Exactly one engine thread at a time owns the pending batch and publishes it to the intrusive SPSC queue. The
|
||||
* producer role may migrate between engine threads, while the player's Netty thread exclusively drains published
|
||||
* entries. Producer and consumer methods must not be called from the opposite role.</p>
|
||||
*/
|
||||
public final class PackedBlockTransitionQueue {
|
||||
private static final int BATCH_MIN_SIZE = 3;
|
||||
private static final int BATCH_SIZE = 8;
|
||||
|
||||
private final IntrusiveSPSCQueue<QueueEntry> publishedEntries = new IntrusiveSPSCQueue<>();
|
||||
private final PendingBatch pending = new PendingBatch();
|
||||
|
||||
public void add(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(tileEntity, "tileEntity");
|
||||
|
||||
if (pending.count != 0 && (pending.modeToken != modeToken || pending.worldEpoch != worldEpoch)) {
|
||||
flushPending();
|
||||
}
|
||||
if (pending.count == 0) {
|
||||
pending.modeToken = modeToken;
|
||||
pending.worldEpoch = worldEpoch;
|
||||
}
|
||||
pending.add(type, tileEntity);
|
||||
if (pending.count == BATCH_SIZE) {
|
||||
flushPending();
|
||||
}
|
||||
}
|
||||
|
||||
/** Publishes the producer-owned partial batch. Only the engine producer may call this method. */
|
||||
public void flushPendingTransitions() {
|
||||
flushPending();
|
||||
}
|
||||
|
||||
public boolean hasPendingTransitions() {
|
||||
return !publishedEntries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains published entries in FIFO order. A claimed queue entry is consumed at most once if a callback throws while
|
||||
* processing it, and any unvisited transitions packed into that entry are discarded.
|
||||
*/
|
||||
public void drainTransitions(BlockView.TransitionConsumer consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
QueueEntry entry;
|
||||
while ((entry = publishedEntries.poll()) != null) {
|
||||
entry.drain(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards transitions already published to the consumer. The producer-owned pending batch is intentionally left
|
||||
* untouched: a structural clear can race an engine flush, and that in-flight batch must retain its old epoch and
|
||||
* mode token so the consumer can reject it normally after it is published.
|
||||
*/
|
||||
public void clearPublishedTransitions() {
|
||||
publishedEntries.clear();
|
||||
}
|
||||
|
||||
private void flushPending() {
|
||||
switch (pending.count) {
|
||||
case 0 -> {
|
||||
return;
|
||||
}
|
||||
case 1 -> publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.modeToken, pending.worldEpoch));
|
||||
case 2 -> {
|
||||
publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.modeToken, pending.worldEpoch));
|
||||
publishedEntries.offer(new SingleEntry(pending.t2, pending.e2, pending.modeToken, pending.worldEpoch));
|
||||
}
|
||||
case BATCH_MIN_SIZE, 4, 5, 6, 7, BATCH_SIZE -> publishedEntries.offer(new BatchEntry(pending));
|
||||
default -> throw new IllegalStateException("Tile transition batch exceeded eight entries");
|
||||
}
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
private abstract static class QueueEntry extends IntrusiveSPSCQueue.Node {
|
||||
abstract void drain(BlockView.TransitionConsumer consumer);
|
||||
}
|
||||
|
||||
private static final class SingleEntry extends QueueEntry {
|
||||
private final BlockViewTransition.Type type;
|
||||
private final TrackedTileEntity<?> tileEntity;
|
||||
private final long modeToken;
|
||||
private final int worldEpoch;
|
||||
|
||||
private SingleEntry(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity, long modeToken, int worldEpoch) {
|
||||
this.type = type;
|
||||
this.tileEntity = tileEntity;
|
||||
this.modeToken = modeToken;
|
||||
this.worldEpoch = worldEpoch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(BlockView.TransitionConsumer consumer) {
|
||||
consumer.accept(type, tileEntity, modeToken, worldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PendingBatch implements Clearable {
|
||||
private BlockViewTransition.Type t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
private TrackedTileEntity<?> e1, e2, e3, e4, e5, e6, e7, e8;
|
||||
private long modeToken;
|
||||
private int worldEpoch;
|
||||
private int count;
|
||||
|
||||
private void add(BlockViewTransition.Type type, TrackedTileEntity<?> tileEntity) {
|
||||
switch (++count) {
|
||||
case 1 -> { t1 = type; e1 = tileEntity; }
|
||||
case 2 -> { t2 = type; e2 = tileEntity; }
|
||||
case 3 -> { t3 = type; e3 = tileEntity; }
|
||||
case 4 -> { t4 = type; e4 = tileEntity; }
|
||||
case 5 -> { t5 = type; e5 = tileEntity; }
|
||||
case 6 -> { t6 = type; e6 = tileEntity; }
|
||||
case 7 -> { t7 = type; e7 = tileEntity; }
|
||||
case 8 -> { t8 = type; e8 = tileEntity; }
|
||||
default -> throw new IllegalStateException("Tile transition batch exceeded eight entries");
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
t1 = null;
|
||||
t2 = null;
|
||||
t3 = null;
|
||||
t4 = null;
|
||||
t5 = null;
|
||||
t6 = null;
|
||||
t7 = null;
|
||||
t8 = null;
|
||||
e1 = null;
|
||||
e2 = null;
|
||||
e3 = null;
|
||||
e4 = null;
|
||||
e5 = null;
|
||||
e6 = null;
|
||||
e7 = null;
|
||||
e8 = null;
|
||||
modeToken = 0L;
|
||||
worldEpoch = 0;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BatchEntry extends QueueEntry {
|
||||
private final BlockViewTransition.Type t1, t2, t3, t4, t5, t6, t7, t8;
|
||||
private final TrackedTileEntity<?> e1, e2, e3, e4, e5, e6, e7, e8;
|
||||
private final long modeToken;
|
||||
private final int worldEpoch;
|
||||
private final int count;
|
||||
|
||||
private BatchEntry(PendingBatch pending) {
|
||||
t1 = pending.t1;
|
||||
t2 = pending.t2;
|
||||
t3 = pending.t3;
|
||||
t4 = pending.t4;
|
||||
t5 = pending.t5;
|
||||
t6 = pending.t6;
|
||||
t7 = pending.t7;
|
||||
t8 = pending.t8;
|
||||
e1 = pending.e1;
|
||||
e2 = pending.e2;
|
||||
e3 = pending.e3;
|
||||
e4 = pending.e4;
|
||||
e5 = pending.e5;
|
||||
e6 = pending.e6;
|
||||
e7 = pending.e7;
|
||||
e8 = pending.e8;
|
||||
modeToken = pending.modeToken;
|
||||
worldEpoch = pending.worldEpoch;
|
||||
count = pending.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(BlockView.TransitionConsumer consumer) {
|
||||
consumer.accept(t1, e1, modeToken, worldEpoch);
|
||||
if (count >= 2) consumer.accept(t2, e2, modeToken, worldEpoch);
|
||||
if (count >= 3) consumer.accept(t3, e3, modeToken, worldEpoch);
|
||||
if (count >= 4) consumer.accept(t4, e4, modeToken, worldEpoch);
|
||||
if (count >= 5) consumer.accept(t5, e5, modeToken, worldEpoch);
|
||||
if (count >= 6) consumer.accept(t6, e6, modeToken, worldEpoch);
|
||||
if (count >= 7) consumer.accept(t7, e7, modeToken, worldEpoch);
|
||||
if (count >= 8) consumer.accept(t8, e8, modeToken, worldEpoch);
|
||||
}
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.utils.IntrusiveSPSCQueue;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Queues entity visibility transitions without allocating a record for every transition.
|
||||
*
|
||||
* <p>Exactly one engine thread at a time owns the pending batch and publishes it to the intrusive SPSC queue. The
|
||||
* producer role may migrate between engine threads, while the player's Netty thread exclusively drains published
|
||||
* entries. Producer and consumer methods must not be called from the opposite role.</p>
|
||||
*/
|
||||
public final class PackedEntityTransitionQueue { //todo: potentially merge this with PackedBlockTransitionQueue, and add a mode token to entities
|
||||
private static final int BATCH_MIN_SIZE = 3;
|
||||
private static final int BATCH_SIZE = 8;
|
||||
|
||||
private final IntrusiveSPSCQueue<QueueEntry> publishedEntries = new IntrusiveSPSCQueue<>();
|
||||
private final PendingBatch pending = new PendingBatch();
|
||||
|
||||
public void add(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
Objects.requireNonNull(type, "type");
|
||||
Objects.requireNonNull(entity, "entity");
|
||||
|
||||
if (pending.count != 0 && pending.worldEpoch != worldEpoch) {
|
||||
flushPending();
|
||||
}
|
||||
if (pending.count == 0) {
|
||||
pending.worldEpoch = worldEpoch;
|
||||
}
|
||||
pending.add(type, entity);
|
||||
if (pending.count == BATCH_SIZE) {
|
||||
flushPending();
|
||||
}
|
||||
}
|
||||
|
||||
/** Publishes the producer-owned partial batch. Only the engine producer may call this method. */
|
||||
public void flushPendingTransitions() {
|
||||
flushPending();
|
||||
}
|
||||
|
||||
public boolean hasPendingTransitions() {
|
||||
return !publishedEntries.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drains published entries in FIFO order. A claimed queue entry is consumed at most once if a callback throws while
|
||||
* processing it, and any unvisited transitions packed into that entry are discarded.
|
||||
*/
|
||||
public void drainTransitions(EntityView.TransitionConsumer consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
QueueEntry entry;
|
||||
while ((entry = publishedEntries.poll()) != null) {
|
||||
entry.drain(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards transitions already published to the consumer. The producer-owned pending batch is intentionally left
|
||||
* untouched: a structural clear can race an engine flush, and that in-flight batch must retain its old epoch so
|
||||
* the consumer can reject it normally after it is published.
|
||||
*/
|
||||
public void clearPublishedTransitions() {
|
||||
publishedEntries.clear();
|
||||
}
|
||||
|
||||
private void flushPending() {
|
||||
switch (pending.count) {
|
||||
case 0 -> {
|
||||
return;
|
||||
}
|
||||
case 1 -> publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.worldEpoch));
|
||||
case 2 -> {
|
||||
publishedEntries.offer(new SingleEntry(pending.t1, pending.e1, pending.worldEpoch));
|
||||
publishedEntries.offer(new SingleEntry(pending.t2, pending.e2, pending.worldEpoch));
|
||||
}
|
||||
case BATCH_MIN_SIZE, 4, 5, 6, 7, BATCH_SIZE -> publishedEntries.offer(new BatchEntry(pending));
|
||||
default -> throw new IllegalStateException("Entity transition batch exceeded eight entries");
|
||||
}
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
private abstract static class QueueEntry extends IntrusiveSPSCQueue.Node {
|
||||
abstract void drain(EntityView.TransitionConsumer consumer);
|
||||
}
|
||||
|
||||
private static final class SingleEntry extends QueueEntry {
|
||||
private final EntityViewTransition.Type type;
|
||||
private final TrackedEntity<?> entity;
|
||||
private final int worldEpoch;
|
||||
|
||||
private SingleEntry(EntityViewTransition.Type type, TrackedEntity<?> entity, int worldEpoch) {
|
||||
this.type = type;
|
||||
this.entity = entity;
|
||||
this.worldEpoch = worldEpoch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(EntityView.TransitionConsumer consumer) {
|
||||
consumer.accept(type, entity, worldEpoch);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class PendingBatch implements Clearable {
|
||||
private EntityViewTransition.Type t1;
|
||||
private EntityViewTransition.Type t2;
|
||||
private EntityViewTransition.Type t3;
|
||||
private EntityViewTransition.Type t4;
|
||||
private EntityViewTransition.Type t5;
|
||||
private EntityViewTransition.Type t6;
|
||||
private EntityViewTransition.Type t7;
|
||||
private EntityViewTransition.Type t8;
|
||||
private TrackedEntity<?> e1;
|
||||
private TrackedEntity<?> e2;
|
||||
private TrackedEntity<?> e3;
|
||||
private TrackedEntity<?> e4;
|
||||
private TrackedEntity<?> e5;
|
||||
private TrackedEntity<?> e6;
|
||||
private TrackedEntity<?> e7;
|
||||
private TrackedEntity<?> e8;
|
||||
private int worldEpoch;
|
||||
private int count;
|
||||
|
||||
private void add(EntityViewTransition.Type type, TrackedEntity<?> entity) {
|
||||
switch (++count) {
|
||||
case 1 -> { t1 = type; e1 = entity; }
|
||||
case 2 -> { t2 = type; e2 = entity; }
|
||||
case 3 -> { t3 = type; e3 = entity; }
|
||||
case 4 -> { t4 = type; e4 = entity; }
|
||||
case 5 -> { t5 = type; e5 = entity; }
|
||||
case 6 -> { t6 = type; e6 = entity; }
|
||||
case 7 -> { t7 = type; e7 = entity; }
|
||||
case 8 -> { t8 = type; e8 = entity; }
|
||||
default -> throw new IllegalStateException("Entity transition batch exceeded eight entries");
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
t1 = null;
|
||||
t2 = null;
|
||||
t3 = null;
|
||||
t4 = null;
|
||||
t5 = null;
|
||||
t6 = null;
|
||||
t7 = null;
|
||||
t8 = null;
|
||||
e1 = null;
|
||||
e2 = null;
|
||||
e3 = null;
|
||||
e4 = null;
|
||||
e5 = null;
|
||||
e6 = null;
|
||||
e7 = null;
|
||||
e8 = null;
|
||||
worldEpoch = 0;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BatchEntry extends QueueEntry {
|
||||
private final EntityViewTransition.Type t1;
|
||||
private final EntityViewTransition.Type t2;
|
||||
private final EntityViewTransition.Type t3;
|
||||
private final EntityViewTransition.Type t4;
|
||||
private final EntityViewTransition.Type t5;
|
||||
private final EntityViewTransition.Type t6;
|
||||
private final EntityViewTransition.Type t7;
|
||||
private final EntityViewTransition.Type t8;
|
||||
private final TrackedEntity<?> e1;
|
||||
private final TrackedEntity<?> e2;
|
||||
private final TrackedEntity<?> e3;
|
||||
private final TrackedEntity<?> e4;
|
||||
private final TrackedEntity<?> e5;
|
||||
private final TrackedEntity<?> e6;
|
||||
private final TrackedEntity<?> e7;
|
||||
private final TrackedEntity<?> e8;
|
||||
private final int worldEpoch;
|
||||
private final int count;
|
||||
|
||||
private BatchEntry(PendingBatch pending) {
|
||||
t1 = pending.t1;
|
||||
t2 = pending.t2;
|
||||
t3 = pending.t3;
|
||||
t4 = pending.t4;
|
||||
t5 = pending.t5;
|
||||
t6 = pending.t6;
|
||||
t7 = pending.t7;
|
||||
t8 = pending.t8;
|
||||
e1 = pending.e1;
|
||||
e2 = pending.e2;
|
||||
e3 = pending.e3;
|
||||
e4 = pending.e4;
|
||||
e5 = pending.e5;
|
||||
e6 = pending.e6;
|
||||
e7 = pending.e7;
|
||||
e8 = pending.e8;
|
||||
worldEpoch = pending.worldEpoch;
|
||||
count = pending.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drain(EntityView.TransitionConsumer consumer) {
|
||||
consumer.accept(t1, e1, worldEpoch);
|
||||
if (count >= 2) consumer.accept(t2, e2, worldEpoch);
|
||||
if (count >= 3) consumer.accept(t3, e3, worldEpoch);
|
||||
if (count >= 4) consumer.accept(t4, e4, worldEpoch);
|
||||
if (count >= 5) consumer.accept(t5, e5, worldEpoch);
|
||||
if (count >= 6) consumer.accept(t6, e6, worldEpoch);
|
||||
if (count >= 7) consumer.accept(t7, e7, worldEpoch);
|
||||
if (count >= 8) consumer.accept(t8, e8, worldEpoch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
public final class ViewRegistry {
|
||||
private static EntityView.Factory entityViewFactory;
|
||||
private static EntityView.Factory playerEntityViewFactory;
|
||||
private static BlockView.Factory blockViewFactory;
|
||||
|
||||
private ViewRegistry() {}
|
||||
|
||||
public static void initialise(BlockView.Factory blockViewFactory1, EntityView.Factory entityViewFactory1, EntityView.Factory playerEntityViewFactory1) {
|
||||
blockViewFactory = blockViewFactory1;
|
||||
entityViewFactory = entityViewFactory1;
|
||||
playerEntityViewFactory = playerEntityViewFactory1;
|
||||
}
|
||||
|
||||
public static BlockView createBlockView(IntSupplier worldEpochSupplier) {
|
||||
if (blockViewFactory == null) {
|
||||
Logger.error(new IllegalStateException("Block view factory is null. Did you forget to initialise ViewRegistry?"), 1, ViewRegistry.class);
|
||||
}
|
||||
return blockViewFactory.createBlockView(worldEpochSupplier);
|
||||
}
|
||||
|
||||
public static EntityView<?> createEntityView(IntSupplier worldEpochSupplier) {
|
||||
if (entityViewFactory == null) {
|
||||
Logger.error(new IllegalStateException("Entity view factory is null. Did you forget to initialise ViewRegistry?"), 1, ViewRegistry.class);
|
||||
}
|
||||
return entityViewFactory.createEntityView(worldEpochSupplier);
|
||||
}
|
||||
|
||||
public static EntityView<?> createPlayerEntityView(IntSupplier worldEpochSupplier) {
|
||||
if (playerEntityViewFactory == null) {
|
||||
Logger.error(new IllegalStateException("Player entity view factory is null. Did you forget to initialise ViewRegistry?"), 1, ViewRegistry.class);
|
||||
}
|
||||
return playerEntityViewFactory.createEntityView(worldEpochSupplier);
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.TwoBlockChunkData;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packGlobalCoords;
|
||||
|
||||
public final class BlockChunkSectionStore extends SWMRLong2ObjectHashTable<BlockChunkData> implements ChunkSectionStore {
|
||||
private final BlockInfoResolver blockInfoResolver;
|
||||
|
||||
public BlockChunkSectionStore(BlockInfoResolver blockInfoResolver) {
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
BlockChunkData chunk = get(key);
|
||||
return chunk != null && chunk.isOccludingLocal(x & ChunkData.LOCAL_MASK, y & ChunkData.LOCAL_MASK, z & ChunkData.LOCAL_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not thread-safe and should only be called from the netty thread.
|
||||
*/
|
||||
@Override
|
||||
public void setBlockID(int x, int y, int z, int blockID) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
char storedBlockID = toStoredBlockID(blockID);
|
||||
BlockChunkData existing = get(key);
|
||||
if (existing == null) { // this means the chunk is currently air (or something's gone horribly wrong)
|
||||
if (storedBlockID == 0) {
|
||||
return;
|
||||
}
|
||||
TwoBlockChunkData newChunk = TwoBlockChunkData.upgradeFromAir(storedBlockID, x, y, z, blockInfoResolver);
|
||||
put(key, newChunk);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockChunkData updated = existing.setBlockID(x & ChunkData.LOCAL_MASK, y & ChunkData.LOCAL_MASK, z & ChunkData.LOCAL_MASK, storedBlockID, blockInfoResolver);
|
||||
if (updated != existing) {
|
||||
put(key, updated);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceSection(int chunkX, int sectionY, int chunkZ, BlockChunkData data) {
|
||||
put(packChunkCoords(chunkX, sectionY, chunkZ), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceSectionOcclusion(int chunkX, int sectionY, int chunkZ, games.cubi.raycastedantiesp.core.chunks.OccludingChunkData data) {
|
||||
throw new UnsupportedOperationException("Block chunk storage requires full block IDs for section replacement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSection(int chunkX, int sectionY, int chunkZ) {
|
||||
remove(packChunkCoords(chunkX, sectionY, chunkZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColumn(int chunkX, int chunkZ) {
|
||||
// Start at the raw 8-bit Y value 0. Incrementing visits 0..255, which represents signed section Y values 0..127 then -128..-1.
|
||||
long key = packChunkCoords(chunkX, 0, chunkZ);
|
||||
for (int i = 0; i < SECTION_Y_COUNT; i++) {
|
||||
remove(key);
|
||||
key += SECTION_Y_INCREMENT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadedSectionCount() {
|
||||
return size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
|
||||
private static char toStoredBlockID(int blockID) {
|
||||
if (blockID < 0 || blockID > Character.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("blockID must fit in an unsigned 16-bit value, but was " + blockID);
|
||||
}
|
||||
return (char) blockID;
|
||||
}
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
|
||||
public interface ChunkSectionStore {
|
||||
/**
|
||||
* Coordinates are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
boolean isOccluding(int x, int y, int z);
|
||||
|
||||
void setBlockID(int x, int y, int z, int blockID);
|
||||
|
||||
void replaceSection(int chunkX, int sectionY, int chunkZ, BlockChunkData data);
|
||||
|
||||
void replaceSectionOcclusion(int chunkX, int sectionY, int chunkZ, OccludingChunkData data);
|
||||
|
||||
void removeSection(int chunkX, int sectionY, int chunkZ);
|
||||
|
||||
void removeColumn(int chunkX, int chunkZ);
|
||||
|
||||
int loadedSectionCount();
|
||||
|
||||
void clear();
|
||||
|
||||
static final int HORIZONTAL_BITS = 28;
|
||||
static final int SECTION_Y_BITS = 8;
|
||||
static final int HORIZONTAL_MIN = -(1 << (HORIZONTAL_BITS - 1));
|
||||
static final int HORIZONTAL_MAX = (1 << (HORIZONTAL_BITS - 1)) - 1;
|
||||
static final int SECTION_Y_MIN = -(1 << (SECTION_Y_BITS - 1));
|
||||
static final int SECTION_Y_MAX = (1 << (SECTION_Y_BITS - 1)) - 1;
|
||||
static final int SECTION_Y_COUNT = 1 << SECTION_Y_BITS;
|
||||
static final long SECTION_Y_INCREMENT = 1L << HORIZONTAL_BITS;
|
||||
static final long HORIZONTAL_MASK = (1L << HORIZONTAL_BITS) - 1L;
|
||||
static final long SECTION_Y_MASK = (1L << SECTION_Y_BITS) - 1L;
|
||||
|
||||
static long packChunkCoords(int chunkX, int sectionY, int chunkZ) {
|
||||
checkHorizontal(chunkX, "chunkX");
|
||||
checkSectionY(sectionY);
|
||||
checkHorizontal(chunkZ, "chunkZ");
|
||||
return ((long) chunkX & HORIZONTAL_MASK) << (SECTION_Y_BITS + HORIZONTAL_BITS)
|
||||
| ((long) sectionY & SECTION_Y_MASK) << HORIZONTAL_BITS
|
||||
| ((long) chunkZ & HORIZONTAL_MASK);
|
||||
}
|
||||
|
||||
static long packGlobalCoords(int x, int y, int z) {
|
||||
return packChunkCoords(x >> 4, y >> 4, z >> 4);
|
||||
}
|
||||
|
||||
static int unpackChunkX(long key) {
|
||||
return (int) (key >> (SECTION_Y_BITS + HORIZONTAL_BITS));
|
||||
}
|
||||
|
||||
static int unpackSectionY(long key) {
|
||||
return (int) (key << HORIZONTAL_BITS >> (HORIZONTAL_BITS + HORIZONTAL_BITS));
|
||||
}
|
||||
|
||||
static int unpackChunkZ(long key) {
|
||||
return (int) (key << (Long.SIZE - HORIZONTAL_BITS) >> (Long.SIZE - HORIZONTAL_BITS));
|
||||
}
|
||||
|
||||
private static void checkHorizontal(int value, String name) {
|
||||
if (value < HORIZONTAL_MIN || value > HORIZONTAL_MAX) {
|
||||
throw new IllegalArgumentException(name + " must be in [" + HORIZONTAL_MIN + ", " + HORIZONTAL_MAX + "], but was " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSectionY(int sectionY) {
|
||||
if (sectionY < SECTION_Y_MIN || sectionY > SECTION_Y_MAX) {
|
||||
throw new IllegalArgumentException("sectionY must be in [" + SECTION_Y_MIN + ", " + SECTION_Y_MAX + "], but was " + sectionY);
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.*;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packGlobalCoords;
|
||||
|
||||
public final class OccludingChunkSectionStore extends SWMRLong2ObjectHashTable<OccludingChunkData> implements ChunkSectionStore {
|
||||
private final BlockInfoResolver blockInfoResolver;
|
||||
|
||||
public OccludingChunkSectionStore(BlockInfoResolver blockInfoResolver) {
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
OccludingChunkData chunk = get(key);
|
||||
return chunk != null && chunk.isOccludingLocal(x & ChunkData.LOCAL_MASK, y & ChunkData.LOCAL_MASK, z & ChunkData.LOCAL_MASK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockID(int x, int y, int z, int blockID) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
boolean occluding = blockID != 0 && blockInfoResolver.isOccluding(blockID);
|
||||
OccludingChunkData existing = get(key);
|
||||
if (existing == null) {
|
||||
if (!occluding) {
|
||||
return;
|
||||
}
|
||||
existing = OccludingChunkData.empty();
|
||||
put(key, existing);
|
||||
}
|
||||
|
||||
OccludingChunkData updated = existing.setOccluding(x & ChunkData.LOCAL_MASK, y & ChunkData.LOCAL_MASK, z & ChunkData.LOCAL_MASK, occluding);
|
||||
if (updated != existing) {
|
||||
put(key, updated);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceSection(int chunkX, int sectionY, int chunkZ, BlockChunkData data) {
|
||||
throw new UnsupportedOperationException("Occlusion chunk storage requires occlusion data for section replacement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceSectionOcclusion(int chunkX, int sectionY, int chunkZ, OccludingChunkData data) {
|
||||
put(packChunkCoords(chunkX, sectionY, chunkZ), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSection(int chunkX, int sectionY, int chunkZ) {
|
||||
remove(packChunkCoords(chunkX, sectionY, chunkZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeColumn(int chunkX, int chunkZ) {
|
||||
// Start at raw Y 0 so the increment covers every possible 8-bit signed section coordinate exactly once.
|
||||
long key = packChunkCoords(chunkX, 0, chunkZ);
|
||||
for (int i = 0; i < SECTION_Y_COUNT; i++) {
|
||||
remove(key);
|
||||
key += SECTION_Y_INCREMENT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadedSectionCount() {
|
||||
return size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
}
|
||||
}
|
||||
+812
@@ -0,0 +1,812 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.controller;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.PlayerConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.RaycastConfig;
|
||||
import games.cubi.raycastedantiesp.core.entity.EntityBypassRegistry;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.players.NettyData;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerRegistry;
|
||||
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
|
||||
import games.cubi.raycastedantiesp.core.utils.Packet;
|
||||
import games.cubi.raycastedantiesp.core.view.EntityView;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_LEASHER;
|
||||
import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_VEHICLE;
|
||||
|
||||
/**
|
||||
* @param <P> The platform's packet wrapper (PacketWrapper<?>)
|
||||
*/
|
||||
public abstract class PacketEntityViewController<P> {
|
||||
private static PacketEntityViewController<?> SELF; //TODO Switch to LazyConstant once out of preview (see https://openjdk.org/jeps/526)
|
||||
|
||||
{
|
||||
synchronized (PacketEntityViewController.class) {
|
||||
if (SELF != null) {
|
||||
throw new IllegalStateException("Multiple instances of PacketEventsEntityViewController created.");
|
||||
}
|
||||
SELF = this;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected static PacketEntityViewController<?> get() {
|
||||
return SELF;
|
||||
}
|
||||
|
||||
protected EntityConfig entityConfig = null;
|
||||
protected PlayerConfig playerConfig = null;
|
||||
protected double hideOnSpawnEntityDistanceSquared = 0;
|
||||
protected double hideOnSpawnPlayerDistanceSquared = 0;
|
||||
|
||||
protected void handleWorldStatePacket(UUID player, String world, UUID worldUUID, int minWorldHeight, int currentTick) {
|
||||
PlayerData playerData = PlayerRegistry.getInstance().getPlayerData(player);
|
||||
if (playerData == null) {
|
||||
Logger.error("Received world state packet for unknown player, uuid=" + player, 2, PacketEntityViewController.class);
|
||||
return;
|
||||
}
|
||||
if (world == null) {
|
||||
Logger.error("Received world state packet without a world name, uuid=" + player, 2, PacketEntityViewController.class);
|
||||
return;
|
||||
}
|
||||
|
||||
NettyData nettyData = playerData.nettyData();
|
||||
String previousWorld = nettyData.getCurrentWorldName();
|
||||
if (world.equals(previousWorld)) {
|
||||
nettyData.setCurrentWorldMinHeight(minWorldHeight);
|
||||
return;
|
||||
}
|
||||
|
||||
int[] remainingEntityIDs = previousWorld == null ? null : drainRemainingEntityIDs(playerData);
|
||||
playerData.beginWorldTransition();
|
||||
try {
|
||||
if (previousWorld != null) {
|
||||
nettyData.setExpectedWorldTransitionDestroyEntityIDs(remainingEntityIDs);
|
||||
playerData.blockView().clear();
|
||||
playerData.entityView().clear();
|
||||
playerData.playerView().clear();
|
||||
nettyData.clearPendingReconciliationState();
|
||||
nettyData.getSelfEntity().clear();
|
||||
}
|
||||
nettyData.setCurrentWorldName(world).setCurrentWorldMinHeight(minWorldHeight);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e, 1, PacketEntityViewController.class);
|
||||
} finally {
|
||||
playerData.completeWorldTransition(worldUUID); //Don't leave the player stuck on an odd world epoch
|
||||
}
|
||||
}
|
||||
|
||||
protected PlayerData handlePlayPhaseLoginPacket(int entityID, UUID playerUUID, int currentTick) {
|
||||
return PlayerRegistry.getInstance().registerAndGetPlayer(playerUUID, currentTick, entityID, this::createSelfEntity);
|
||||
}
|
||||
|
||||
protected abstract NettyEntity<?> createSelfEntity(PlayerData ownData, int entityID, UUID playerUUID);
|
||||
|
||||
/** Applies a SHOW transition immediately on the Netty thread without publishing it to the engine SPSC queue. */
|
||||
protected abstract void processDirectEntityShow(PlayerData playerData, EntityView<?> view, NettyEntity<?> entity, int worldEpoch);
|
||||
|
||||
protected void handlePlayerDisconnect(UUID player) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
PlayerRegistry.getInstance().unregisterPlayer(player);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
@Packet(Packet.Packets.SPAWN_ENTITY)
|
||||
protected boolean handleEntitySpawn(P packet, int entityID, boolean isPlayer, PlayerData playerData, UUID world, int currentTick) {
|
||||
boolean returnValue = handleEntitySpawn0(packet, isPlayer, playerData, world, currentTick);
|
||||
playerData.nettyData().runPendingPostSpawnTaskForEntity(entityID);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
protected boolean handleEntitySpawn0(P packet, boolean isPlayer, PlayerData playerData, UUID world, int currentTick) {
|
||||
if (world == null) {
|
||||
Logger.error(new RuntimeException("World null when handling spawn entity packet, uuid=" + playerData.getPlayerUUID() + " tick=" + currentTick), 2, PacketEntityViewController.class);
|
||||
return false;
|
||||
}
|
||||
|
||||
NettyEntity<?> entity = Logger.requireNonNull(processEntitySpawn(playerData, packet, world, currentTick), "processEntitySpawn returned null", 3, PacketEntityViewController.class);
|
||||
|
||||
if ((!isPlayer && entityConfig.enabled()) || isPlayer && playerConfig.enabled()) {
|
||||
Locatable ownLocation = playerData.ownLocation();
|
||||
boolean staleOwnLocation = ownLocation == null || ownLocation.world() == null || !ownLocation.world().equals(world);
|
||||
double distanceSquared = staleOwnLocation ? Double.POSITIVE_INFINITY : ownLocation.distanceSquared(entity);
|
||||
if (distanceSquared > (isPlayer ? hideOnSpawnPlayerDistanceSquared : hideOnSpawnEntityDistanceSquared)) {
|
||||
entity.setVisible(false);
|
||||
entity.setClientVisible(false);
|
||||
if (isPlayer) {
|
||||
insertEntityToPlayerView(entity, playerData, world);
|
||||
return true;
|
||||
}
|
||||
insertEntityToEntityView(entity, playerData, world);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
entity.setClientVisible(true);
|
||||
}
|
||||
if (isPlayer) {
|
||||
insertEntityToPlayerView(entity, playerData, world);
|
||||
return false;
|
||||
}
|
||||
insertEntityToEntityView(entity, playerData, world);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Packet(Packet.Packets.ENTITY_ANIMATION)
|
||||
protected boolean handleEntityAnimation(int entityID, PlayerData playerData) {
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
@Packet(Packet.Packets.ENTITY_EVENT)
|
||||
protected boolean handleEntityEvent(int entityID, PlayerData playerData) {
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
@Packet(Packet.Packets.HURT_ANIMATION)
|
||||
protected boolean handleHurtAnimation(int entityID, PlayerData playerData) {
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleRelativeMove(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processRelativeMovePacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleRelativeMoveAndRotation(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processRelativeMoveAndRotationPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleTeleport(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processTeleportPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handlePositionSync(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processPositionSyncPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityRotation(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processRotationPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityHeadLook(P packet, PlayerData playerData, int currentTick) {
|
||||
int entityID = processHeadLookPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityMetadata(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity != null) {
|
||||
processTrackedMetadata(packet, entity);
|
||||
}
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleRemoveEntityEffect(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
@Packet(Packet.Packets.ENTITY_EQUIPMENT)
|
||||
protected boolean handleEntityEquipment(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityVelocity(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
processEntityVelocityPacket(packet, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityEffect(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityPassengers(int entityID, int[] passengers, PlayerData playerData, int currentTick) {
|
||||
boolean bypassedVehicle = EntityBypassRegistry.isBypassed(entityID);
|
||||
NettyEntity<?> vehicle = bypassedVehicle ? null : playerData.entityFromID(entityID);
|
||||
int[] previousPassengers = getPreviousPassengerState(entityID, vehicle, playerData);
|
||||
playerData.nettyData().consumeUnresolvedPassengers(entityID); // throw away any unresolved passengers as this new packet will have the correct passenger list
|
||||
// "Stale" passengers are passengers that the previous authoritative state said were mounted,
|
||||
// but the new full replacement passenger list no longer contains.
|
||||
clearStalePassengerReferences(entityID, previousPassengers, passengers, playerData);
|
||||
if (vehicle == null) {
|
||||
playerData.nettyData().setUnresolvedPassengers(entityID, passengers);
|
||||
if (bypassedVehicle) {
|
||||
for (int passengerID : passengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
continue;
|
||||
}
|
||||
passenger.setVehicleID(entityID);
|
||||
forceVisibleBecauseAttached(passenger, playerData, currentTick, "bypassed vehicle passenger");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return handleEntityPassengersNow(vehicle, passengers, playerData, currentTick);
|
||||
}
|
||||
|
||||
//This (and leash handling) leaks some info to the client, as it will receive the passenger packet even if the passengers are auto-hidden once parsed, but as the packet doesn't include any location or type info, this shouldn't be too incriminating.
|
||||
boolean handleEntityPassengersNow(NettyEntity<?> entity, int[] passengers, PlayerData playerData, int currentTick) {
|
||||
int entityID = entity.entityID();
|
||||
entity.setPassengerIDs(passengers);
|
||||
int[] unresolvedPassengers = null;
|
||||
boolean selfIsPassenger = false;
|
||||
for (int passengerID : passengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
unresolvedPassengers = PrimitiveIntArrayList.add(unresolvedPassengers, passengerID);
|
||||
continue;
|
||||
}
|
||||
if (passenger.isSelfEntity()) {
|
||||
selfIsPassenger = true;
|
||||
}
|
||||
passenger.setVehicleID(entityID);
|
||||
}
|
||||
playerData.nettyData().setUnresolvedPassengers(entityID, unresolvedPassengers);
|
||||
checkVehicle(entity, playerData);
|
||||
boolean cancelForForcedVehicleShow = selfIsPassenger && forceVisibleBecauseAttached(entity, playerData, currentTick, "self-passenger vehicle");
|
||||
if (cancelForForcedVehicleShow) {
|
||||
return true;
|
||||
}
|
||||
if (cancelIfEnabledAndHidden(entityID, playerData)) return true;
|
||||
boolean passengersNotVisible = false;
|
||||
IntArrayList visiblePassengers = new IntArrayList(passengers.length);
|
||||
for (int passengerID : passengers) {
|
||||
if (EntityBypassRegistry.isBypassed(passengerID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (entity.isSelfEntity() && forceVisibleBecauseAttached(passenger, playerData, currentTick, "self-vehicle passenger")) {
|
||||
passengersNotVisible = true;
|
||||
// The direct SHOW path already makes this passenger client-visible. Keep it in the
|
||||
// replacement relationship packet so the packet does not undo the newly established mount.
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (entity.isSelfEntity() || passenger.isSelfEntity()) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
else if (cancelIfEnabledAndHidden(passenger, playerData)) {
|
||||
passengersNotVisible = true;
|
||||
}
|
||||
else {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (passengersNotVisible) {
|
||||
//some passengers are hidden but others aren't. Cancel this packet and send another silently with just the visible passengers.
|
||||
sendEntityPassengerPacket(entityID, visiblePassengers, playerData);
|
||||
}
|
||||
return passengersNotVisible;
|
||||
}
|
||||
|
||||
private int[] getPreviousPassengerState(int vehicleID, NettyEntity<?> vehicle, PlayerData playerData) {
|
||||
if (vehicle != null) {
|
||||
int[] previousPassengerIDs = vehicle.passengerIDs();
|
||||
if (!PrimitiveIntArrayList.isEmpty(previousPassengerIDs)) {
|
||||
return previousPassengerIDs;
|
||||
}
|
||||
}
|
||||
return playerData.nettyData().getUnresolvedPassengers(vehicleID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears reverse vehicle links for passengers that were part of the previous vehicle state,
|
||||
* but are absent from the new authoritative replacement list.
|
||||
*/
|
||||
private void clearStalePassengerReferences(int vehicleID, int[] previousPassengers, int[] newPassengers, PlayerData playerData) {
|
||||
if (PrimitiveIntArrayList.isEmpty(previousPassengers)) {
|
||||
return;
|
||||
}
|
||||
for (int previousPassengerID : previousPassengers) {
|
||||
if (PrimitiveIntArrayList.contains(newPassengers, previousPassengerID)) {
|
||||
continue;
|
||||
}
|
||||
NettyEntity<?> previousPassenger = playerData.entityFromID(previousPassengerID);
|
||||
if (previousPassenger != null && previousPassenger.vehicleID() == vehicleID) {
|
||||
previousPassenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkVehicle(NettyEntity<?> entity, PlayerData playerData) {
|
||||
int vehicleID = entity.vehicleID();
|
||||
if (vehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(vehicleID);
|
||||
if (vehicle == null) {
|
||||
return;
|
||||
}
|
||||
resendPassengerStateIfClientVisible(vehicle, playerData);
|
||||
}
|
||||
|
||||
protected void handleDestroyEntities(int[] entityIDs, PlayerData playerData, int currentTick) {
|
||||
for (int entityID : entityIDs) {
|
||||
if (playerData.nettyData().consumeExpectedWorldTransitionDestroyEntityID(entityID)) {
|
||||
playerData.nettyData().clearPendingPostSpawnTasksForEntity(entityID);
|
||||
playerData.entityView().removeEntity(entityID);
|
||||
playerData.playerView().removeEntity(entityID); // If not present, this fails silently, so no need to check for correct view first.
|
||||
continue;
|
||||
}
|
||||
clearPassengerReferencesForDestroyedEntity(entityID, playerData);
|
||||
clearLeashReferencesForDestroyedEntity(entityID, playerData);
|
||||
playerData.nettyData().clearPendingPostSpawnTasksForEntity(entityID);
|
||||
EntityView<?> view = playerData.viewFromEntityID(entityID);
|
||||
if (view == null) continue;
|
||||
Logger.debug("Removing entity from view due to destroy packet, entityID=" + entityID + " player=" + playerData.getPlayerUUID() + " tick=" + currentTick);
|
||||
view.removeEntity(entityID, currentTick);
|
||||
}
|
||||
}
|
||||
|
||||
private int[] drainRemainingEntityIDs(PlayerData playerData) {
|
||||
int[] entityIDs = playerData.entityView().getKnownEntityIDs();
|
||||
int[] playerEntityIDs = playerData.playerView().getKnownEntityIDs();
|
||||
int[] remainingEntityIDs = new int[entityIDs.length + playerEntityIDs.length];
|
||||
int offset = 0;
|
||||
System.arraycopy(entityIDs, 0, remainingEntityIDs, offset, entityIDs.length);
|
||||
offset += entityIDs.length;
|
||||
System.arraycopy(playerEntityIDs, 0, remainingEntityIDs, offset, playerEntityIDs.length);
|
||||
return remainingEntityIDs;
|
||||
}
|
||||
|
||||
private void clearPassengerReferencesForDestroyedEntity(int entityID, PlayerData playerData) {
|
||||
int[] unresolvedPassengers = playerData.nettyData().consumeUnresolvedPassengers(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(unresolvedPassengers)) {
|
||||
for (int passengerID : unresolvedPassengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && passenger.vehicleID() == entityID) {
|
||||
passenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int unresolvedVehicleID = playerData.nettyData().consumeUnresolvedVehicleForPassenger(entityID);
|
||||
if (unresolvedVehicleID != NO_VEHICLE) {
|
||||
NettyEntity<?> unresolvedVehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
if (unresolvedVehicle != null) {
|
||||
// this can occur if the vehicle existed at the time of the passenger packet but not the passenger, and somehow the passenger never got resolved to the vehicle (missing spawn packets etc). In reality this should never happen.
|
||||
unresolvedVehicle.setPassengerIDs(PrimitiveIntArrayList.remove(unresolvedVehicle.passengerIDs(), entityID));
|
||||
}
|
||||
}
|
||||
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int[] currentPassengerIDs = entity.passengerIDs();
|
||||
if (!PrimitiveIntArrayList.isEmpty(currentPassengerIDs)) {
|
||||
for (int passengerID : currentPassengerIDs) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && passenger.vehicleID() == entityID) {
|
||||
passenger.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int vehicleID = entity.vehicleID();
|
||||
if (vehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(vehicleID);
|
||||
if (vehicle != null) {
|
||||
vehicle.setPassengerIDs(PrimitiveIntArrayList.remove(vehicle.passengerIDs(), entityID));
|
||||
}
|
||||
entity.setVehicleID(NO_VEHICLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears both sides of resolved and unresolved leash relationships so a reused entity ID
|
||||
* cannot inherit relationships belonging to the destroyed entity.
|
||||
*/
|
||||
private void clearLeashReferencesForDestroyedEntity(int entityID, PlayerData playerData) {
|
||||
// Deferred relationships are indexed by both endpoints, so clear the cases where this ID
|
||||
// was the holder and where it was the leashed entity.
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().consumeUnresolvedLeashes(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null && leashedEntity.leashingEntity() == entityID) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pendingHolderEntityID = playerData.nettyData().consumeUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (pendingHolderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> pendingHolder = playerData.entityFromID(pendingHolderEntityID);
|
||||
if (pendingHolder != null) {
|
||||
pendingHolder.removeLeashedEntity(entityID);
|
||||
}
|
||||
}
|
||||
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// A tracked entity owns the same two relationship directions in its resolved state.
|
||||
int[] currentLeashedEntityIDs = entity.leashedEntityIDsOrNull();
|
||||
if (!PrimitiveIntArrayList.isEmpty(currentLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : currentLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null && leashedEntity.leashingEntity() == entityID) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
int holderEntityID = entity.leashingEntity();
|
||||
if (holderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> holder = playerData.entityFromID(holderEntityID);
|
||||
if (holder != null) {
|
||||
holder.removeLeashedEntity(entityID);
|
||||
}
|
||||
entity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleAttributeUpdate(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
@Packet(Packet.Packets.LEASH_ENTITY)
|
||||
protected boolean handleLeashEntity(int leashedEntityID, int holderEntityID, PlayerData playerData, int currentTick) {
|
||||
if (playerData.nettyData().isSelfEntityID(leashedEntityID) && playerData.nettyData().isSelfEntityID(holderEntityID)) {
|
||||
return false;
|
||||
}
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
removeExistingLeashReference(leashedEntityID, leashedEntity, playerData);
|
||||
|
||||
if (holderEntityID == NO_LEASHER) {
|
||||
return leashedEntity != null && cancelIfEnabledAndHidden(leashedEntity, playerData);
|
||||
}
|
||||
|
||||
NettyEntity<?> holderEntity = playerData.entityFromID(holderEntityID);
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(holderEntityID);
|
||||
}
|
||||
if (holderEntity != null) {
|
||||
holderEntity.addLeashedEntity(leashedEntityID);
|
||||
}
|
||||
if (leashedEntity == null || holderEntity == null) {
|
||||
playerData.nettyData().addUnresolvedLeash(holderEntityID, leashedEntityID);
|
||||
}
|
||||
|
||||
if (holderEntity != null && holderEntity.isSelfEntity() && leashedEntity != null
|
||||
&& forceVisibleBecauseAttached(leashedEntity, playerData, currentTick, "self-held leash")) {
|
||||
return true; // The visibility update repairs leash state, so suppress the packet to avoid sending it twice and before the client is aware of the entity.
|
||||
}
|
||||
return leashedEntity != null && cancelIfEnabledAndHidden(leashedEntity, playerData)
|
||||
|| holderEntity != null && cancelIfEnabledAndHidden(holderEntity, playerData);
|
||||
}
|
||||
|
||||
private boolean forceVisibleBecauseAttached(NettyEntity<?> entity, PlayerData self, int currentTick, String reason) {
|
||||
if (entity.isSelfEntity()) {
|
||||
return false;
|
||||
}
|
||||
boolean wasClientVisible = entity.clientVisible();
|
||||
EntityView<?> view = self.viewFromEntityID(entity.entityID());
|
||||
if (view == null) {
|
||||
Logger.warning("Could not find owning view while forcing attached entity visible, id=" + entity.entityID() + " player=" + self.getPlayerUUID() + " reason=" + reason, 6, PacketEntityViewController.class);
|
||||
// Note that this path can fire when a vehicle is bypassed, so its log level must be higher than default.
|
||||
return false;
|
||||
}
|
||||
boolean wasVisible = entity.visible();
|
||||
int worldEpoch = self.acquireWorldEpoch();
|
||||
if (!view.recordDirectVisibility(entity, true, currentTick, worldEpoch)) {
|
||||
return false;
|
||||
}
|
||||
if (!wasVisible || !wasClientVisible) {
|
||||
processDirectEntityShow(self, view, entity, worldEpoch);
|
||||
}
|
||||
return !wasClientVisible;
|
||||
}
|
||||
|
||||
private void removeExistingLeashReference(int leashedEntityID, NettyEntity<?> leashedEntity, PlayerData playerData) {
|
||||
int previousLeashingEntityID = leashedEntity == null
|
||||
? playerData.nettyData().getUnresolvedHolderForLeashedEntity(leashedEntityID)
|
||||
: leashedEntity.leashingEntity();
|
||||
if (previousLeashingEntityID == NO_LEASHER) {
|
||||
return;
|
||||
}
|
||||
playerData.nettyData().removeUnresolvedLeash(previousLeashingEntityID, leashedEntityID);
|
||||
NettyEntity<?> previousHolder = playerData.entityFromID(previousLeashingEntityID);
|
||||
if (previousHolder != null) {
|
||||
previousHolder.removeLeashedEntity(leashedEntityID);
|
||||
}
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(NO_LEASHER);
|
||||
}
|
||||
}
|
||||
|
||||
protected RaycastConfig getCorrectConfig(EntityView<?> entityView) {
|
||||
if (entityView.isPlayerView()) {
|
||||
return playerConfig;
|
||||
} else {
|
||||
return entityConfig;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the packet should be suppressed
|
||||
*/
|
||||
protected boolean cancelIfEnabledAndHidden(int entityID, PlayerData playerData) {
|
||||
if (playerData.nettyData().isSelfEntityID(entityID)) {
|
||||
return false;
|
||||
}
|
||||
EntityView<?> entityView = playerData.viewFromEntityID(entityID);
|
||||
|
||||
if (entityView == null) {
|
||||
Logger.warning("Checked if packet for entity should be cancelled, but entity did not exist. ID: " + entityID + " for player: " + playerData.getPlayerUUID(), 6, PacketEntityViewController.class);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entityView.isVisible(entityID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getCorrectConfig(entityView).enabled(); // If this statement is reached, the entity should be hidden, so if the config is enabled it is hidden.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the packet should be suppressed
|
||||
*/
|
||||
protected boolean cancelIfEnabledAndHidden(NettyEntity<?> entity, PlayerData playerData) {
|
||||
if (entity.isSelfEntity()) {
|
||||
return false;
|
||||
}
|
||||
if (entity.visible()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getCorrectConfig(playerData.viewFromEntityID(entity.entityID())).enabled(); // If this statement is reached, the entity should be hidden, so if the config is enabled it is hidden.
|
||||
}
|
||||
|
||||
/**
|
||||
* Replays any passenger relationship that was blocked earlier because either:
|
||||
* 1. this entity is the vehicle and one or more passengers were missing, or
|
||||
* 2. this entity is the passenger and the vehicle was already known.
|
||||
*/
|
||||
protected void reconcileUnresolvedPassengers(NettyEntity<?> insertedEntity, PlayerData playerData) {
|
||||
int[] pendingPassengers = playerData.nettyData().getUnresolvedPassengers(insertedEntity.entityID());
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingPassengers)) {
|
||||
playerData.nettyData().consumeUnresolvedPassengers(insertedEntity.entityID());
|
||||
handleEntityPassengersNow(insertedEntity, pendingPassengers, playerData, insertedEntity.lastChecked());
|
||||
}
|
||||
|
||||
int unresolvedVehicleID = playerData.nettyData().getUnresolvedVehicleForPassenger(insertedEntity.entityID());
|
||||
if (unresolvedVehicleID == NO_VEHICLE) {
|
||||
return;
|
||||
}
|
||||
if (EntityBypassRegistry.isBypassed(unresolvedVehicleID)) {
|
||||
insertedEntity.setVehicleID(unresolvedVehicleID);
|
||||
forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "bypassed vehicle unresolved passenger");
|
||||
return;
|
||||
}
|
||||
NettyEntity<?> vehicle = playerData.entityFromID(unresolvedVehicleID);
|
||||
if (vehicle == null) {
|
||||
return;
|
||||
}
|
||||
insertedEntity.setVehicleID(unresolvedVehicleID);
|
||||
playerData.nettyData().removeUnresolvedPassengerLink(insertedEntity.entityID(), unresolvedVehicleID);
|
||||
if (vehicle.isSelfEntity() && forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "self-vehicle unresolved passenger")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconciles relationship state which arrived before this entity was identified as bypassed.
|
||||
* The pending records are retained because a bypassed entity will never have a tracked entity
|
||||
* to own the authoritative relationship state.
|
||||
*/
|
||||
protected void handleBypassedEntitySpawn(int entityID, PlayerData playerData, int currentTick) {
|
||||
// Vanilla may send entity state before its spawn packet, and those packets were already
|
||||
// forwarded to the client. Discard deferred tracking work rather than replaying duplicates.
|
||||
playerData.nettyData().clearPendingPostSpawnTasksForEntity(entityID);
|
||||
int[] pendingPassengers = playerData.nettyData().getUnresolvedPassengers(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingPassengers)) {
|
||||
for (int passengerID : pendingPassengers) {
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger == null) {
|
||||
continue;
|
||||
}
|
||||
passenger.setVehicleID(entityID);
|
||||
forceVisibleBecauseAttached(passenger, playerData, currentTick, "bypassed vehicle passenger");
|
||||
}
|
||||
}
|
||||
|
||||
int holderEntityID = playerData.nettyData().getUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (holderEntityID != NO_LEASHER) {
|
||||
NettyEntity<?> holder = playerData.entityFromID(holderEntityID);
|
||||
if (holder != null) {
|
||||
holder.addLeashedEntity(entityID);
|
||||
}
|
||||
}
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().getUnresolvedLeashes(entityID);
|
||||
if (!PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity != null) {
|
||||
leashedEntity.setLeashingEntity(entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves deferred leash state into a newly tracked entity while retaining relationships whose
|
||||
* other endpoint is still untracked or permanently bypassed.
|
||||
*/
|
||||
protected void reconcileUnresolvedLeashes(NettyEntity<?> insertedEntity, PlayerData playerData) {
|
||||
int entityID = insertedEntity.entityID();
|
||||
int pendingHolderEntityID = playerData.nettyData().getUnresolvedHolderForLeashedEntity(entityID);
|
||||
if (pendingHolderEntityID != NO_LEASHER) {
|
||||
insertedEntity.setLeashingEntity(pendingHolderEntityID);
|
||||
NettyEntity<?> holder = playerData.entityFromID(pendingHolderEntityID);
|
||||
if (holder != null) {
|
||||
holder.addLeashedEntity(entityID);
|
||||
playerData.nettyData().removeUnresolvedLeash(pendingHolderEntityID, entityID);
|
||||
if (holder.isSelfEntity()) {
|
||||
forceVisibleBecauseAttached(insertedEntity, playerData, insertedEntity.lastChecked(), "self-held unresolved leash");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[] pendingLeashedEntityIDs = playerData.nettyData().getUnresolvedLeashes(entityID);
|
||||
if (PrimitiveIntArrayList.isEmpty(pendingLeashedEntityIDs)) {
|
||||
return;
|
||||
}
|
||||
for (int leashedEntityID : pendingLeashedEntityIDs) {
|
||||
NettyEntity<?> leashedEntity = playerData.entityFromID(leashedEntityID);
|
||||
if (leashedEntity == null) {
|
||||
if (EntityBypassRegistry.isBypassed(leashedEntityID)) {
|
||||
insertedEntity.addLeashedEntity(leashedEntityID);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
leashedEntity.setLeashingEntity(entityID);
|
||||
insertedEntity.addLeashedEntity(leashedEntityID);
|
||||
playerData.nettyData().removeUnresolvedLeash(entityID, leashedEntityID);
|
||||
if (insertedEntity.isSelfEntity()) {
|
||||
forceVisibleBecauseAttached(leashedEntity, playerData, leashedEntity.lastChecked(), "self-held unresolved leash");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean keepingClientEntityWhenHidden(NettyEntity<?> entity, PlayerData data) {
|
||||
if (entityConfig.keepClientEntityWhenHidden() == playerConfig.keepClientEntityWhenHidden()) {
|
||||
return entityConfig.keepClientEntityWhenHidden();
|
||||
}
|
||||
EntityView<?> view = data.viewFromEntityID(entity.entityID());
|
||||
return getCorrectConfig(view).keepClientEntityWhenHidden();
|
||||
}
|
||||
|
||||
protected void resendPassengerStateIfClientVisible(NettyEntity<?> vehicle, PlayerData playerData) {
|
||||
if (!vehicle.clientVisible() || (keepingClientEntityWhenHidden(vehicle, playerData) && !vehicle.visible())) {
|
||||
return;
|
||||
}
|
||||
sendEntityPassengerPacket(vehicle.entityID(), collectClientVisiblePassengers(vehicle.passengerIDs(), playerData), playerData);
|
||||
}
|
||||
|
||||
protected IntArrayList collectClientVisiblePassengers(int[] passengerIDs, PlayerData playerData) {
|
||||
// HackyEntityIDGuard reserves -1, so it cannot accidentally match an entity being shown.
|
||||
return collectClientVisiblePassengers(passengerIDs, playerData, -1);
|
||||
}
|
||||
|
||||
protected IntArrayList collectClientVisiblePassengers(int[] passengerIDs, PlayerData playerData, int entityBeingShownID) {
|
||||
int size = passengerIDs == null ? 0 : passengerIDs.length;
|
||||
IntArrayList visiblePassengers = new IntArrayList(size);
|
||||
if (passengerIDs == null) {
|
||||
return visiblePassengers;
|
||||
}
|
||||
for (int passengerID : passengerIDs) {
|
||||
if (EntityBypassRegistry.isBypassed(passengerID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
continue;
|
||||
}
|
||||
NettyEntity<?> passenger = playerData.entityFromID(passengerID);
|
||||
if (passenger != null && ((passenger.clientVisible() && (!keepingClientEntityWhenHidden(passenger, playerData) || passenger.visible())) || passenger.entityID() == entityBeingShownID)) {
|
||||
visiblePassengers.add(passengerID);
|
||||
}
|
||||
}
|
||||
return visiblePassengers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The created entity, with a default visibility of <code>true</code>. Must not return null. Does not insert the entity into any views, that is the responsibility of the caller.
|
||||
*/
|
||||
protected abstract NettyEntity<?> processEntitySpawn(PlayerData playerData, P packet, UUID world, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRelativeMovePacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRelativeMoveAndRotationPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processTeleportPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processPositionSyncPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
protected abstract void processTrackedMetadata(P packet, NettyEntity<?> entity);
|
||||
|
||||
protected abstract void cachePacket(P packet, int entityID, PlayerData playerData, int currentTick);
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRotationPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processHeadLookPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processEntityVelocityPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
/**Silently sends the provided array of entities as passengers for the required vehicle.*/
|
||||
protected abstract void sendEntityPassengerPacket(int vehicle, IntArrayList passengers, PlayerData playerData);
|
||||
|
||||
protected abstract void insertEntityToPlayerView(NettyEntity<?> entity, PlayerData playerData, UUID world);
|
||||
|
||||
protected abstract void insertEntityToEntityView(NettyEntity<?> entity, PlayerData playerData, UUID world);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
short-git: ${short_git}
|
||||
long-git: ${long_git}
|
||||
build-time: ${build_time}
|
||||
version: ${version}
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.ByteArrayBlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.CharArrayBlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.FourBlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.SingleBlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.SixteenBlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.TwoBlockChunkData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BlockChunkDataTest {
|
||||
private static final BlockInfoResolver FIRST_255_OCCLUDING = resolver(blockStateID -> blockStateID >= 0 && blockStateID < 255);
|
||||
private static final BlockInfoResolver ALL_SMALL_OCCLUDING = resolver(blockStateID -> blockStateID >= 0 && blockStateID < 512);
|
||||
|
||||
@Test
|
||||
void factorySelectsSmallestRepresentations() {
|
||||
assertInstanceOf(SingleBlockChunkData.class, fromStates(repeating(0), FIRST_255_OCCLUDING));
|
||||
assertInstanceOf(TwoBlockChunkData.class, fromStates(repeating(0, 1), FIRST_255_OCCLUDING));
|
||||
assertInstanceOf(FourBlockChunkData.class, fromStates(repeating(0, 1, 2, 3), FIRST_255_OCCLUDING));
|
||||
assertInstanceOf(SixteenBlockChunkData.class, fromStates(repeating(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), FIRST_255_OCCLUDING));
|
||||
assertInstanceOf(ByteArrayBlockChunkData.class, fromStates(repeating(uniqueWithNonOccludingTail(256)), FIRST_255_OCCLUDING));
|
||||
assertInstanceOf(CharArrayBlockChunkData.class, fromStates(repeating(uniqueWithNonOccludingTail(257)), FIRST_255_OCCLUDING));
|
||||
}
|
||||
|
||||
@Test
|
||||
void upgradesPreserveBlockIdsAndOcclusion() {
|
||||
char[] expected = new char[ChunkData.BLOCK_COUNT];
|
||||
BlockChunkData data = BlockChunkData.filled((char) 0, FIRST_255_OCCLUDING);
|
||||
|
||||
for (int packed = 1; packed <= 256; packed++) {
|
||||
data = setPacked(data, packed, (char) packed);
|
||||
expected[packed] = (char) packed;
|
||||
|
||||
if (packed == 1) {
|
||||
assertInstanceOf(TwoBlockChunkData.class, data);
|
||||
} else if (packed == 2 || packed == 3) {
|
||||
assertInstanceOf(FourBlockChunkData.class, data);
|
||||
} else if (packed >= 4 && packed <= 15) {
|
||||
assertInstanceOf(SixteenBlockChunkData.class, data);
|
||||
} else if (packed >= 16 && packed <= 255) {
|
||||
assertInstanceOf(ByteArrayBlockChunkData.class, data);
|
||||
} else {
|
||||
assertInstanceOf(CharArrayBlockChunkData.class, data);
|
||||
}
|
||||
}
|
||||
|
||||
assertMatches(expected, data, FIRST_255_OCCLUDING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void quarterByteWritesDoNotCorruptNeighboringCells() {
|
||||
BlockChunkData data = fromStates(repeating(0, 1, 2, 3), FIRST_255_OCCLUDING);
|
||||
assertInstanceOf(FourBlockChunkData.class, data);
|
||||
|
||||
data = setPacked(data, 0, (char) 2);
|
||||
assertEquals(2, getPacked(data, 0));
|
||||
assertEquals(1, getPacked(data, 1));
|
||||
assertEquals(2, getPacked(data, 2));
|
||||
assertEquals(3, getPacked(data, 3));
|
||||
|
||||
data = setPacked(data, 3, (char) 0);
|
||||
assertEquals(2, getPacked(data, 0));
|
||||
assertEquals(1, getPacked(data, 1));
|
||||
assertEquals(2, getPacked(data, 2));
|
||||
assertEquals(0, getPacked(data, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void halfByteWritesDoNotCorruptNeighboringCells() {
|
||||
BlockChunkData data = fromStates(repeating(0, 1, 2, 3, 4), FIRST_255_OCCLUDING);
|
||||
assertInstanceOf(SixteenBlockChunkData.class, data);
|
||||
|
||||
data = setPacked(data, 0, (char) 4);
|
||||
assertEquals(4, getPacked(data, 0));
|
||||
assertEquals(1, getPacked(data, 1));
|
||||
|
||||
data = setPacked(data, 1, (char) 3);
|
||||
assertEquals(4, getPacked(data, 0));
|
||||
assertEquals(3, getPacked(data, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bytePaletteIndex255Works() {
|
||||
char[] blockIDs = new char[ChunkData.BLOCK_COUNT];
|
||||
for (int packed = 0; packed < 255; packed++) {
|
||||
blockIDs[packed] = (char) packed;
|
||||
}
|
||||
blockIDs[255] = 1000;
|
||||
|
||||
BlockChunkData data = fromStates(blockIDs, FIRST_255_OCCLUDING);
|
||||
|
||||
assertInstanceOf(ByteArrayBlockChunkData.class, data);
|
||||
assertEquals(254, getPacked(data, 254));
|
||||
assertEquals(1000, getPacked(data, 255));
|
||||
assertTrue(isOccludingPacked(data, 254));
|
||||
assertFalse(isOccludingPacked(data, 255));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allOccludingByteBoundaryStaysByteArray() {
|
||||
char[] blockIDs = new char[ChunkData.BLOCK_COUNT];
|
||||
for (int packed = 0; packed < 256; packed++) {
|
||||
blockIDs[packed] = (char) packed;
|
||||
}
|
||||
|
||||
BlockChunkData data = fromStates(blockIDs, ALL_SMALL_OCCLUDING);
|
||||
|
||||
assertInstanceOf(ByteArrayBlockChunkData.class, data);
|
||||
for (int packed = 0; packed < 256; packed++) {
|
||||
assertEquals(packed, getPacked(data, packed));
|
||||
assertTrue(isOccludingPacked(data, packed));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void palettedOcclusionDoesNotDependOnPaletteAppendOrder() {
|
||||
BlockInfoResolver oddOccluding = resolver(blockStateID -> (blockStateID & 1) == 1);
|
||||
char[] blockIDs = repeating(2, 1, 4, 3);
|
||||
|
||||
BlockChunkData data = fromStates(blockIDs, oddOccluding);
|
||||
|
||||
assertInstanceOf(FourBlockChunkData.class, data);
|
||||
assertMatches(blockIDs, data, oddOccluding);
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidLocalCoordinatesThrow() {
|
||||
BlockChunkData single = BlockChunkData.filled((char) 0, FIRST_255_OCCLUDING);
|
||||
assertThrows(IllegalArgumentException.class, () -> single.getBlockID(-1, 0, 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> single.setBlockID(0, 16, 0, (char) 0, FIRST_255_OCCLUDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> single.isOccludingLocal(0, 0, 16));
|
||||
|
||||
BlockChunkData paletted = fromStates(repeating(0, 1, 2, 3), FIRST_255_OCCLUDING);
|
||||
assertThrows(IllegalArgumentException.class, () -> paletted.getBlockID(-1, 0, 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> paletted.setBlockID(0, 16, 0, (char) 2, FIRST_255_OCCLUDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> paletted.isOccludingLocal(0, 0, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
void paletteFactoryDiscardsUnusedEntriesAndUsesCorePackedPositions() {
|
||||
char[] sourcePalette = {(char) 0, (char) 7, (char) 8, (char) 9};
|
||||
int target = ChunkData.packUncheckedGuarded(3, 2, 1);
|
||||
BlockChunkData data = BlockChunkData.copyOfPalette(sourcePalette, packed -> packed == target ? 2 : 1, FIRST_255_OCCLUDING);
|
||||
|
||||
assertInstanceOf(TwoBlockChunkData.class, data);
|
||||
assertEquals(8, data.getBlockID(3, 2, 1));
|
||||
assertEquals(7, data.getBlockID(1, 2, 3));
|
||||
}
|
||||
|
||||
private static BlockInfoResolver resolver(IntPredicate occluding) {
|
||||
return new BlockInfoResolver() {
|
||||
@Override
|
||||
public boolean isOccluding(int blockStateID) {
|
||||
return occluding.test(blockStateID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTileEntity(int blockStateID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBlockEntityData(int blockStateID) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static BlockChunkData fromStates(char[] blockIDs, BlockInfoResolver blockInfoResolver) {
|
||||
return BlockChunkData.copyOfStates(packed -> blockIDs[packed], blockInfoResolver);
|
||||
}
|
||||
|
||||
private static char[] repeating(int... blockIDs) {
|
||||
char[] converted = new char[blockIDs.length];
|
||||
for (int i = 0; i < blockIDs.length; i++) {
|
||||
converted[i] = (char) blockIDs[i];
|
||||
}
|
||||
return repeating(converted);
|
||||
}
|
||||
|
||||
private static char[] repeating(char[] blockIDs) {
|
||||
char[] data = new char[ChunkData.BLOCK_COUNT];
|
||||
for (int packed = 0; packed < data.length; packed++) {
|
||||
data[packed] = blockIDs[packed % blockIDs.length];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static char[] uniqueWithNonOccludingTail(int uniqueCount) {
|
||||
char[] blockIDs = new char[uniqueCount];
|
||||
int occludingCount = Math.min(uniqueCount, 255);
|
||||
for (int i = 0; i < occludingCount; i++) {
|
||||
blockIDs[i] = (char) i;
|
||||
}
|
||||
for (int i = occludingCount; i < uniqueCount; i++) {
|
||||
blockIDs[i] = (char) (1000 + i);
|
||||
}
|
||||
return blockIDs;
|
||||
}
|
||||
|
||||
private static BlockChunkData setPacked(BlockChunkData data, int packed, char blockID) {
|
||||
return data.setBlockID(ChunkData.unpackX(packed), ChunkData.unpackY(packed), ChunkData.unpackZ(packed), blockID, FIRST_255_OCCLUDING);
|
||||
}
|
||||
|
||||
private static char getPacked(BlockChunkData data, int packed) {
|
||||
return data.getBlockID(ChunkData.unpackX(packed), ChunkData.unpackY(packed), ChunkData.unpackZ(packed));
|
||||
}
|
||||
|
||||
private static boolean isOccludingPacked(BlockChunkData data, int packed) {
|
||||
return data.isOccludingLocal(ChunkData.unpackX(packed), ChunkData.unpackY(packed), ChunkData.unpackZ(packed));
|
||||
}
|
||||
|
||||
private static void assertMatches(char[] expected, BlockChunkData data, BlockInfoResolver blockInfoResolver) {
|
||||
for (int packed = 0; packed < expected.length; packed++) {
|
||||
int packedIndex = packed;
|
||||
char expectedBlockID = expected[packed];
|
||||
assertEquals(expectedBlockID, getPacked(data, packed), () -> "block ID mismatch at packed index " + packedIndex);
|
||||
assertEquals(blockInfoResolver.isOccluding(expectedBlockID), isOccludingPacked(data, packed), () -> "occlusion mismatch at packed index " + packedIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 192 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user