Compare commits
595 Commits
1.12.2-R0.
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c3b8e3239 | ||
|
|
b7527d1dba | ||
|
|
4d2519d0b0 | ||
|
|
47e8f5dae4 | ||
|
|
cff1a2d7fb | ||
|
|
a7e2207be5 | ||
|
|
a8ba53b243 | ||
|
|
e627088d55 | ||
|
|
2eef58a9e3 | ||
|
|
ff35e4a14b | ||
|
|
f4428b79a1 | ||
|
|
cd0007d17f | ||
|
|
0cdbe546b5 | ||
|
|
48bc7a76a6 | ||
|
|
c52b1a2464 | ||
|
|
8b617ed169 | ||
|
|
b6d360e399 | ||
|
|
ea47663e3c | ||
|
|
baf64bb7a0 | ||
|
|
13b6dd77c8 | ||
|
|
8e0d49c722 | ||
|
|
88f3d2bb91 | ||
|
|
561b80c7fa | ||
|
|
752fc2981a | ||
|
|
b66854b35a | ||
|
|
d6400a0a68 | ||
|
|
9680395435 | ||
|
|
9e71f569dc | ||
|
|
104045e04d | ||
|
|
c398827cba | ||
|
|
1746d7b012 | ||
|
|
8a5d8fdaea | ||
|
|
09136ba60d | ||
|
|
7bec837bdb | ||
|
|
cfb02cf611 | ||
|
|
4d9c01aa87 | ||
|
|
39670d24e1 | ||
|
|
dd01cae8fe | ||
|
|
0098d0c20d | ||
|
|
d8ea0f157a | ||
|
|
13d3cb28e4 | ||
|
|
a15099f9e8 | ||
|
|
490ae739a4 | ||
|
|
7dcfc130d2 | ||
|
|
0e9940771e | ||
|
|
ee8e09fe58 | ||
|
|
b74ec9aa2e | ||
|
|
ea8292aaf9 | ||
|
|
7b47710c42 | ||
|
|
d34531aa84 | ||
|
|
30bb7a43fb | ||
|
|
9a54ba116e | ||
|
|
a3cc630375 | ||
|
|
e5081d4575 | ||
|
|
852acc0d65 | ||
|
|
7e756e786d | ||
|
|
62848df6de | ||
|
|
f5a531a15c | ||
|
|
ba3d1c9672 | ||
|
|
fa08306751 | ||
|
|
9a8d4c35a9 | ||
|
|
adf961666a | ||
|
|
947b22892c | ||
|
|
0d9f04a748 | ||
|
|
26652d43fc | ||
|
|
ac24d10a57 | ||
|
|
f220a6a153 | ||
|
|
233aab099e | ||
|
|
5268e9a55a | ||
|
|
83c30311d0 | ||
|
|
6a7f2b8699 | ||
|
|
cb55572504 | ||
|
|
9d5c535d18 | ||
|
|
b46cddd84d | ||
|
|
936cf720f4 | ||
|
|
9b6412766f | ||
|
|
d847e87c65 | ||
|
|
ff8c0cd3be | ||
|
|
19991463bf | ||
|
|
c2931e362e | ||
|
|
e912498dac | ||
|
|
98a7b4d757 | ||
|
|
62aa216b48 | ||
|
|
1a56f7ac75 | ||
|
|
0080380486 | ||
|
|
e7419af0de | ||
|
|
371817ab85 | ||
|
|
9ad318d4bb | ||
|
|
e066c5e12c | ||
|
|
cfa99ef96e | ||
|
|
03bcac33d7 | ||
|
|
fcbda069fc | ||
|
|
27561af9d8 | ||
|
|
ecb47cc23f | ||
|
|
2fd9d75ba7 | ||
|
|
69c5da47a0 | ||
|
|
c46b459f08 | ||
|
|
a540b150aa | ||
|
|
16eb219b60 | ||
|
|
3dac5cebbf | ||
|
|
78a3fb3aad | ||
|
|
df97aca45f | ||
|
|
a0daa4f40e | ||
|
|
ebf0968fd3 | ||
|
|
a0d41a8dea | ||
|
|
8101d7b1a7 | ||
|
|
9a0558d218 | ||
|
|
6d023d0ff5 | ||
|
|
26d65b8875 | ||
|
|
b65309abd3 | ||
|
|
e07860fb92 | ||
|
|
9491da6b8f | ||
|
|
4d57eb6172 | ||
|
|
2920fa4993 | ||
|
|
48574c2eb4 | ||
|
|
233199054e | ||
|
|
fe6068d6de | ||
|
|
a9a9b933f5 | ||
|
|
d082c42898 | ||
|
|
d784d03289 | ||
|
|
3702d83f80 | ||
|
|
ebd4a75b88 | ||
|
|
d45dde48f1 | ||
|
|
55878409ac | ||
|
|
5f0eca806a | ||
|
|
5e656d02eb | ||
|
|
e407443ca9 | ||
|
|
345faccac7 | ||
|
|
0dcd33f41b | ||
|
|
10a0c82475 | ||
|
|
2871e0dc81 | ||
|
|
15ab29a426 | ||
|
|
93cac1aeea | ||
|
|
55bbbdfbf2 | ||
|
|
01555f49a0 | ||
|
|
4c40903958 | ||
|
|
74d0113b46 | ||
|
|
1db625034e | ||
|
|
6fbd890884 | ||
|
|
3411916593 | ||
|
|
9e2b072bc6 | ||
|
|
cf03617415 | ||
|
|
d2c3477e59 | ||
|
|
6c9c9bef6e | ||
|
|
4a48e19dcc | ||
|
|
0e44c002df | ||
|
|
cbe1830f1c | ||
|
|
c7e7d1a40b | ||
|
|
daf6af0269 | ||
|
|
b510185638 | ||
|
|
0eaeb3b28c | ||
|
|
a2fad07eb6 | ||
|
|
f07072102b | ||
|
|
94264a57a3 | ||
|
|
83f71f673b | ||
|
|
3794ab48c1 | ||
|
|
643f313789 | ||
|
|
573d187e38 | ||
|
|
2e9075e2d7 | ||
|
|
db9cf4e5a2 | ||
|
|
08c6269f3e | ||
|
|
d25176aff1 | ||
|
|
f5fc1e6b64 | ||
|
|
000ea6409b | ||
|
|
925e91c99e | ||
|
|
b1b3efae8d | ||
|
|
a00d3645e1 | ||
|
|
95d3bc3529 | ||
|
|
677914bd39 | ||
|
|
e82e06c760 | ||
|
|
e40656e7f2 | ||
|
|
676173300f | ||
|
|
2d45820922 | ||
|
|
bdbec60f02 | ||
|
|
433e18e7d2 | ||
|
|
21d24bdfa5 | ||
|
|
4eec855840 | ||
|
|
dbe68a55d4 | ||
|
|
08d22009b7 | ||
|
|
0f32cb2ee9 | ||
|
|
fc47e66e4c | ||
|
|
8778323b0c | ||
|
|
8751adbf1b | ||
|
|
742fe4e0a3 | ||
|
|
3d75fe1118 | ||
|
|
a1c3051508 | ||
|
|
da57bfbf57 | ||
|
|
54e05c84f6 | ||
|
|
9fd22502b2 | ||
|
|
5551f505a1 | ||
|
|
8f421ffb2a | ||
|
|
7fe2637206 | ||
|
|
362c9561dd | ||
|
|
fa1cf770f4 | ||
|
|
4758e8aeef | ||
|
|
998b18d2d8 | ||
|
|
b5b7684c58 | ||
|
|
48604bc9a6 | ||
|
|
2f4b0a7a88 | ||
|
|
16a91e1e31 | ||
|
|
d64d8eb5f8 | ||
|
|
e10f2ae716 | ||
|
|
e62e662196 | ||
|
|
6c425fa820 | ||
|
|
29385180ab | ||
|
|
295d11b87a | ||
|
|
fda0839d62 | ||
|
|
6002e2e6d2 | ||
|
|
b23baff1d8 | ||
|
|
05ea8eda44 | ||
|
|
84de7a43fc | ||
|
|
3a53619460 | ||
|
|
fd6f9ef9f3 | ||
|
|
bcea435a88 | ||
|
|
8d669910f6 | ||
|
|
5f3843eb14 | ||
|
|
c407e63047 | ||
|
|
c60d1f672e | ||
|
|
ff6b2d60ab | ||
|
|
1cde35cfc1 | ||
|
|
49cfe2d8e6 | ||
|
|
19f2be2d7d | ||
|
|
8ce60a6575 | ||
|
|
1fffe53720 | ||
|
|
c33f5cea3b | ||
|
|
bc27b6b11d | ||
|
|
ea9589df5c | ||
|
|
53e8b9cf2a | ||
|
|
1d0b02d8d3 | ||
|
|
7436817e08 | ||
|
|
7b6f58c979 | ||
|
|
7f12dd9c28 | ||
|
|
973d4d56c2 | ||
|
|
db31b8edde | ||
|
|
2aabcc3bb1 | ||
|
|
9e83056973 | ||
|
|
7d268c178c | ||
|
|
4ed193b1dd | ||
|
|
1445ea5401 | ||
|
|
950662e652 | ||
|
|
9686940a08 | ||
|
|
46c2fd8790 | ||
|
|
53b7a9095c | ||
|
|
1803ed497f | ||
|
|
9931749781 | ||
|
|
5721388795 | ||
|
|
7e195b8bd9 | ||
|
|
3929f61633 | ||
|
|
d9b608826a | ||
|
|
30f216b3c5 | ||
|
|
663953230d | ||
|
|
18868c715c | ||
|
|
26e0546b50 | ||
|
|
1708888915 | ||
|
|
a4c72a2762 | ||
|
|
a096eeadb1 | ||
|
|
47fc205ba4 | ||
|
|
8a9d3acc05 | ||
|
|
c4db74f13a | ||
|
|
044759f197 | ||
|
|
c120dafe85 | ||
|
|
3cf50c844d | ||
|
|
fbeb9840ea | ||
|
|
82106ee8b6 | ||
|
|
a74aa135ae | ||
|
|
0201722e69 | ||
|
|
cbf71003ff | ||
|
|
90f6d0e9ba | ||
|
|
4290216041 | ||
|
|
33b5d7fb22 | ||
|
|
ac1d99be3b | ||
|
|
d282f46a5b | ||
|
|
a1dee4e1b6 | ||
|
|
e8e6eb230d | ||
|
|
5fd8d633cb | ||
|
|
473190dc17 | ||
|
|
ce64d00b3a | ||
|
|
810c8a5d00 | ||
|
|
768ac2f14c | ||
|
|
183c5fc53d | ||
|
|
5e51b97d27 | ||
|
|
dbd6e66ab9 | ||
|
|
8cb2bc2356 | ||
|
|
48ff1679fe | ||
|
|
8f77cd21b5 | ||
|
|
a825d60641 | ||
|
|
64f74e19a0 | ||
|
|
a741a4336c | ||
|
|
6946210cf9 | ||
|
|
e412d13ccc | ||
|
|
a74603ce85 | ||
|
|
b9a14c436f | ||
|
|
3ff1a9d072 | ||
|
|
0174722008 | ||
|
|
7475c7fb8f | ||
|
|
41da0735ba | ||
|
|
843e612652 | ||
|
|
739614b286 | ||
|
|
04502d021b | ||
|
|
2bc7a3b190 | ||
|
|
1cbd868bdf | ||
|
|
c54d83cedc | ||
|
|
d9040bf6f3 | ||
|
|
a877b1903f | ||
|
|
a768ef41c6 | ||
|
|
22d100f9f4 | ||
|
|
1e57476b41 | ||
|
|
d5e59449fd | ||
|
|
3b20dbd3f8 | ||
|
|
ec977b85e9 | ||
|
|
c22d51f944 | ||
|
|
c05abe18b1 | ||
|
|
da6685793d | ||
|
|
55b7a1bfed | ||
|
|
0f9e51fd0b | ||
|
|
bfca47a782 | ||
|
|
f2563e1f76 | ||
|
|
a5d9181450 | ||
|
|
f1b3273cba | ||
|
|
1028ea8ff8 | ||
|
|
3d562bec84 | ||
|
|
610ec6d52e | ||
|
|
27a7b2a823 | ||
|
|
cb3fe4a4c2 | ||
|
|
b894a5256a | ||
|
|
b99ec14a99 | ||
|
|
4f2510bb51 | ||
|
|
24360a8085 | ||
|
|
367f5e2e87 | ||
|
|
91e0140620 | ||
|
|
24b26ab846 | ||
|
|
c0df425445 | ||
|
|
389c787eb9 | ||
|
|
685b07f51d | ||
|
|
43adb03349 | ||
|
|
d742c096c6 | ||
|
|
8071a603ba | ||
|
|
889b6ea5ba | ||
|
|
2df37be2e2 | ||
|
|
36543cabf5 | ||
|
|
2173b1e2bc | ||
|
|
6e9351caaf | ||
|
|
eb28c5ae38 | ||
|
|
ae6de9567f | ||
|
|
a6c252130f | ||
|
|
5b2147cef5 | ||
|
|
a4836cf014 | ||
|
|
a924263f2f | ||
|
|
eb4ac897c7 | ||
|
|
090ab24a6b | ||
|
|
445f6f185d | ||
|
|
3c198efd87 | ||
|
|
8fa3e82671 | ||
|
|
7381ae8793 | ||
|
|
ac5291d8e4 | ||
|
|
57b84f327b | ||
|
|
4529c0237a | ||
|
|
0dfabac80f | ||
|
|
7c4a81bcb6 | ||
|
|
263cf75f49 | ||
|
|
005b2d2097 | ||
|
|
13b5b7cc13 | ||
|
|
1bc90004ca | ||
|
|
8a41fa0401 | ||
|
|
043b87f4ef | ||
|
|
6da2ca1f67 | ||
|
|
f0044d7d07 | ||
|
|
ea18e73509 | ||
|
|
f24d488601 | ||
|
|
a3501fb8dd | ||
|
|
70b75489f2 | ||
|
|
abe730886a | ||
|
|
645293ed0e | ||
|
|
00859a2e18 | ||
|
|
d643cae29f | ||
|
|
9aa63c56ab | ||
|
|
b06e5f3e13 | ||
|
|
f2a81f8a1e | ||
|
|
7487ac4edf | ||
|
|
07a8521999 | ||
|
|
1879eebd8f | ||
|
|
679236cfb9 | ||
|
|
5fe93610c9 | ||
|
|
f73c20e342 | ||
|
|
8e6000c523 | ||
|
|
2f87a4c54e | ||
|
|
751fcb584d | ||
|
|
10d2d285d9 | ||
|
|
818f5559f7 | ||
|
|
bf7f6fe3bc | ||
|
|
7acc339704 | ||
|
|
f0d17e54e9 | ||
|
|
01c40ed0d3 | ||
|
|
4fdc9f0166 | ||
|
|
3b4926bed2 | ||
|
|
7e0f44f0af | ||
|
|
b41e4fd8c3 | ||
|
|
241a8ffefa | ||
|
|
c2748ea2df | ||
|
|
e563233ff3 | ||
|
|
9a5de6cf31 | ||
|
|
9f7b490f61 | ||
|
|
6dceb465c3 | ||
|
|
17ba164cbc | ||
|
|
bb19cf0f7a | ||
|
|
0a59c8ce5f | ||
|
|
5d5bb381c0 | ||
|
|
05cc09ff51 | ||
|
|
2ba4bc2755 | ||
|
|
9b5b40c002 | ||
|
|
a0545a756d | ||
|
|
6e62515d11 | ||
|
|
ff100c348e | ||
|
|
a25ff5dd93 | ||
|
|
c6dbae3c24 | ||
|
|
b2bafb826f | ||
|
|
fb20bb3113 | ||
|
|
927d946dba | ||
|
|
9ceec10f18 | ||
|
|
74353989e4 | ||
|
|
c2705d4722 | ||
|
|
b743d7dc4c | ||
|
|
601ec9e90d | ||
|
|
6dcd61f2c7 | ||
|
|
c42528f4f1 | ||
|
|
402d9d2536 | ||
|
|
6ba139a83e | ||
|
|
0690cb1c9f | ||
|
|
b8879db641 | ||
|
|
a3cc6062b6 | ||
|
|
dba9fad220 | ||
|
|
af7444df09 | ||
|
|
2def9e628a | ||
|
|
1641f2767f | ||
|
|
f2c15275e9 | ||
|
|
c58612f271 | ||
|
|
4d44c9f8cc | ||
|
|
3d34b1e011 | ||
|
|
032ffea438 | ||
|
|
2b6175edcb | ||
|
|
c06c7e2776 | ||
|
|
af678041f0 | ||
|
|
5c03cad4f2 | ||
|
|
6de709c4c6 | ||
|
|
bca8f20393 | ||
|
|
144c9e08f5 | ||
|
|
bd47cab2ff | ||
|
|
4c7da04d9f | ||
|
|
cf300713b4 | ||
|
|
4c93b2b13a | ||
|
|
78ddbbd7c7 | ||
|
|
ecb28a58a6 | ||
|
|
9e62b22fb8 | ||
|
|
2ace17105f | ||
|
|
528ab01026 | ||
|
|
87583d4e7c | ||
|
|
f77f039dbb | ||
|
|
3fbba5de34 | ||
|
|
79d3980be2 | ||
|
|
280db63b42 | ||
|
|
f93abbf076 | ||
|
|
03a5ef5149 | ||
|
|
58de950203 | ||
|
|
2887399202 | ||
|
|
cbfe35f062 | ||
|
|
1a330a4c07 | ||
|
|
c932a0d1b1 | ||
|
|
515e9d86b9 | ||
|
|
5f917f8253 | ||
|
|
cede9c99fa | ||
|
|
fd733df52a | ||
|
|
5f6671cd50 | ||
|
|
ff00b7556e | ||
|
|
3875266bb7 | ||
|
|
ca8e0d7c0f | ||
|
|
269e1c30f1 | ||
|
|
79d0207801 | ||
|
|
a2c09040b4 | ||
|
|
c50f6f2a68 | ||
|
|
9cfe108024 | ||
|
|
545ce61711 | ||
|
|
e881bb1c23 | ||
|
|
c926121dd6 | ||
|
|
b859bf6b4d | ||
|
|
5113e99853 | ||
|
|
68b4db992f | ||
|
|
2765bb8891 | ||
|
|
067b86b7cc | ||
|
|
08013d2b4a | ||
|
|
a6a51f9805 | ||
|
|
d223e4ad00 | ||
|
|
44d1491789 | ||
|
|
e82a99d4d8 | ||
|
|
5e912befc0 | ||
|
|
45d6b0c072 | ||
|
|
d596840e83 | ||
|
|
9e06a9fe5c | ||
|
|
452dd1f3b5 | ||
|
|
8dbfbd2650 | ||
|
|
fc17d8fdc7 | ||
|
|
bbd1057666 | ||
|
|
671c5fbc49 | ||
|
|
405a299b36 | ||
|
|
8b6de7576a | ||
|
|
f6f2d1121c | ||
|
|
8a6c36ab2c | ||
|
|
4c622207e1 | ||
|
|
8db031c856 | ||
|
|
7c6627edc8 | ||
|
|
343666756c | ||
|
|
99b9880f0e | ||
|
|
022a6468d5 | ||
|
|
9d5d638670 | ||
|
|
4e920243d1 | ||
|
|
239f83e1d3 | ||
|
|
93588656d1 | ||
|
|
8a9ad35a57 | ||
|
|
e4ed177d7b | ||
|
|
fb7bf16869 | ||
|
|
1e93929534 | ||
|
|
30f6e3f56f | ||
|
|
c55568a01c | ||
|
|
04ff47a598 | ||
|
|
fdec006644 | ||
|
|
3eb2067ffa | ||
|
|
b89d955eb5 | ||
|
|
54205afb71 | ||
|
|
711fc08eeb | ||
|
|
e8dfb64f42 | ||
|
|
a78ae42d9c | ||
|
|
f7792c2510 | ||
|
|
9fedd2d94e | ||
|
|
cf62349837 | ||
|
|
1d9f3a0584 | ||
|
|
8925ac73d4 | ||
|
|
5c39b7eabd | ||
|
|
d8f0674b89 | ||
|
|
cda8c79514 | ||
|
|
080b080c15 | ||
|
|
19e1d0d927 | ||
|
|
974cf681d0 | ||
|
|
3e38351ce7 | ||
|
|
dc30e8c8d5 | ||
|
|
427a4152f3 | ||
|
|
68816a0b5a | ||
|
|
f6e54678bb | ||
|
|
aed67213c2 | ||
|
|
9038d2d2b6 | ||
|
|
eb96ab4f5b | ||
|
|
89ca2f2bc5 | ||
|
|
97798e18ce | ||
|
|
db54c87abd | ||
|
|
f45908ae38 | ||
|
|
2b49aba77c | ||
|
|
bc2a639c52 | ||
|
|
3938713380 | ||
|
|
dc10b10979 | ||
|
|
876bf4d7cd | ||
|
|
3ee0111f24 | ||
|
|
42a90440b9 | ||
|
|
b58e98e0de | ||
|
|
dc9c0655de | ||
|
|
c3e9767dbc | ||
|
|
01ecfef964 | ||
|
|
8a7ebe839c | ||
|
|
c11a88d1ba | ||
|
|
9626867217 | ||
|
|
55248e4deb | ||
|
|
095a6e4d0b | ||
|
|
559896e14b | ||
|
|
6855fbe294 | ||
|
|
41d97284be | ||
|
|
b4f557ccb1 | ||
|
|
5f936eb1b7 | ||
|
|
f46e63958b | ||
|
|
68833e6726 | ||
|
|
3a1e04cfbb | ||
|
|
0f00949e6f | ||
|
|
24d0c6a541 | ||
|
|
474d9ecb6a | ||
|
|
2282ca02b7 | ||
|
|
ab9aaa6195 | ||
|
|
f89f26e2db | ||
|
|
7bdc57cb70 | ||
|
|
b4da072470 | ||
|
|
c43b8592c9 | ||
|
|
a17a194c6a | ||
|
|
7856043ed6 | ||
|
|
69e6cc1fea | ||
|
|
8a3ddb716e | ||
|
|
ccb3bb9865 | ||
|
|
f0df6a62c4 | ||
|
|
16f172a4d1 | ||
|
|
1bd0498f86 | ||
|
|
5a90c8d8fd |
50
.circleci/config.yml
Normal file
50
.circleci/config.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
working_directory: ~/Akarin-project/Akarin
|
||||
parallelism: 1
|
||||
shell: /bin/bash --login
|
||||
environment:
|
||||
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
|
||||
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
|
||||
docker:
|
||||
- image: circleci/build-image:ubuntu-14.04-XXL-upstart-1189-5614f37
|
||||
command: /sbin/init
|
||||
steps:
|
||||
# Machine Setup
|
||||
- checkout
|
||||
# Prepare for artifact
|
||||
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
|
||||
- run:
|
||||
working_directory: ~/Akarin-project/Akarin
|
||||
command: sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac; echo -e "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64" >> $BASH_ENV
|
||||
# Dependencies
|
||||
# Restore the dependency cache
|
||||
- restore_cache:
|
||||
keys:
|
||||
# This branch if available
|
||||
- v1-dep-{{ .Branch }}-
|
||||
# Default branch if not
|
||||
- v1-dep-ver/1.12.2-
|
||||
# Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
|
||||
- v1-dep-
|
||||
- run: git config --global user.email "circle@circleci.com"
|
||||
- run: git config --global user.name "CircleCI"
|
||||
- run: chmod +x scripts/inst.sh
|
||||
- run: ./scripts/inst.sh --setup --remote
|
||||
# Save dependency cache
|
||||
- save_cache:
|
||||
key: v1-dep-{{ .Branch }}-{{ epoch }}
|
||||
paths:
|
||||
- ~/.m2
|
||||
# Test
|
||||
- run: yes|cp -rf ./akarin-*.jar $CIRCLE_ARTIFACTS
|
||||
# Teardown
|
||||
# Save test results
|
||||
- store_test_results:
|
||||
path: /tmp/circleci-test-results
|
||||
# Save artifacts
|
||||
- store_artifacts:
|
||||
path: /tmp/circleci-artifacts
|
||||
- store_artifacts:
|
||||
path: /tmp/circleci-test-results
|
||||
25
Jenkinsfile
vendored
Normal file
25
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Init Submodules') {
|
||||
steps {
|
||||
sh 'git submodule update --init --recursive'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'update-alternatives --set java /usr/lib/jvm/zulu8/jre/bin/java'
|
||||
sh 'chmod +x scripts/inst.sh'
|
||||
sh './scripts/inst.sh --setup --remote'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Archive') {
|
||||
steps {
|
||||
archiveArtifacts(artifacts: '*.jar', fingerprint: true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,17 @@ As such, Akarin is licensed under the
|
||||
[GNU General Public License version 3](licenses/GPL.md); as it inherits it from Paper,
|
||||
who in turn inherits it from the original Spigot projects.
|
||||
|
||||
Any author who is _not_ listed below should be presumed to have released their work
|
||||
Any author who is _not_ listed below should be presumed to have their work released
|
||||
under the original [GPL](licenses/GPL.md) license.
|
||||
|
||||
In the interest of promoting a better Minecraft platform for everyone, contributors
|
||||
may choose to release their code under the more permissive [MIT License](licenses/MIT.md).
|
||||
|
||||
The authors listed below have chosen to release their code under that more permissive
|
||||
The authors listed below have chosen to release their code under the more permissive
|
||||
[MIT License](licenses/MIT.md). Any contributor who wants their name added below
|
||||
should submit a pull request to this project to add their name.
|
||||
should submit a Pull Request to this project and add their name.
|
||||
|
||||
```text
|
||||
Sotr <kira@kira.moe>
|
||||
MatrixTunnel <https://github.com/MatrixTunnel>
|
||||
```
|
||||
49
README.md
49
README.md
@@ -1,29 +1,31 @@
|
||||
# <img src="https://i.loli.net/2018/05/17/5afd869c443ef.png" alt="Akarin Face" align="right">Akarin
|
||||
[](http://ci.ilummc.com/job/Akarin/)
|
||||
[](https://bstats.org/plugin/bukkit/Torch)
|
||||
[](https://akarin.io)
|
||||
[](https://discord.gg/fw2pJAj)
|
||||
[](https://bstats.org/plugin/bukkit/Torch)
|
||||
|
||||
Akarin is currently **under heavy development** and contributions are welcome!
|
||||
|
||||
Introduction
|
||||
---
|
||||
> Akarin is a powerful server software form the 'new dimension', formerly known as [Torch](https://github.com/Akarin-project/Torch).
|
||||
> Akarin is a powerful server software from the 'new dimension', formerly known as Torch.
|
||||
|
||||
As a [Paper](https://github.com/PaperMC/Paper) fork, it supports almost all plugins that [Spigot](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse) can use.
|
||||
As a [Paper](https://github.com/PaperMC/Paper) fork, it should support almost all plugins that work on [Spigot](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/spigot/browse).
|
||||
|
||||
It has a few key goals:
|
||||
* **Open Access** - Make more game mechanism configurable.
|
||||
* **Bedrock** - Safety and stable is important for a server.
|
||||
* **Fast** - Simplify the logic and import the multi-thread compute.
|
||||
Our project has a few key goals:
|
||||
|
||||
Akarin is **under heavy development** yet, contribution is welcome and run a test before putting into production.
|
||||
* **Open Access** - Make more game mechanics configurable.
|
||||
* **Bedrock** - Make the server more safe and stable.
|
||||
* **Fast** - Simplify the logic and implement multi-threaded computing.
|
||||
|
||||
*Issues and Pull Requests will be labeled accordingly*
|
||||
|
||||
Get Akarin
|
||||
---
|
||||
### Download
|
||||
#### Recommended Sites
|
||||
+ [ **Circle CI**](https://circleci.com/gh/Akarin-project/Akarin/tree/master) - Checkout the 'Artifacts' tab of the latest build *Login required*
|
||||
+ [ **Jenkins**](http://ci.ilummc.com/job/Akarin/) - *Kudos to [Izzel_Aliz](https://github.com/IzzelAliz)*
|
||||
#### Recommended
|
||||
+ [**Jenkins**](http://ci.josephworks.net/job/Akarin/job/ver%252F1.12.2/) - Kudos to [JosephWorks](https://github.com/josephworks)
|
||||
|
||||
*Contact me via the email below or open an [Issue](https://github.com/Akarin-project/akarin/issues) if you want to add your website here*
|
||||
*Open an [Issue](https://github.com/Akarin-project/Akarin/issues) or a [Pull Request](https://github.com/Akarin-project/Akarin/pulls) if you want to add your website here*
|
||||
|
||||
### Build
|
||||
#### Requirements
|
||||
@@ -34,20 +36,23 @@ Get Akarin
|
||||
```sh
|
||||
./scripts/inst.sh --setup --fast
|
||||
```
|
||||
*For non-modification compile, add `--fast` option to skip the test is recommended.*
|
||||
*Futhermore, if your machine have a insufficient memory, you may add `--remote` option to avoid decompile locally.*
|
||||
|
||||
Demonstration servers
|
||||
**Notes**
|
||||
* You must use `--setup` at least once to deploy necessary dependencies otherwise some imports cannot be organized.
|
||||
* For non-modified projects, it is recommended to add the `--fast` option to skip any tests.
|
||||
* If your machine has insufficient memory, you may want to add the `--remote` option to avoid decompiling locally.
|
||||
|
||||
Demo Servers
|
||||
---
|
||||
+ **demo.akarin.io**
|
||||
* `demo.akarin.io` (official)
|
||||
* `omc.hk` (auth required)
|
||||
|
||||
*Contact me via the email below or open an [Issue](https://github.com/Akarin-project/akarin/issues) if you want to add your server here*
|
||||
*Open an [Issue](https://github.com/Akarin-project/Akarin/issues) or a [Pull Request](https://github.com/Akarin-project/Akarin/pulls) if you want to add your website here*
|
||||
|
||||
Contributing
|
||||
---
|
||||
* Feel free to open an [Issue](https://github.com/Akarin-project/akarin/issues) if you have any problem with Akarin.
|
||||
* [Pull Request](https://github.com/Akarin-project/akarin/pulls) is welcomed, Akarin use [Mixin](https://github.com/SpongePowered/Mixin) to modify the code, you can checkout `sources` folder to see them. Moreover, add your name to the [LICENSE](https://github.com/Akarin-project/Akarin/blob/master/LICENSE.md) if you want to publish your code under the [MIT License](https://github.com/Akarin-project/Akarin/blob/master/licenses/MIT.md).
|
||||
* If you want to join the [Akarin-project](https://github.com/Akarin-project) team, you can send an email to `kira@kira.moe` with your experience and necessary information. Besides, welcome to join our [TIM Group](https://jq.qq.com/?_wv=1027&k=59q2kV4) to chat *(Chinese)*.
|
||||
* Note that you must `--setup` at least once to deploy necessary dependency otherwise some imports cannot be organized.
|
||||
* Akarin uses [Mixin](https://github.com/SpongePowered/Mixin) to modify the code. You can checkout the `sources` folder to see more.
|
||||
* Add your name to the [LICENSE](https://github.com/Akarin-project/Akarin/blob/master/LICENSE.md) if you want to publish your code under the [MIT License](https://github.com/Akarin-project/Akarin/blob/master/licenses/MIT.md).
|
||||
* If you want to join the [Akarin-project](https://github.com/Akarin-project) team, you can [send](mailto://kira@kira.moe) us an email with your experience and necessary information.
|
||||
|
||||

|
||||
16
circle.yml
16
circle.yml
@@ -1,16 +0,0 @@
|
||||
machine:
|
||||
java:
|
||||
version: openjdk8
|
||||
|
||||
dependencies:
|
||||
cache-directories:
|
||||
- "/home/ubuntu/Akarin/work/Paper/work/Minecraft"
|
||||
override:
|
||||
- git config --global user.email "circle@circleci.com"
|
||||
- git config --global user.name "CircleCI"
|
||||
- chmod +x scripts/inst.sh
|
||||
- ./scripts/inst.sh --setup --remote
|
||||
|
||||
test:
|
||||
post:
|
||||
- yes|cp -rf ./akarin-1.12.2.jar $CIRCLE_ARTIFACTS
|
||||
62
removed/com/destroystokyo/paper/antixray/DataBitsReader.java
Normal file
62
removed/com/destroystokyo/paper/antixray/DataBitsReader.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.destroystokyo.paper.antixray;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class DataBitsReader {
|
||||
|
||||
private ByteBuf dataBits; // Akarin
|
||||
private int bitsPerValue;
|
||||
private int mask;
|
||||
private int longInDataBitsIndex;
|
||||
private int bitInLongIndex;
|
||||
private long current;
|
||||
|
||||
public void setDataBits(ByteBuf dataBits) { // Akarin
|
||||
this.dataBits = dataBits;
|
||||
}
|
||||
|
||||
public void setBitsPerValue(int bitsPerValue) {
|
||||
this.bitsPerValue = bitsPerValue;
|
||||
mask = (1 << bitsPerValue) - 1;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.longInDataBitsIndex = index;
|
||||
bitInLongIndex = 0;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (dataBits.capacity() > longInDataBitsIndex + 7) { // Akarin
|
||||
// Akarin start
|
||||
dataBits.getLong(longInDataBitsIndex);
|
||||
/*
|
||||
current = ((((long) dataBits[longInDataBitsIndex]) << 56)
|
||||
| (((long) dataBits[longInDataBitsIndex + 1] & 0xff) << 48)
|
||||
| (((long) dataBits[longInDataBitsIndex + 2] & 0xff) << 40)
|
||||
| (((long) dataBits[longInDataBitsIndex + 3] & 0xff) << 32)
|
||||
| (((long) dataBits[longInDataBitsIndex + 4] & 0xff) << 24)
|
||||
| (((long) dataBits[longInDataBitsIndex + 5] & 0xff) << 16)
|
||||
| (((long) dataBits[longInDataBitsIndex + 6] & 0xff) << 8)
|
||||
| (((long) dataBits[longInDataBitsIndex + 7] & 0xff)));
|
||||
*/ // Akarin end
|
||||
}
|
||||
}
|
||||
|
||||
public int read() {
|
||||
int value = (int) (current >>> bitInLongIndex) & mask;
|
||||
bitInLongIndex += bitsPerValue;
|
||||
|
||||
if (bitInLongIndex > 63) {
|
||||
bitInLongIndex -= 64;
|
||||
longInDataBitsIndex += 8;
|
||||
init();
|
||||
|
||||
if (bitInLongIndex > 0) {
|
||||
value |= current << bitsPerValue - bitInLongIndex & mask;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
94
removed/com/destroystokyo/paper/antixray/DataBitsWriter.java
Normal file
94
removed/com/destroystokyo/paper/antixray/DataBitsWriter.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.destroystokyo.paper.antixray;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class DataBitsWriter {
|
||||
|
||||
private ByteBuf dataBits; // Akarin
|
||||
private int bitsPerValue;
|
||||
private long mask;
|
||||
private int longInDataBitsIndex;
|
||||
private int bitInLongIndex;
|
||||
private long current;
|
||||
private boolean dirty;
|
||||
|
||||
public void setDataBits(ByteBuf dataBits) { // Akarin
|
||||
this.dataBits = dataBits;
|
||||
}
|
||||
|
||||
public void setBitsPerValue(int bitsPerValue) {
|
||||
this.bitsPerValue = bitsPerValue;
|
||||
mask = (1 << bitsPerValue) - 1;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.longInDataBitsIndex = index;
|
||||
bitInLongIndex = 0;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (dataBits.capacity() > longInDataBitsIndex + 7) { // Akarin
|
||||
// Akarin start
|
||||
current = dataBits.getLong(longInDataBitsIndex);
|
||||
/*
|
||||
current = ((((long) dataBits[longInDataBitsIndex]) << 56)
|
||||
| (((long) dataBits[longInDataBitsIndex + 1] & 0xff) << 48)
|
||||
| (((long) dataBits[longInDataBitsIndex + 2] & 0xff) << 40)
|
||||
| (((long) dataBits[longInDataBitsIndex + 3] & 0xff) << 32)
|
||||
| (((long) dataBits[longInDataBitsIndex + 4] & 0xff) << 24)
|
||||
| (((long) dataBits[longInDataBitsIndex + 5] & 0xff) << 16)
|
||||
| (((long) dataBits[longInDataBitsIndex + 6] & 0xff) << 8)
|
||||
| (((long) dataBits[longInDataBitsIndex + 7] & 0xff)));
|
||||
*/ // Akarin end
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
if (dirty && dataBits.capacity() > longInDataBitsIndex + 7) { // Akarin
|
||||
// Akarin start
|
||||
dataBits.setLong(longInDataBitsIndex, current);
|
||||
/*
|
||||
dataBits[longInDataBitsIndex] = (byte) (current >> 56 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 1] = (byte) (current >> 48 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 2] = (byte) (current >> 40 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 3] = (byte) (current >> 32 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 4] = (byte) (current >> 24 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 5] = (byte) (current >> 16 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 6] = (byte) (current >> 8 & 0xff);
|
||||
dataBits[longInDataBitsIndex + 7] = (byte) (current & 0xff);
|
||||
*/ // Akarin end
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int value) {
|
||||
current = current & ~(mask << bitInLongIndex) | (value & mask) << bitInLongIndex;
|
||||
dirty = true;
|
||||
bitInLongIndex += bitsPerValue;
|
||||
|
||||
if (bitInLongIndex > 63) {
|
||||
finish();
|
||||
bitInLongIndex -= 64;
|
||||
longInDataBitsIndex += 8;
|
||||
init();
|
||||
|
||||
if (bitInLongIndex > 0) {
|
||||
current = current & ~(mask >>> bitsPerValue - bitInLongIndex) | (value & mask) >>> bitsPerValue - bitInLongIndex;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void skip() {
|
||||
bitInLongIndex += bitsPerValue;
|
||||
|
||||
if (bitInLongIndex > 63) {
|
||||
finish();
|
||||
bitInLongIndex -= 64;
|
||||
longInDataBitsIndex += 8;
|
||||
init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.destroystokyo.paper.antixray;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.DataPalette;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.PacketPlayOutMapChunk;
|
||||
|
||||
/**
|
||||
* Akarin Changes Note
|
||||
* 1) byte[] -> ByteBuf (compatibility)
|
||||
*/
|
||||
public class PacketPlayOutMapChunkInfo {
|
||||
|
||||
private final PacketPlayOutMapChunk packetPlayOutMapChunk;
|
||||
private final Chunk chunk;
|
||||
private final int chunkSectionSelector;
|
||||
private ByteBuf data; // Akarin
|
||||
private final int[] bitsPerValue = new int[16];
|
||||
private final DataPalette[] dataPalettes = new DataPalette[16];
|
||||
private final int[] dataBitsIndexes = new int[16];
|
||||
private final IBlockData[][] predefinedBlockData = new IBlockData[16][];
|
||||
|
||||
public PacketPlayOutMapChunkInfo(PacketPlayOutMapChunk packetPlayOutMapChunk, Chunk chunk, int chunkSectionSelector) {
|
||||
this.packetPlayOutMapChunk = packetPlayOutMapChunk;
|
||||
this.chunk = chunk;
|
||||
this.chunkSectionSelector = chunkSectionSelector;
|
||||
}
|
||||
|
||||
public PacketPlayOutMapChunk getPacketPlayOutMapChunk() {
|
||||
return packetPlayOutMapChunk;
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public int getChunkSectionSelector() {
|
||||
return chunkSectionSelector;
|
||||
}
|
||||
|
||||
public ByteBuf getData() { // Akarin
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(ByteBuf data) { // Akarin
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getBitsPerValue(int chunkSectionIndex) {
|
||||
return bitsPerValue[chunkSectionIndex];
|
||||
}
|
||||
|
||||
public void setBitsPerValue(int chunkSectionIndex, int bitsPerValue) {
|
||||
this.bitsPerValue[chunkSectionIndex] = bitsPerValue;
|
||||
}
|
||||
|
||||
public DataPalette getDataPalette(int chunkSectionIndex) {
|
||||
return dataPalettes[chunkSectionIndex];
|
||||
}
|
||||
|
||||
public void setDataPalette(int chunkSectionIndex, DataPalette dataPalette) {
|
||||
dataPalettes[chunkSectionIndex] = dataPalette;
|
||||
}
|
||||
|
||||
public int getDataBitsIndex(int chunkSectionIndex) {
|
||||
return dataBitsIndexes[chunkSectionIndex];
|
||||
}
|
||||
|
||||
public void setDataBitsIndex(int chunkSectionIndex, int dataBitsIndex) {
|
||||
dataBitsIndexes[chunkSectionIndex] = dataBitsIndex;
|
||||
}
|
||||
|
||||
public IBlockData[] getPredefinedBlockData(int chunkSectionIndex) {
|
||||
return predefinedBlockData[chunkSectionIndex];
|
||||
}
|
||||
|
||||
public void setPredefinedBlockData(int chunkSectionIndex, IBlockData[] predefinedBlockData) {
|
||||
this.predefinedBlockData[chunkSectionIndex] = predefinedBlockData;
|
||||
}
|
||||
|
||||
public boolean isWritten(int chunkSectionIndex) {
|
||||
return bitsPerValue[chunkSectionIndex] != 0;
|
||||
}
|
||||
}
|
||||
193
removed/net/minecraft/server/PacketPlayOutMapChunk.java
Normal file
193
removed/net/minecraft/server/PacketPlayOutMapChunk.java
Normal file
@@ -0,0 +1,193 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
// Paper start
|
||||
import com.destroystokyo.paper.antixray.PacketPlayOutMapChunkInfo; // Anti-Xray
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
* Akarin Changes Note
|
||||
* 1) WrappedByteBuf -> ByteBuf (compatibility)
|
||||
*/
|
||||
public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
|
||||
|
||||
private int a;
|
||||
private int b;
|
||||
private int c;
|
||||
private ByteBuf d; // Akarin - byte[] -> ByteBuf
|
||||
private List<NBTTagCompound> e;
|
||||
private boolean f;
|
||||
private volatile boolean ready = false; // Paper - Async-Anti-Xray - Ready flag for the network manager
|
||||
|
||||
// Paper start - Async-Anti-Xray - Set the ready flag to true
|
||||
public PacketPlayOutMapChunk() {
|
||||
this.ready = true;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public PacketPlayOutMapChunk(Chunk chunk, int i) {
|
||||
PacketPlayOutMapChunkInfo packetPlayOutMapChunkInfo = chunk.world.chunkPacketBlockController.getPacketPlayOutMapChunkInfo(this, chunk, i); // Paper - Anti-Xray - Add chunk packet info
|
||||
this.a = chunk.locX;
|
||||
this.b = chunk.locZ;
|
||||
this.f = i == '\uffff';
|
||||
boolean flag = chunk.getWorld().worldProvider.m();
|
||||
|
||||
this.d = allocateBuffer(this.a(chunk, flag, i)); // Akarin
|
||||
|
||||
// Paper start - Anti-Xray - Add chunk packet info
|
||||
if (packetPlayOutMapChunkInfo != null) {
|
||||
packetPlayOutMapChunkInfo.setData(this.d);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
this.c = this.writeChunk(new PacketDataSerializer(this.d), chunk, flag, i, packetPlayOutMapChunkInfo); // Paper - Anti-Xray - Add chunk packet info // Akarin
|
||||
this.e = Lists.newArrayList();
|
||||
Iterator iterator = chunk.getTileEntities().entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Entry entry = (Entry) iterator.next();
|
||||
BlockPosition blockposition = (BlockPosition) entry.getKey();
|
||||
TileEntity tileentity = (TileEntity) entry.getValue();
|
||||
int j = blockposition.getY() >> 4;
|
||||
|
||||
if (this.e() || (i & 1 << j) != 0) {
|
||||
NBTTagCompound nbttagcompound = tileentity.d();
|
||||
|
||||
this.e.add(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
chunk.world.chunkPacketBlockController.modifyBlocks(this, packetPlayOutMapChunkInfo); // Paper - Anti-Xray - Modify blocks
|
||||
}
|
||||
|
||||
// Paper start - Async-Anti-Xray - Getter and Setter for the ready flag
|
||||
public boolean isReady() {
|
||||
return this.ready;
|
||||
}
|
||||
|
||||
public void setReady(boolean ready) {
|
||||
this.ready = ready;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public void a(PacketDataSerializer packetdataserializer) throws IOException {
|
||||
this.a = packetdataserializer.readInt();
|
||||
this.b = packetdataserializer.readInt();
|
||||
this.f = packetdataserializer.readBoolean();
|
||||
this.c = packetdataserializer.g();
|
||||
int i = packetdataserializer.g();
|
||||
|
||||
if (i > 2097152) {
|
||||
throw new RuntimeException("Chunk Packet trying to allocate too much memory on read.");
|
||||
} else {
|
||||
this.d = Unpooled.buffer(i); // Akarin
|
||||
packetdataserializer.readBytes(this.d);
|
||||
int j = packetdataserializer.g();
|
||||
|
||||
this.e = Lists.newArrayList();
|
||||
|
||||
for (int k = 0; k < j; ++k) {
|
||||
this.e.add(packetdataserializer.j());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
||||
packetdataserializer.writeInt(this.a);
|
||||
packetdataserializer.writeInt(this.b);
|
||||
packetdataserializer.writeBoolean(this.f);
|
||||
packetdataserializer.d(this.c);
|
||||
packetdataserializer.d(this.d.capacity()); // Akarin
|
||||
packetdataserializer.writeBytes(this.d.array()); // Akarin
|
||||
packetdataserializer.d(this.e.size());
|
||||
Iterator iterator = this.e.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
NBTTagCompound nbttagcompound = (NBTTagCompound) iterator.next();
|
||||
|
||||
packetdataserializer.a(nbttagcompound);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void a(PacketListenerPlayOut packetlistenerplayout) {
|
||||
packetlistenerplayout.a(this);
|
||||
}
|
||||
|
||||
private ByteBuf g() { return allocateBuffer(-1); } // Akarin
|
||||
private ByteBuf allocateBuffer(int expectedCapacity) { // Akarin - added argument
|
||||
ByteBuf bytebuf = expectedCapacity == -1 ? Unpooled.buffer() : Unpooled.buffer(expectedCapacity); // Akarin
|
||||
|
||||
bytebuf.writerIndex(0);
|
||||
return bytebuf;
|
||||
}
|
||||
|
||||
// Paper start - Anti-Xray - Support default method
|
||||
public int writeChunk(PacketDataSerializer packetDataSerializer, Chunk chunk, boolean writeSkyLightArray, int chunkSectionSelector) { return this.a(packetDataSerializer, chunk, writeSkyLightArray, chunkSectionSelector); } // OBFHELPER
|
||||
public int a(PacketDataSerializer packetdataserializer, Chunk chunk, boolean flag, int i) {
|
||||
return this.a(packetdataserializer, chunk, flag, i, null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public int writeChunk(PacketDataSerializer packetDataSerializer, Chunk chunk, boolean writeSkyLightArray, int chunkSectionSelector, PacketPlayOutMapChunkInfo packetPlayOutMapChunkInfo) { return this.a(packetDataSerializer, chunk, writeSkyLightArray, chunkSectionSelector, packetPlayOutMapChunkInfo); } // Paper - Anti-Xray - OBFHELPER
|
||||
public int a(PacketDataSerializer packetdataserializer, Chunk chunk, boolean flag, int i, PacketPlayOutMapChunkInfo packetPlayOutMapChunkInfo) { // Paper - Anti-Xray - Add chunk packet info
|
||||
int j = 0;
|
||||
ChunkSection[] achunksection = chunk.getSections();
|
||||
int k = 0;
|
||||
|
||||
for (int l = achunksection.length; k < l; ++k) {
|
||||
ChunkSection chunksection = achunksection[k];
|
||||
|
||||
if (chunksection != Chunk.a && (!this.e() || !chunksection.a()) && (i & 1 << k) != 0) {
|
||||
j |= 1 << k;
|
||||
chunksection.getBlocks().writeBlocks(packetdataserializer, packetPlayOutMapChunkInfo, k); // Paper - Anti-Xray - Add chunk packet info
|
||||
packetdataserializer.writeBytes(chunksection.getEmittedLightArray().asBytes());
|
||||
if (flag) {
|
||||
packetdataserializer.writeBytes(chunksection.getSkyLightArray().asBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.e()) {
|
||||
packetdataserializer.writeBytes(chunk.getBiomeIndex());
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
protected int a(Chunk chunk, boolean flag, int i) {
|
||||
int j = 0;
|
||||
ChunkSection[] achunksection = chunk.getSections();
|
||||
int k = 0;
|
||||
|
||||
for (int l = achunksection.length; k < l; ++k) {
|
||||
ChunkSection chunksection = achunksection[k];
|
||||
|
||||
if (chunksection != Chunk.a && (!this.e() || !chunksection.a()) && (i & 1 << k) != 0) {
|
||||
j += chunksection.getBlocks().a();
|
||||
j += chunksection.getEmittedLightArray().asBytes().length;
|
||||
if (flag) {
|
||||
j += chunksection.getSkyLightArray().asBytes().length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.e()) {
|
||||
j += chunk.getBiomeIndex().length;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
public boolean e() {
|
||||
return this.f;
|
||||
}
|
||||
}
|
||||
@@ -15,25 +15,30 @@ if [ "$2" == "--setup" ] || [ "$3" == "--setup" ] || [ "$4" == "--setup" ]; then
|
||||
if [ -d "Minecraft" ]; then
|
||||
rm Minecraft/ -r
|
||||
fi
|
||||
git clone https://github.com/Akarin-project/Minecraft.git
|
||||
git clone https://github.com/LegacyGamerHD/Minecraft.git
|
||||
fi
|
||||
|
||||
cd "$paperbasedir"
|
||||
./paper patch
|
||||
./paper jar
|
||||
)
|
||||
fi
|
||||
|
||||
echo "[Akarin] Ready to build"
|
||||
(
|
||||
echo "[Akarin] Touch sources.."
|
||||
\cp -rf "$basedir/sources/src" "$paperbasedir/Paper-Server/"
|
||||
\cp -rf "$basedir/sources/pom.xml" "$paperbasedir/Paper-Server/"
|
||||
|
||||
cd "$paperbasedir"
|
||||
if [ "$2" == "--fast" ] || [ "$3" == "--fast" ] || [ "$4" == "--fast" ]; then
|
||||
echo "[Akarin] Test has been skipped"
|
||||
\cp -rf "$basedir/sources/src" "$paperbasedir/Paper-Server/"
|
||||
\cp -rf "$basedir/sources/pom.xml" "$paperbasedir/Paper-Server/"
|
||||
mvn clean install -DskipTests
|
||||
else
|
||||
rm -rf Paper-API/src
|
||||
rm -rf Paper-Server/src
|
||||
./paper patch
|
||||
\cp -rf "$basedir/sources/src" "$paperbasedir/Paper-Server/"
|
||||
\cp -rf "$basedir/sources/pom.xml" "$paperbasedir/Paper-Server/"
|
||||
mvn clean install
|
||||
fi
|
||||
|
||||
|
||||
2
scripts/inst.sh
Normal file → Executable file
2
scripts/inst.sh
Normal file → Executable file
@@ -4,7 +4,7 @@
|
||||
set -e
|
||||
basedir="$pwd"
|
||||
|
||||
(git submodule update --init --remote && chmod +x scripts/build.sh && ./scripts/build.sh "$basedir" "$1" "$2" "$3") || (
|
||||
(chmod +x scripts/build.sh && ./scripts/build.sh "$basedir" "$1" "$2" "$3") || (
|
||||
echo "Failed to build Akarin"
|
||||
exit 1
|
||||
) || exit 1
|
||||
|
||||
179
sources/pom.xml
179
sources/pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>akarin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.12.2-R0.1-RELEASE</version>
|
||||
<version>1.12.2-R0.4-SNAPSHOT</version>
|
||||
<name>Akarin</name>
|
||||
<url>https://github.com/Akarin-project/Akarin</url>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.24.Final</version>
|
||||
<version>4.1.78.Final</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -45,6 +45,12 @@
|
||||
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>minecraft-server</artifactId>
|
||||
<version>${minecraft.version}-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.jopt-simple</groupId>
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
@@ -54,7 +60,7 @@
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<version>3.21.0.1</version>
|
||||
<version>3.41.2.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -69,16 +75,15 @@
|
||||
<version>3.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.minecrell</groupId>
|
||||
<artifactId>terminalconsoleappender</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>4.4.0</version>
|
||||
<version>4.5.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -91,7 +96,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<version>2.17.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -99,20 +104,28 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<version>2.17.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-iostreams</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Paper - Async loggers -->
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- testing -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -124,36 +137,95 @@
|
||||
|
||||
<!-- Akarin -->
|
||||
<dependency>
|
||||
<groupId>io.akarin</groupId>
|
||||
<artifactId>legacylauncher</artifactId>
|
||||
<version>1.20</version>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-tree</artifactId>
|
||||
<version>9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-analysis</artifactId>
|
||||
<version>9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-util</artifactId>
|
||||
<version>9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-commons</artifactId>
|
||||
<version>9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.akarin</groupId>
|
||||
<artifactId>mixin</artifactId>
|
||||
<version>0.7.8-SNAPSHOT</version>
|
||||
<version>0.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.akarin</groupId>
|
||||
<artifactId>legacylauncher</artifactId>
|
||||
<version>1.26</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.concurrent-locks</groupId>
|
||||
<artifactId>concurrent-locks</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.9.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-public</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>akarin-repo</id>
|
||||
<url>https://raw.githubusercontent.com/Akarin-project/akarin-repo/master/repository</url>
|
||||
<id>elmakers-repo</id>
|
||||
<url>http://maven.elmakers.com/repository/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spongepowered-repo</id>
|
||||
<url>https://repo.spongepowered.org/maven/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>nallar-repo</id>
|
||||
<url>http://repo.nallar.me/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>josephworks</id>
|
||||
<url>https://repo.josephworks.net/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-nexusg</id>
|
||||
<url>https://oss.sonatype.org/content/repositories</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spigotmc-public</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
<id>paper</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
@@ -168,7 +240,7 @@
|
||||
<version>1.3</version>
|
||||
<configuration>
|
||||
<outputPrefix>git-Akarin-</outputPrefix>
|
||||
<scmDirectory>..</scmDirectory>
|
||||
<scmDirectory>../..</scmDirectory> <!-- Akarin -->
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@@ -194,6 +266,7 @@
|
||||
<Specification-Title>Bukkit</Specification-Title>
|
||||
<Specification-Version>${api.version}</Specification-Version>
|
||||
<Specification-Vendor>Bukkit Team</Specification-Vendor>
|
||||
<Multi-Release>true</Multi-Release> <!-- Paper start - update log4j -->
|
||||
</manifestEntries>
|
||||
<manifestSections>
|
||||
<manifestSection>
|
||||
@@ -221,7 +294,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -230,6 +303,37 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation> <!-- Paper -->
|
||||
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>org.spigotmc:minecraft-server:**</artifact>
|
||||
<excludes>
|
||||
<exclude>io/netty/**</exclude>
|
||||
<exclude>org/apache/logging/log4j/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>io.akarin:legacylauncher:**</artifact>
|
||||
<excludes>
|
||||
<exclude>org/objectweb/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>com.destroystokyo.paper:paper-api:**</artifact>
|
||||
<excludes>
|
||||
<exclude>org/objectweb/**</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
|
||||
<relocations>
|
||||
<!-- Paper - Workaround for hardcoded path lookup in dependency, easier than forking it - GH-189 -->
|
||||
<!--<relocation>-->
|
||||
@@ -261,27 +365,16 @@
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/services/java.sql.Driver</resource>
|
||||
</transformer>
|
||||
<transformer implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer" />
|
||||
<transformer implementation="io.github.edwgiz.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer" />
|
||||
</transformers>
|
||||
<!-- Akarin - Avoid signature failure -->
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.edwgiz</groupId>
|
||||
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
|
||||
<version>2.8.1</version>
|
||||
<groupId>io.github.edwgiz</groupId>
|
||||
<artifactId>log4j-maven-shade-plugin-extensions</artifactId>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
@@ -289,6 +382,12 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.7.0</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>org/spigotmc/CaseInsensitiveHashingStrategy.java</exclude>
|
||||
<exclude>org/spigotmc/CaseInsensitiveMap.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
128
sources/src/main/java/co/aikar/timings/MinecraftTimings.java
Normal file
128
sources/src/main/java/co/aikar/timings/MinecraftTimings.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package co.aikar.timings;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import net.minecraft.server.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import org.bukkit.craftbukkit.scheduler.CraftTask;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class MinecraftTimings {
|
||||
|
||||
public static final Timing playerListTimer = Timings.ofSafe("Player List");
|
||||
public static final Timing commandFunctionsTimer = Timings.ofSafe("Command Functions");
|
||||
public static final Timing connectionTimer = Timings.ofSafe("Connection Handler");
|
||||
public static final Timing tickablesTimer = Timings.ofSafe("Tickables");
|
||||
public static final Timing minecraftSchedulerTimer = Timings.ofSafe("Minecraft Scheduler");
|
||||
public static final Timing bukkitSchedulerTimer = Timings.ofSafe("Bukkit Scheduler");
|
||||
public static final Timing bukkitSchedulerPendingTimer = Timings.ofSafe("Bukkit Scheduler - Pending");
|
||||
public static final Timing bukkitSchedulerFinishTimer = Timings.ofSafe("Bukkit Scheduler - Finishing");
|
||||
public static final Timing chunkIOTickTimer = Timings.ofSafe("ChunkIOTick");
|
||||
public static final Timing timeUpdateTimer = Timings.ofSafe("Time Update");
|
||||
public static final Timing serverCommandTimer = Timings.ofSafe("Server Command");
|
||||
public static final Timing savePlayers = Timings.ofSafe("Save Players");
|
||||
|
||||
public static final Timing tickEntityTimer = Timings.ofSafe("## tickEntity");
|
||||
public static final Timing tickTileEntityTimer = Timings.ofSafe("## tickTileEntity");
|
||||
public static final Timing packetProcessTimer = Timings.ofSafe("## Packet Processing");
|
||||
public static final Timing scheduledBlocksTimer = Timings.ofSafe("## Scheduled Blocks");
|
||||
public static final Timing structureGenerationTimer = Timings.ofSafe("Structure Generation");
|
||||
|
||||
public static final Timing processQueueTimer = Timings.ofSafe("processQueue");
|
||||
|
||||
public static final Timing playerCommandTimer = Timings.ofSafe("playerCommand");
|
||||
|
||||
public static final Timing entityActivationCheckTimer = Timings.ofSafe("entityActivationCheck");
|
||||
|
||||
public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
||||
public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
||||
|
||||
private static final Map<Class<? extends Runnable>, String> taskNameCache = new MapMaker().weakKeys().makeMap();
|
||||
|
||||
private MinecraftTimings() {}
|
||||
|
||||
/**
|
||||
* Gets a timer associated with a plugins tasks.
|
||||
* @param bukkitTask
|
||||
* @param period
|
||||
* @return
|
||||
*/
|
||||
public static Timing getPluginTaskTimings(BukkitTask bukkitTask, long period) {
|
||||
if (!bukkitTask.isSync()) {
|
||||
return NullTimingHandler.NULL;
|
||||
}
|
||||
Plugin plugin;
|
||||
|
||||
Runnable task = ((CraftTask) bukkitTask).task;
|
||||
|
||||
final Class<? extends Runnable> taskClass = task.getClass();
|
||||
if (bukkitTask.getOwner() != null) {
|
||||
plugin = bukkitTask.getOwner();
|
||||
} else {
|
||||
plugin = TimingsManager.getPluginByClassloader(taskClass);
|
||||
}
|
||||
|
||||
final String taskname = taskNameCache.computeIfAbsent(taskClass, clazz ->
|
||||
clazz.isAnonymousClass() || clazz.isLocalClass()
|
||||
? clazz.getName()
|
||||
: clazz.getCanonicalName());
|
||||
|
||||
StringBuilder name = new StringBuilder(64);
|
||||
name.append("Task: ").append(taskname);
|
||||
if (period > 0) {
|
||||
name.append(" (interval:").append(period).append(")");
|
||||
} else {
|
||||
name.append(" (Single)");
|
||||
}
|
||||
|
||||
if (plugin == null) {
|
||||
return Timings.ofSafe(null, name.toString());
|
||||
}
|
||||
|
||||
return Timings.ofSafe(plugin, name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a named timer for the specified entity type to track type specific timings.
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static Timing getEntityTimings(Entity entity) {
|
||||
String entityType = entity.getClass().getName();
|
||||
return Timings.ofSafe("Minecraft", "## tickEntity - " + entityType, tickEntityTimer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a named timer for the specified tile entity type to track type specific timings.
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static Timing getTileEntityTimings(TileEntity entity) {
|
||||
String entityType = entity.getClass().getName();
|
||||
return Timings.ofSafe("Minecraft", "## tickTileEntity - " + entityType, tickTileEntityTimer);
|
||||
}
|
||||
public static Timing getCancelTasksTimer() {
|
||||
return Timings.ofSafe("Cancel Tasks");
|
||||
}
|
||||
public static Timing getCancelTasksTimer(Plugin plugin) {
|
||||
return Timings.ofSafe(plugin, "Cancel Tasks");
|
||||
}
|
||||
|
||||
public static void stopServer() {
|
||||
TimingsManager.stopServer();
|
||||
}
|
||||
|
||||
public static Timing getBlockTiming(Block block) {
|
||||
return Timings.ofSafe("## Scheduled Block: " + block.getName(), scheduledBlocksTimer);
|
||||
}
|
||||
|
||||
public static Timing getStructureTiming(StructureGenerator structureGenerator) {
|
||||
return Timings.ofSafe("Structure Generator - " + structureGenerator.getName(), structureGenerationTimer);
|
||||
}
|
||||
|
||||
public static Timing getPacketTiming(Packet packet) {
|
||||
return Timings.ofSafe("## Packet - " + packet.getClass().getSimpleName(), packetProcessTimer);
|
||||
}
|
||||
}
|
||||
131
sources/src/main/java/co/aikar/timings/TimedChunkGenerator.java
Normal file
131
sources/src/main/java/co/aikar/timings/TimedChunkGenerator.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* This file is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2014-2016 Daniel Ennis <http://aikar.co>
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
|
||||
package co.aikar.timings;
|
||||
|
||||
import net.minecraft.server.BiomeBase.BiomeMeta;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.EnumCreatureType;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.generator.InternalChunkGenerator;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TimedChunkGenerator extends InternalChunkGenerator {
|
||||
private final WorldServer world;
|
||||
private final InternalChunkGenerator timedGenerator;
|
||||
|
||||
public TimedChunkGenerator(WorldServer worldServer, InternalChunkGenerator gen) {
|
||||
world = worldServer;
|
||||
timedGenerator = gen;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public byte[] generate(org.bukkit.World world, Random random, int x, int z) {
|
||||
return timedGenerator.generate(world, random, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public short[][] generateExtBlockSections(org.bukkit.World world, Random random, int x, int z,
|
||||
BiomeGrid biomes) {
|
||||
return timedGenerator.generateExtBlockSections(world, random, x, z, biomes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public byte[][] generateBlockSections(org.bukkit.World world, Random random, int x, int z,
|
||||
BiomeGrid biomes) {
|
||||
return timedGenerator.generateBlockSections(world, random, x, z, biomes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(org.bukkit.World world, Random random, int x, int z, BiomeGrid biome) {
|
||||
return timedGenerator.generateChunkData(world, random, x, z, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawn(org.bukkit.World world, int x, int z) {
|
||||
return timedGenerator.canSpawn(world, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(org.bukkit.World world) {
|
||||
return timedGenerator.getDefaultPopulators(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFixedSpawnLocation(org.bukkit.World world, Random random) {
|
||||
return timedGenerator.getFixedSpawnLocation(world, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getOrCreateChunk(int i, int j) {
|
||||
try (Timing ignored = world.timings.chunkGeneration.startTiming()) {
|
||||
return timedGenerator.getOrCreateChunk(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recreateStructures(int i, int j) {
|
||||
try (Timing ignored = world.timings.syncChunkLoadStructuresTimer.startTiming()) {
|
||||
timedGenerator.recreateStructures(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(Chunk chunk, int i, int j) {
|
||||
return timedGenerator.a(chunk, i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BiomeMeta> getMobsFor(EnumCreatureType enumcreaturetype, BlockPosition blockposition) {
|
||||
return timedGenerator.getMobsFor(enumcreaturetype, blockposition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public BlockPosition findNearestMapFeature(World world, String s, BlockPosition blockposition, boolean flag) {
|
||||
return timedGenerator.findNearestMapFeature(world, s, blockposition, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recreateStructures(Chunk chunk, int i, int j) {
|
||||
try (Timing ignored = world.timings.syncChunkLoadStructuresTimer.startTiming()) {
|
||||
timedGenerator.recreateStructures(chunk, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(World world, String s, BlockPosition blockPosition) {
|
||||
return timedGenerator.a(world, s, blockPosition);
|
||||
}
|
||||
}
|
||||
@@ -24,23 +24,26 @@
|
||||
package co.aikar.timings;
|
||||
|
||||
import co.aikar.util.LoadingIntMap;
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.api.internal.Akari.AssignableThread;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* <b>Akarin Changes Note</b><br>
|
||||
* <br>
|
||||
* 1) Add volatile to fields<br>
|
||||
* @author cakoyo
|
||||
*/
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
class TimingHandler implements Timing {
|
||||
String name;
|
||||
private static AtomicInteger idPool = new AtomicInteger(1);
|
||||
static Deque<TimingHandler> TIMING_STACK = new ArrayDeque<>();
|
||||
final int id = idPool.getAndIncrement();
|
||||
|
||||
private static int idPool = 1;
|
||||
final int id = idPool++;
|
||||
|
||||
final String name;
|
||||
final TimingIdentifier identifier;
|
||||
private final boolean verbose;
|
||||
|
||||
private final Int2ObjectOpenHashMap<TimingData> children = new LoadingIntMap<>(TimingData::new);
|
||||
@@ -48,22 +51,15 @@ class TimingHandler implements Timing {
|
||||
final TimingData record;
|
||||
private final TimingHandler groupHandler;
|
||||
|
||||
private volatile long start = 0; // Akarin - volatile
|
||||
private volatile int timingDepth = 0; // Akarin - volatile
|
||||
private long start = 0;
|
||||
private int timingDepth = 0;
|
||||
private boolean added;
|
||||
private boolean timed;
|
||||
private boolean enabled;
|
||||
private TimingHandler parent;
|
||||
|
||||
TimingHandler(TimingIdentifier id) {
|
||||
if (id.name.startsWith("##")) {
|
||||
verbose = true;
|
||||
this.name = id.name.substring(3);
|
||||
} else {
|
||||
this.name = id.name;
|
||||
verbose = false;
|
||||
}
|
||||
|
||||
this.identifier = id;
|
||||
this.verbose = id.name.startsWith("##");
|
||||
this.record = new TimingData(this.id);
|
||||
this.groupHandler = id.groupHandler;
|
||||
|
||||
@@ -88,59 +84,61 @@ class TimingHandler implements Timing {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timing startTimingIfSync() {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
startTiming();
|
||||
}
|
||||
return this;
|
||||
startTiming();
|
||||
return (Timing) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTimingIfSync() {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
stopTiming();
|
||||
if (Akari.isPrimaryThread(false)) {
|
||||
stopTiming(true); // Avoid twice thread check
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timing startTiming() {
|
||||
if (enabled && ++timingDepth == 1) {
|
||||
if (enabled && Bukkit.isPrimaryThread() && ++timingDepth == 1) {
|
||||
start = System.nanoTime();
|
||||
parent = TimingsManager.CURRENT;
|
||||
TimingsManager.CURRENT = this;
|
||||
TIMING_STACK.addLast(this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTiming() {
|
||||
if (enabled && --timingDepth == 0 && start != 0) {
|
||||
if (!Bukkit.isPrimaryThread()) {
|
||||
stopTiming(false);
|
||||
}
|
||||
|
||||
public void stopTiming(long start) {
|
||||
if (enabled) addDiff(System.nanoTime() - start);
|
||||
}
|
||||
|
||||
public void stopTiming(boolean alreadySync) {
|
||||
if (!enabled) return;
|
||||
if (!alreadySync) {
|
||||
Thread curThread = Thread.currentThread();
|
||||
if (curThread.getClass() == AssignableThread.class) return;
|
||||
if (curThread != MinecraftServer.getServer().primaryThread) {
|
||||
if (AkarinGlobalConfig.silentAsyncTimings) return;
|
||||
Bukkit.getLogger().log(Level.SEVERE, "stopTiming called async for " + name);
|
||||
new Throwable().printStackTrace();
|
||||
start = 0;
|
||||
return;
|
||||
Thread.dumpStack();
|
||||
}
|
||||
}
|
||||
|
||||
// Main thread ensured
|
||||
if (--timingDepth == 0 && start != 0) {
|
||||
addDiff(System.nanoTime() - start);
|
||||
start = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort() {
|
||||
if (enabled && timingDepth > 0) {
|
||||
start = 0;
|
||||
}
|
||||
}
|
||||
public final void abort() {
|
||||
|
||||
}
|
||||
void addDiff(long diff) {
|
||||
if (TimingsManager.CURRENT == this) {
|
||||
TimingsManager.CURRENT = parent;
|
||||
if (parent != null) {
|
||||
parent.children.get(id).add(diff);
|
||||
}
|
||||
if (this != null) {
|
||||
this.children.get(id).add(diff);
|
||||
}
|
||||
|
||||
record.add(diff);
|
||||
if (!added) {
|
||||
added = true;
|
||||
@@ -148,15 +146,29 @@ class TimingHandler implements Timing {
|
||||
TimingsManager.HANDLERS.add(this);
|
||||
}
|
||||
if (groupHandler != null) {
|
||||
groupHandler.addDiff(diff);
|
||||
groupHandler.addDiff(diff, this);
|
||||
groupHandler.children.get(id).add(diff);
|
||||
}
|
||||
}
|
||||
void addDiff(long diff, TimingHandler parent) {
|
||||
if (parent != null) {
|
||||
parent.children.get(id).add(diff);
|
||||
}
|
||||
|
||||
record.add(diff);
|
||||
if (!added) {
|
||||
added = true;
|
||||
timed = true;
|
||||
TimingsManager.HANDLERS.add(this);
|
||||
}
|
||||
if (groupHandler != null) {
|
||||
groupHandler.addDiff(diff, parent);
|
||||
groupHandler.children.get(id).add(diff);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset this timer, setting all values to zero.
|
||||
*
|
||||
* @param full
|
||||
*/
|
||||
void reset(boolean full) {
|
||||
record.reset();
|
||||
@@ -186,8 +198,7 @@ class TimingHandler implements Timing {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is simply for the Closeable interface so it can be used with
|
||||
* try-with-resources ()
|
||||
* This is simply for the Closeable interface so it can be used with try-with-resources ()
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
103
sources/src/main/java/co/aikar/timings/WorldTimingsHandler.java
Normal file
103
sources/src/main/java/co/aikar/timings/WorldTimingsHandler.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package co.aikar.timings;
|
||||
|
||||
import net.minecraft.server.World;
|
||||
|
||||
/**
|
||||
* Set of timers per world, to track world specific timings.
|
||||
*/
|
||||
public class WorldTimingsHandler {
|
||||
public final Timing mobSpawn;
|
||||
public final Timing doChunkUnload;
|
||||
public final Timing doPortalForcer;
|
||||
public final Timing scheduledBlocks;
|
||||
public final Timing scheduledBlocksCleanup;
|
||||
public final Timing scheduledBlocksTicking;
|
||||
public final Timing chunkTicks;
|
||||
public final Timing lightChunk;
|
||||
public final Timing chunkTicksBlocks;
|
||||
public final Timing doVillages;
|
||||
public final Timing doChunkMap;
|
||||
public final Timing doChunkMapUpdate;
|
||||
public final Timing doChunkMapToUpdate;
|
||||
public final Timing doChunkMapSortMissing;
|
||||
public final Timing doChunkMapSortSendToPlayers;
|
||||
public final Timing doChunkMapPlayersNeedingChunks;
|
||||
public final Timing doChunkMapPendingSendToPlayers;
|
||||
public final Timing doChunkMapUnloadChunks;
|
||||
public final Timing doChunkGC;
|
||||
public final Timing doSounds;
|
||||
public final Timing entityRemoval;
|
||||
public final Timing entityTick;
|
||||
public final Timing tileEntityTick;
|
||||
public final Timing tileEntityPending;
|
||||
public final Timing tracker1;
|
||||
public final Timing tracker2;
|
||||
public final Timing doTick;
|
||||
public final Timing tickEntities;
|
||||
|
||||
public final Timing syncChunkLoadTimer;
|
||||
public final Timing syncChunkLoadDataTimer;
|
||||
public final Timing syncChunkLoadStructuresTimer;
|
||||
public final Timing syncChunkLoadPostTimer;
|
||||
public final Timing syncChunkLoadNBTTimer;
|
||||
public final Timing syncChunkLoadPopulateNeighbors;
|
||||
public final Timing chunkGeneration;
|
||||
public final Timing chunkIOStage1;
|
||||
public final Timing chunkIOStage2;
|
||||
public final Timing worldSave;
|
||||
public final Timing worldSaveChunks;
|
||||
public final Timing worldSaveLevel;
|
||||
public final Timing chunkSaveData;
|
||||
|
||||
public final Timing lightingQueueTimer;
|
||||
|
||||
public WorldTimingsHandler(World server) {
|
||||
String name = server.worldData.getName() +" - ";
|
||||
|
||||
mobSpawn = Timings.ofSafe(name + "mobSpawn");
|
||||
doChunkUnload = Timings.ofSafe(name + "doChunkUnload");
|
||||
scheduledBlocks = Timings.ofSafe(name + "Scheduled Blocks");
|
||||
scheduledBlocksCleanup = Timings.ofSafe(name + "Scheduled Blocks - Cleanup");
|
||||
scheduledBlocksTicking = Timings.ofSafe(name + "Scheduled Blocks - Ticking");
|
||||
chunkTicks = Timings.ofSafe(name + "Chunk Ticks");
|
||||
lightChunk = Timings.ofSafe(name + "Light Chunk");
|
||||
chunkTicksBlocks = Timings.ofSafe(name + "Chunk Ticks - Blocks");
|
||||
doVillages = Timings.ofSafe(name + "doVillages");
|
||||
doChunkMap = Timings.ofSafe(name + "doChunkMap");
|
||||
doChunkMapUpdate = Timings.ofSafe(name + "doChunkMap - Update");
|
||||
doChunkMapToUpdate = Timings.ofSafe(name + "doChunkMap - To Update");
|
||||
doChunkMapSortMissing = Timings.ofSafe(name + "doChunkMap - Sort Missing");
|
||||
doChunkMapSortSendToPlayers = Timings.ofSafe(name + "doChunkMap - Sort Send To Players");
|
||||
doChunkMapPlayersNeedingChunks = Timings.ofSafe(name + "doChunkMap - Players Needing Chunks");
|
||||
doChunkMapPendingSendToPlayers = Timings.ofSafe(name + "doChunkMap - Pending Send To Players");
|
||||
doChunkMapUnloadChunks = Timings.ofSafe(name + "doChunkMap - Unload Chunks");
|
||||
doSounds = Timings.ofSafe(name + "doSounds");
|
||||
doChunkGC = Timings.ofSafe(name + "doChunkGC");
|
||||
doPortalForcer = Timings.ofSafe(name + "doPortalForcer");
|
||||
entityTick = Timings.ofSafe(name + "entityTick");
|
||||
entityRemoval = Timings.ofSafe(name + "entityRemoval");
|
||||
tileEntityTick = Timings.ofSafe(name + "tileEntityTick");
|
||||
tileEntityPending = Timings.ofSafe(name + "tileEntityPending");
|
||||
|
||||
syncChunkLoadTimer = Timings.ofSafe(name + "syncChunkLoad");
|
||||
syncChunkLoadDataTimer = Timings.ofSafe(name + "syncChunkLoad - Data");
|
||||
syncChunkLoadStructuresTimer = Timings.ofSafe(name + "chunkLoad - recreateStructures");
|
||||
syncChunkLoadPostTimer = Timings.ofSafe(name + "chunkLoad - Post");
|
||||
syncChunkLoadNBTTimer = Timings.ofSafe(name + "chunkLoad - NBT");
|
||||
syncChunkLoadPopulateNeighbors = Timings.ofSafe(name + "chunkLoad - Populate Neighbors");
|
||||
chunkGeneration = Timings.ofSafe(name + "chunkGeneration");
|
||||
chunkIOStage1 = Timings.ofSafe(name + "ChunkIO Stage 1 - DiskIO");
|
||||
chunkIOStage2 = Timings.ofSafe(name + "ChunkIO Stage 2 - Post Load");
|
||||
worldSave = Timings.ofSafe(name + "World Save");
|
||||
worldSaveLevel = Timings.ofSafe(name + "World Save - Level");
|
||||
worldSaveChunks = Timings.ofSafe(name + "World Save - Chunks");
|
||||
chunkSaveData = Timings.ofSafe(name + "Chunk Save - Data");
|
||||
|
||||
tracker1 = Timings.ofSafe(name + "tracker stage 1");
|
||||
tracker2 = Timings.ofSafe(name + "tracker stage 2");
|
||||
doTick = Timings.ofSafe(name + "doTick");
|
||||
tickEntities = Timings.ofSafe(name + "tickEntities");
|
||||
|
||||
lightingQueueTimer = Timings.ofSafe(name + "Lighting Queue");
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.akarin.api;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
import co.aikar.timings.Timings;
|
||||
|
||||
public abstract class Akari {
|
||||
/**
|
||||
* A common logger used by mixin classes
|
||||
*/
|
||||
public final static Logger logger = LogManager.getLogger("Akarin");
|
||||
|
||||
/**
|
||||
* Temporarily disable desync timings error, moreover it's worthless to trace async operation
|
||||
*/
|
||||
public static volatile boolean silentTiming;
|
||||
|
||||
/**
|
||||
* A common thread pool factory
|
||||
*/
|
||||
public static final ThreadFactory STAGE_FACTORY = new ThreadFactoryBuilder().setNameFormat("Akarin Schedule Thread - %1$d").build();
|
||||
|
||||
/**
|
||||
* Main thread callback tasks
|
||||
*/
|
||||
public static final Queue<Runnable> callbackQueue = Queues.newConcurrentLinkedQueue();
|
||||
|
||||
/**
|
||||
* A common tick pool
|
||||
*/
|
||||
public static final ExecutorCompletionService<Void> STAGE_TICK = new ExecutorCompletionService<Void>(Executors.newFixedThreadPool(1, Akari.STAGE_FACTORY));
|
||||
|
||||
/*
|
||||
* The unsafe
|
||||
*/
|
||||
public final static sun.misc.Unsafe UNSAFE = getUnsafe();
|
||||
|
||||
private static sun.misc.Unsafe getUnsafe() {
|
||||
try {
|
||||
Field theUnsafe = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
return (sun.misc.Unsafe) theUnsafe.get(null);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Timings
|
||||
*/
|
||||
public final static Timing worldTiming = getTiming("Akarin - World");
|
||||
|
||||
public final static Timing callbackTiming = getTiming("Akarin - Callback");
|
||||
|
||||
private static Timing getTiming(String name) {
|
||||
try {
|
||||
Method ofSafe = Timings.class.getDeclaredMethod("ofSafe", String.class);
|
||||
ofSafe.setAccessible(true);
|
||||
return (Timing) ofSafe.invoke(null, name);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
161
sources/src/main/java/io/akarin/api/internal/Akari.java
Normal file
161
sources/src/main/java/io/akarin/api/internal/Akari.java
Normal file
@@ -0,0 +1,161 @@
|
||||
package io.akarin.api.internal;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
import co.aikar.timings.Timings;
|
||||
import io.akarin.api.internal.Akari.AssignableFactory;
|
||||
import io.akarin.api.internal.Akari.TimingSignal;
|
||||
import io.akarin.api.internal.utils.ReentrantSpinningLock;
|
||||
import io.akarin.api.internal.utils.thread.SuspendableExecutorCompletionService;
|
||||
import io.akarin.api.internal.utils.thread.SuspendableThreadPoolExecutor;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public abstract class Akari {
|
||||
/**
|
||||
* A common logger used by mixin classes
|
||||
*/
|
||||
public final static Logger logger = LogManager.getLogger("Akarin");
|
||||
|
||||
/**
|
||||
* A common thread pool factory
|
||||
*/
|
||||
public static final ThreadFactory STAGE_FACTORY = new ThreadFactoryBuilder().setNameFormat("Akarin Parallel Registry Thread - %1$d").build();
|
||||
|
||||
/**
|
||||
* Main thread callback tasks
|
||||
*/
|
||||
public static final Queue<Runnable> callbackQueue = Queues.newConcurrentLinkedQueue();
|
||||
|
||||
public static class AssignableThread extends Thread {
|
||||
public AssignableThread(Runnable run) {
|
||||
super(run);
|
||||
}
|
||||
public AssignableThread() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AssignableFactory implements ThreadFactory {
|
||||
private final String threadName;
|
||||
private int threadNumber;
|
||||
|
||||
public AssignableFactory(String name) {
|
||||
threadName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable run) {
|
||||
Thread thread = new AssignableThread(run);
|
||||
thread.setName(StringUtils.replaceChars(threadName, "$", String.valueOf(threadNumber++)));
|
||||
thread.setPriority(AkarinGlobalConfig.primaryThreadPriority); // Fair
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TimingSignal {
|
||||
public final World tickedWorld;
|
||||
public final boolean isEntities;
|
||||
|
||||
public TimingSignal(World world, boolean entities) {
|
||||
tickedWorld = world;
|
||||
isEntities = entities;
|
||||
}
|
||||
}
|
||||
|
||||
public static SuspendableExecutorCompletionService<TimingSignal> STAGE_TICK;
|
||||
|
||||
static {
|
||||
resizeTickExecutors(3);
|
||||
}
|
||||
|
||||
public static void resizeTickExecutors(int worlds) {
|
||||
int parallelism;
|
||||
switch (AkarinGlobalConfig.parallelMode) {
|
||||
case -1:
|
||||
return;
|
||||
case 0:
|
||||
parallelism = 2;
|
||||
break;
|
||||
case 1:
|
||||
parallelism = worlds + 1;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
parallelism = worlds * 2;
|
||||
break;
|
||||
}
|
||||
STAGE_TICK = new SuspendableExecutorCompletionService<>(new SuspendableThreadPoolExecutor(parallelism, parallelism,
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(),
|
||||
new AssignableFactory("Akarin Parallel Ticking Thread - $")));
|
||||
}
|
||||
|
||||
public static boolean isPrimaryThread() {
|
||||
return isPrimaryThread(true);
|
||||
}
|
||||
|
||||
public static boolean isPrimaryThread(boolean assign) {
|
||||
Thread current = Thread.currentThread();
|
||||
return current == MinecraftServer.getServer().primaryThread || (assign ? (current.getClass() == AssignableThread.class) : false);
|
||||
}
|
||||
|
||||
public static final String EMPTY_STRING = "";
|
||||
|
||||
/*
|
||||
* The unsafe
|
||||
*/
|
||||
public final static sun.misc.Unsafe UNSAFE = getUnsafe();
|
||||
|
||||
private static sun.misc.Unsafe getUnsafe() {
|
||||
try {
|
||||
Field theUnsafe = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
return (sun.misc.Unsafe) theUnsafe.get(null);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String serverVersion = Akari.class.getPackage().getImplementationVersion();
|
||||
|
||||
public static String getServerVersion() {
|
||||
return serverVersion + " (MC: " + MinecraftServer.getServer().getVersion() + ")";
|
||||
}
|
||||
|
||||
/*
|
||||
* Timings
|
||||
*/
|
||||
public final static Timing worldTiming = getTiming("Akarin - Full World Tick");
|
||||
|
||||
public final static Timing callbackTiming = getTiming("Akarin - Callback Queue");
|
||||
|
||||
private static Timing getTiming(String name) {
|
||||
try {
|
||||
Method ofSafe = Timings.class.getDeclaredMethod("ofSafe", String.class);
|
||||
ofSafe.setAccessible(true);
|
||||
return (Timing) ofSafe.invoke(null, name);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.akarin.api;
|
||||
package io.akarin.api.internal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.api.internal.mixin;
|
||||
|
||||
public interface IMixinRealTimeTicking {
|
||||
|
||||
long getRealTimeTicks();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.akarin.api.internal.mixin;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public interface IMixinWorldServer {
|
||||
public Object lock();
|
||||
public Random rand();
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
* at http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
package io.akarin.api;
|
||||
package io.akarin.api.internal.utils;
|
||||
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.ArrayList;
|
||||
@@ -45,6 +45,8 @@ import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
|
||||
/**
|
||||
* An unbounded thread-safe {@linkplain Queue queue} based on linked nodes.
|
||||
* This queue orders elements FIFO (first-in-first-out).
|
||||
@@ -0,0 +1,102 @@
|
||||
package io.akarin.api.internal.utils;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ReentrantSpinningLock {
|
||||
/*
|
||||
* Impl Note:
|
||||
* A write lock can reentrant as a read lock, while a
|
||||
* read lock is not allowed to reentrant as a write lock.
|
||||
* READ LOCK IS UNTESTED, USE WITH CATION.
|
||||
*/
|
||||
private final AtomicBoolean writeLocked = new AtomicBoolean(false);
|
||||
|
||||
// --------- Thread local restricted fields ---------
|
||||
private long heldThreadId = 0;
|
||||
private int reentrantLocks = 0;
|
||||
|
||||
/**
|
||||
* Lock as a typical reentrant write lock
|
||||
*/
|
||||
public void lock() {
|
||||
long currentThreadId = Thread.currentThread().getId();
|
||||
if (heldThreadId == currentThreadId) {
|
||||
reentrantLocks++;
|
||||
} else {
|
||||
while (!writeLocked.compareAndSet(false, true)) ; // In case acquire one lock concurrently
|
||||
heldThreadId = currentThreadId;
|
||||
}
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
if (reentrantLocks == 0) {
|
||||
heldThreadId = 0;
|
||||
//if (readerThreads.get() == 0 || readerThreads.getAndDecrement() == 1) { // Micro-optimization: this saves one subtract
|
||||
writeLocked.set(false);
|
||||
//}
|
||||
} else {
|
||||
--reentrantLocks;
|
||||
}
|
||||
}
|
||||
|
||||
private final AtomicInteger readerThreads = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* Lock as a typical reentrant read lock
|
||||
*/
|
||||
@Deprecated
|
||||
public void lockWeak() {
|
||||
long currentThreadId = Thread.currentThread().getId();
|
||||
if (heldThreadId == currentThreadId) {
|
||||
reentrantLocks++;
|
||||
} else {
|
||||
if (readerThreads.get() == 0) {
|
||||
while (!writeLocked.compareAndSet(false, true)) ; // Block future write lock
|
||||
}
|
||||
heldThreadId = currentThreadId;
|
||||
readerThreads.getAndIncrement(); // Micro-optimization: this saves one plus
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void unlockWeak() {
|
||||
if (reentrantLocks == 0) {
|
||||
heldThreadId = 0;
|
||||
writeLocked.set(false);
|
||||
} else {
|
||||
--reentrantLocks;
|
||||
}
|
||||
}
|
||||
|
||||
// --------- Wrappers to allow typical usages ---------
|
||||
private SpinningWriteLock wrappedWriteLock = new SpinningWriteLock();
|
||||
private SpinningReadLock wrappedReadLock = new SpinningReadLock();
|
||||
|
||||
public class SpinningWriteLock {
|
||||
public void lock() {
|
||||
lock();
|
||||
}
|
||||
public void unlock() {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public class SpinningReadLock {
|
||||
public void lock() {
|
||||
lockWeak();
|
||||
}
|
||||
public void unlock() {
|
||||
unlockWeak();
|
||||
}
|
||||
}
|
||||
|
||||
public SpinningWriteLock writeLock() {
|
||||
return wrappedWriteLock;
|
||||
}
|
||||
|
||||
public SpinningReadLock readLock() {
|
||||
return wrappedReadLock;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.akarin.api;
|
||||
package io.akarin.api.internal.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.ObjectOutputStream;
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
Written in 2015 by Sebastiano Vigna (vigna@acm.org)
|
||||
|
||||
To the extent possible under law, the author has dedicated all copyright
|
||||
and related and neighboring rights to this software to the public domain
|
||||
worldwide. This software is distributed without any warranty.
|
||||
|
||||
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
|
||||
package io.akarin.api.internal.utils.random;
|
||||
|
||||
/**
|
||||
* This is a SplittableRandom-style generator, meant to have a tiny state
|
||||
* that permits storing many different generators with low overhead.
|
||||
* It should be rather fast, though no guarantees can be made on all hardware.
|
||||
* <br>
|
||||
* Benchmarking on a Windows laptop with an i7-4700MQ processor running OpenJDK 8
|
||||
* reports generation of 64-bit random long output as 17.8x faster than generating
|
||||
* an equivalent number of random longs with java.util.Random, and generation of
|
||||
* 32-bit random int output as 9.8x faster. Specifically, generating 1 billion longs
|
||||
* took about 1.28 nanoseconds per long (1.277 seconds for the whole group) with
|
||||
* LightRNG, while java.util.Random (which is meant to produce int, to be fair) took
|
||||
* about 22.8 nanoseconds per long (22.797 seconds for the whole group). XorRNG
|
||||
* appears to be occasionally faster on int output than LightRNG, but it isn't clear
|
||||
* why or what causes that (JIT or GC internals, possibly). XorRNG is slightly
|
||||
* slower at generating 64-bit random data, including long and double, but not by
|
||||
* a significant degree (a multiplier between 0.9 and 1.2 times). The only deciding
|
||||
* factor then is state size, where LightRNG is as small as possible for any JVM
|
||||
* object with even a single field: 16 bytes (on a 64-bit JVM; 8-byte objects with
|
||||
* 4 bytes or less of non-static members may be possible on 32-bit JVMs but I can't
|
||||
* find anything confirming that guess).
|
||||
* <br>
|
||||
* So yes, this should be very fast, and with only a single long used per LightRNG,
|
||||
* it is about as memory-efficient as these generators get.
|
||||
* <br>
|
||||
* Written in 2015 by Sebastiano Vigna (vigna@acm.org)
|
||||
* @author Sebastiano Vigna
|
||||
* @author Tommy Ettinger
|
||||
*/
|
||||
public class LightRNG implements RandomnessSource, StatefulRandomness
|
||||
{
|
||||
/** 2 raised to the 53, - 1. */
|
||||
private static final long DOUBLE_MASK = ( 1L << 53 ) - 1;
|
||||
/** 2 raised to the -53. */
|
||||
private static final double NORM_53 = 1. / ( 1L << 53 );
|
||||
/** 2 raised to the 24, -1. */
|
||||
private static final long FLOAT_MASK = ( 1L << 24 ) - 1;
|
||||
/** 2 raised to the -24. */
|
||||
private static final double NORM_24 = 1. / ( 1L << 24 );
|
||||
|
||||
private static final long serialVersionUID = -374415589203474497L;
|
||||
|
||||
public long state; /* The state can be seeded with any value. */
|
||||
|
||||
/** Creates a new generator seeded using Math.random. */
|
||||
public LightRNG() {
|
||||
this((long) Math.floor(Math.random() * Long.MAX_VALUE));
|
||||
}
|
||||
|
||||
public LightRNG( final long seed ) {
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int next( int bits ) {
|
||||
return (int)( nextLong() & ( 1L << bits ) - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Can return any long, positive or negative, of any size permissible in a 64-bit signed integer.
|
||||
* @return any long, all 64 bits are random
|
||||
*/
|
||||
@Override
|
||||
public long nextLong() {
|
||||
long z = ( state += 0x9E3779B97F4A7C15L );
|
||||
z = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
z = (z ^ (z >>> 27)) * 0x94D049BB133111EBL;
|
||||
return z ^ (z >>> 31);
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the
|
||||
* copy, both will generate the same sequence of random numbers from the point copy() was called. This just need to
|
||||
* copy the state so it isn't shared, usually, and produce a new value with the same exact state.
|
||||
*
|
||||
* @return a copy of this RandomnessSource
|
||||
*/
|
||||
@Override
|
||||
public RandomnessSource copy() {
|
||||
return new LightRNG(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can return any int, positive or negative, of any size permissible in a 32-bit signed integer.
|
||||
* @return any int, all 32 bits are random
|
||||
*/
|
||||
public int nextInt() {
|
||||
return (int)nextLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclusive on the upper bound. The lower bound is 0.
|
||||
* @param bound the upper bound; should be positive
|
||||
* @return a random int less than n and at least equal to 0
|
||||
*/
|
||||
public int nextInt( final int bound ) {
|
||||
if ( bound <= 0 ) return 0;
|
||||
int threshold = (0x7fffffff - bound + 1) % bound;
|
||||
for (;;) {
|
||||
int bits = (int)(nextLong() & 0x7fffffff);
|
||||
if (bits >= threshold)
|
||||
return bits % bound;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inclusive lower, exclusive upper.
|
||||
* @param lower the lower bound, inclusive, can be positive or negative
|
||||
* @param upper the upper bound, exclusive, should be positive, must be greater than lower
|
||||
* @return a random int at least equal to lower and less than upper
|
||||
*/
|
||||
public int nextInt( final int lower, final int upper ) {
|
||||
if ( upper - lower <= 0 ) throw new IllegalArgumentException("Upper bound must be greater than lower bound");
|
||||
return lower + nextInt(upper - lower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclusive on the upper bound. The lower bound is 0.
|
||||
* @param bound the upper bound; should be positive
|
||||
* @return a random long less than n
|
||||
*/
|
||||
public long nextLong( final long bound ) {
|
||||
if ( bound <= 0 ) return 0;
|
||||
long threshold = (0x7fffffffffffffffL - bound + 1) % bound;
|
||||
for (;;) {
|
||||
long bits = nextLong() & 0x7fffffffffffffffL;
|
||||
if (bits >= threshold)
|
||||
return bits % bound;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inclusive lower, exclusive upper.
|
||||
* @param lower the lower bound, inclusive, can be positive or negative
|
||||
* @param upper the upper bound, exclusive, should be positive, must be greater than lower
|
||||
* @return a random long at least equal to lower and less than upper
|
||||
*/
|
||||
public long nextLong( final long lower, final long upper ) {
|
||||
if ( upper - lower <= 0 ) throw new IllegalArgumentException("Upper bound must be greater than lower bound");
|
||||
return lower + nextLong(upper - lower);
|
||||
}
|
||||
/**
|
||||
* Gets a uniform random double in the range [0.0,1.0)
|
||||
* @return a random double at least equal to 0.0 and less than 1.0
|
||||
*/
|
||||
public double nextDouble() {
|
||||
return ( nextLong() & DOUBLE_MASK ) * NORM_53;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a uniform random double in the range [0.0,outer) given a positive parameter outer. If outer
|
||||
* is negative, it will be the (exclusive) lower bound and 0.0 will be the (inclusive) upper bound.
|
||||
* @param outer the exclusive outer bound, can be negative
|
||||
* @return a random double between 0.0 (inclusive) and outer (exclusive)
|
||||
*/
|
||||
public double nextDouble(final double outer) {
|
||||
return nextDouble() * outer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a uniform random float in the range [0.0,1.0)
|
||||
* @return a random float at least equal to 0.0 and less than 1.0
|
||||
*/
|
||||
public float nextFloat() {
|
||||
return (float)( ( nextLong() & FLOAT_MASK ) * NORM_24 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a random value, true or false.
|
||||
* Calls nextLong() once.
|
||||
* @return a random true or false value.
|
||||
*/
|
||||
public boolean nextBoolean() {
|
||||
return ( nextLong() & 1 ) != 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a byte array as a parameter, this will fill the array with random bytes (modifying it
|
||||
* in-place). Calls nextLong() {@code Math.ceil(bytes.length / 8.0)} times.
|
||||
* @param bytes a byte array that will have its contents overwritten with random bytes.
|
||||
*/
|
||||
public void nextBytes( final byte[] bytes ) {
|
||||
int i = bytes.length, n = 0;
|
||||
while( i != 0 ) {
|
||||
n = Math.min( i, 8 );
|
||||
for ( long bits = nextLong(); n-- != 0; bits >>= 8 ) bytes[ --i ] = (byte)bits;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the seed of this generator (which is also the current state).
|
||||
* @param seed the seed to use for this LightRNG, as if it was constructed with this seed.
|
||||
*/
|
||||
public void setSeed( final long seed ) {
|
||||
state = seed;
|
||||
}
|
||||
/**
|
||||
* Sets the seed (also the current state) of this generator.
|
||||
* @param seed the seed to use for this LightRNG, as if it was constructed with this seed.
|
||||
*/
|
||||
@Override
|
||||
public void setState( final long seed ) {
|
||||
state = seed;
|
||||
}
|
||||
/**
|
||||
* Gets the current state of this generator.
|
||||
* @return the current seed of this LightRNG, changed once per call to nextLong()
|
||||
*/
|
||||
@Override
|
||||
public long getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances or rolls back the LightRNG's state without actually generating numbers. Skip forward
|
||||
* or backward a number of steps specified by advance, where a step is equal to one call to nextInt().
|
||||
* @param advance Number of future generations to skip past. Can be negative to backtrack.
|
||||
* @return the state after skipping.
|
||||
*/
|
||||
public long skip(long advance)
|
||||
{
|
||||
return state += 0x9E3779B97F4A7C15L * advance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LightRNG (" + state + ")"; // Akarin
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package io.akarin.api.internal.utils.random;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This is a "fake" LightRandom, backed by the LightRNG.
|
||||
*
|
||||
* This is useful if you want to quickly replace a Random variable with
|
||||
* LightRNG without breaking every code.
|
||||
*/
|
||||
public class LightRandom extends Random {
|
||||
public static LightRNG light = new LightRNG(); // LightRNG, static.
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public int next(int bits) {
|
||||
return light.next(bits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextBytes(byte[] bytes) {
|
||||
light.nextBytes(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return light.nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int n) {
|
||||
return light.nextInt(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return light.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return light.nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return light.nextFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return light.nextDouble();
|
||||
}
|
||||
|
||||
// Akarin start
|
||||
@Override
|
||||
public void setSeed(long seed) {
|
||||
light.setSeed(seed);
|
||||
}
|
||||
// Akarin end
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.akarin.api.internal.utils.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This interface defines the interactions required of a random number
|
||||
* generator. It is a replacement for Java's built-in Random because for
|
||||
* improved performance.
|
||||
*
|
||||
* @author Eben Howard - http://squidpony.com - howard@squidpony.com
|
||||
*/
|
||||
public interface RandomnessSource extends Serializable {
|
||||
|
||||
/**
|
||||
* Using this method, any algorithm that might use the built-in Java Random
|
||||
* can interface with this randomness source.
|
||||
*
|
||||
* @param bits the number of bits to be returned
|
||||
* @return the integer containing the appropriate number of bits
|
||||
*/
|
||||
int next(int bits);
|
||||
|
||||
/**
|
||||
*
|
||||
* Using this method, any algorithm that needs to efficiently generate more
|
||||
* than 32 bits of random data can interface with this randomness source.
|
||||
*
|
||||
* Get a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive).
|
||||
* @return a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive)
|
||||
*/
|
||||
long nextLong();
|
||||
|
||||
/**
|
||||
* Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the
|
||||
* copy, both will generate the same sequence of random numbers from the point copy() was called. This just need to
|
||||
* copy the state so it isn't shared, usually, and produce a new value with the same exact state.
|
||||
* @return a copy of this RandomnessSource
|
||||
*/
|
||||
RandomnessSource copy();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.akarin.api.internal.utils.random;
|
||||
|
||||
/**
|
||||
* A simple interface for RandomnessSources that have the additional property of a state that can be re-set.
|
||||
* Created by Tommy Ettinger on 9/15/2015.
|
||||
*/
|
||||
public interface StatefulRandomness extends RandomnessSource {
|
||||
/**
|
||||
* Get the current internal state of the StatefulRandomness as a long.
|
||||
* @return the current internal state of this object.
|
||||
*/
|
||||
long getState();
|
||||
|
||||
/**
|
||||
* Set the current internal state of this StatefulRandomness with a long.
|
||||
*
|
||||
* @param state a 64-bit long. You should avoid passing 0, even though some implementations can handle that.
|
||||
*/
|
||||
void setState(long state);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.akarin.api.internal.utils.thread;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class OpenExecutionException extends ExecutionException {
|
||||
private static final long serialVersionUID = 7830266012832686185L;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Written by Doug Lea with assistance from members of JCP JSR-166
|
||||
* Expert Group and released to the public domain, as explained at
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
package io.akarin.api.internal.utils.thread;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletionService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SuspendableExecutorCompletionService<V> implements CompletionService<V> {
|
||||
private final SuspendableThreadPoolExecutor executor;
|
||||
private final BlockingQueue<Future<V>> completionQueue;
|
||||
|
||||
public void suspend() {
|
||||
executor.suspend();
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
executor.resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* FutureTask extension to enqueue upon completion
|
||||
*/
|
||||
private class QueueingFuture extends FutureTask<Void> {
|
||||
QueueingFuture(RunnableFuture<V> task) {
|
||||
super(task, null);
|
||||
this.task = task;
|
||||
}
|
||||
protected void done() { completionQueue.add(task); }
|
||||
private final Future<V> task;
|
||||
}
|
||||
|
||||
private RunnableFuture<V> newTaskFor(Callable<V> task) {
|
||||
return new FutureTask<V>(task);
|
||||
}
|
||||
|
||||
private RunnableFuture<V> newTaskFor(Runnable task, V result) {
|
||||
return new FutureTask<V>(task, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ExecutorCompletionService using the supplied
|
||||
* executor for base task execution and a
|
||||
* {@link LinkedBlockingQueue} as a completion queue.
|
||||
*
|
||||
* @param executor the executor to use
|
||||
* @throws NullPointerException if executor is {@code null}
|
||||
*/
|
||||
public SuspendableExecutorCompletionService(SuspendableThreadPoolExecutor executor) {
|
||||
if (executor == null)
|
||||
throw new NullPointerException();
|
||||
this.executor = executor;
|
||||
this.completionQueue = new LinkedBlockingQueue<Future<V>>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ExecutorCompletionService using the supplied
|
||||
* executor for base task execution and the supplied queue as its
|
||||
* completion queue.
|
||||
*
|
||||
* @param executor the executor to use
|
||||
* @param completionQueue the queue to use as the completion queue
|
||||
* normally one dedicated for use by this service. This
|
||||
* queue is treated as unbounded -- failed attempted
|
||||
* {@code Queue.add} operations for completed tasks cause
|
||||
* them not to be retrievable.
|
||||
* @throws NullPointerException if executor or completionQueue are {@code null}
|
||||
*/
|
||||
public SuspendableExecutorCompletionService(SuspendableThreadPoolExecutor executor,
|
||||
BlockingQueue<Future<V>> completionQueue) {
|
||||
if (executor == null || completionQueue == null)
|
||||
throw new NullPointerException();
|
||||
this.executor = executor;
|
||||
this.completionQueue = completionQueue;
|
||||
}
|
||||
|
||||
public Future<V> submit(Callable<V> task) {
|
||||
if (task == null) throw new NullPointerException();
|
||||
RunnableFuture<V> f = newTaskFor(task);
|
||||
executor.execute(new QueueingFuture(f));
|
||||
return f;
|
||||
}
|
||||
|
||||
public Future<V> submit(Runnable task, V result) {
|
||||
if (task == null) throw new NullPointerException();
|
||||
RunnableFuture<V> f = newTaskFor(task, result);
|
||||
executor.execute(new QueueingFuture(f));
|
||||
return f;
|
||||
}
|
||||
|
||||
public Future<V> take() throws InterruptedException {
|
||||
return completionQueue.take();
|
||||
}
|
||||
|
||||
public Future<V> poll() {
|
||||
return completionQueue.poll();
|
||||
}
|
||||
|
||||
public Future<V> poll(long timeout, TimeUnit unit)
|
||||
throws InterruptedException {
|
||||
return completionQueue.poll(timeout, unit);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,8 @@ package io.akarin.server.core;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -14,8 +16,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import io.akarin.api.Akari;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class AkarinGlobalConfig {
|
||||
|
||||
private static File CONFIG_FILE;
|
||||
@@ -153,11 +155,6 @@ public class AkarinGlobalConfig {
|
||||
legacyVersioningCompat = getBoolean("alternative.legacy-versioning-compat", false);
|
||||
}
|
||||
|
||||
public static int registryTerminationSeconds;
|
||||
private static void registryTerminationSeconds() {
|
||||
registryTerminationSeconds = getSeconds(getString("bootstrap.parallel-registry-termination", "9s"));
|
||||
}
|
||||
|
||||
public static int playersPerIOThread;
|
||||
private static void playersPerIOThread() {
|
||||
playersPerIOThread = getInt("core.players-per-chunk-io-thread", 50);
|
||||
@@ -168,28 +165,106 @@ public class AkarinGlobalConfig {
|
||||
silentAsyncTimings = getBoolean("core.always-silent-async-timing", false);
|
||||
}
|
||||
|
||||
public static boolean legacyWorldTimings;
|
||||
private static void legacyWorldTimings() {
|
||||
legacyWorldTimings = getBoolean("alternative.legacy-world-timings-required", false);
|
||||
}
|
||||
|
||||
public static int timeUpdateInterval;
|
||||
public static long timeUpdateInterval;
|
||||
private static void timeUpdateInterval() {
|
||||
timeUpdateInterval = getSeconds(getString("core.world-time-update-interval", "1s"));
|
||||
timeUpdateInterval = getSeconds(getString("core.tick-rate.world-time-update-interval", "1s")) * 10;
|
||||
}
|
||||
|
||||
public static int keepAliveSendInterval;
|
||||
public static long keepAliveSendInterval;
|
||||
private static void keepAliveSendInterval() {
|
||||
keepAliveSendInterval = getSeconds(getString("core.keep-alive-packet-send-interval", "15s"));
|
||||
keepAliveSendInterval = getSeconds(getString("core.tick-rate.keep-alive-packet-send-interval", "15s")) * 1000;
|
||||
}
|
||||
|
||||
public static int keepAliveTimeout;
|
||||
public static long keepAliveTimeout;
|
||||
private static void keepAliveTimeout() {
|
||||
keepAliveTimeout = getSeconds(getString("core.keep-alive-response-timeout", "30s"));
|
||||
keepAliveTimeout = getSeconds(getString("core.keep-alive-response-timeout", "30s")) * 1000;
|
||||
}
|
||||
|
||||
public static boolean throwOnAsyncCaught;
|
||||
private static void throwOnAsyncCaught() {
|
||||
throwOnAsyncCaught = getBoolean("core.thread-safe.async-catcher.throw-on-caught", true);
|
||||
}
|
||||
|
||||
public static boolean allowSpawnerModify;
|
||||
private static void allowSpawnerModify() {
|
||||
allowSpawnerModify = getBoolean("alternative.allow-spawner-modify", true);
|
||||
}
|
||||
|
||||
public static boolean noResponseDoGC;
|
||||
private static void noResponseDoGC() {
|
||||
noResponseDoGC = getBoolean("alternative.gc-before-stuck-restart", true);
|
||||
}
|
||||
|
||||
public static String messageKick;
|
||||
public static String messageBan;
|
||||
public static String messageBanReason;
|
||||
public static String messageBanExpires;
|
||||
public static String messageBanIp;
|
||||
public static String messageDupLogin;
|
||||
public static String messageJoin;
|
||||
public static String messageJoinRenamed;
|
||||
public static String messageKickKeepAlive;
|
||||
public static String messagePlayerQuit;
|
||||
private static void messagekickKeepAlive() {
|
||||
messageKick = getString("messages.disconnect.kick-player", "Kicked by an operator.");
|
||||
messageBan = getString("messages.disconnect.ban-player-name", "You are banned from this server! %s %s");
|
||||
messageBanReason = getString("messages.disconnect.ban-reason", "\nReason: ");
|
||||
messageBanExpires = getString("messages.disconnect.ban-expires", "\nYour ban will be removed on ");
|
||||
messageBanIp = getString("messages.disconnect.ban-player-ip", "Your IP address is banned from this server! %s %s");
|
||||
messageDupLogin = getString("messages.disconnect.kick-player-duplicate-login", "You logged in from another location");
|
||||
messageJoin = getString("messages.connect.player-join-server", "§e%s joined the game");
|
||||
messageJoinRenamed = getString("messages.connect.renamed-player-join-server", "§e%s (formerly known as %s) joined the game");
|
||||
messageKickKeepAlive = getString("messages.disconnect.kick-player-timeout-keep-alive", "Timed out");
|
||||
messagePlayerQuit = getString("messages.disconnect.player-quit-server", "§e%s left the game");
|
||||
}
|
||||
|
||||
public static String serverBrandName;
|
||||
private static void serverBrandName() {
|
||||
serverBrandName = getString("alternative.modified-server-brand-name", "");
|
||||
}
|
||||
|
||||
public static boolean disableEndPortalCreate;
|
||||
private static void disableEndPortalCreate() {
|
||||
disableEndPortalCreate = getBoolean("alternative.disable-end-portal-create", false);
|
||||
}
|
||||
|
||||
public static int primaryThreadPriority;
|
||||
private static void primaryThreadPriority() {
|
||||
primaryThreadPriority = getInt("core.primary-thread-priority", 7);
|
||||
}
|
||||
|
||||
public static long playersInfoUpdateInterval;
|
||||
private static void playersInfoUpdateInterval() {
|
||||
playersInfoUpdateInterval = getSeconds(getString("core.tick-rate.players-info-update-interval", "30s")) * 10;
|
||||
}
|
||||
|
||||
public static long versionUpdateInterval;
|
||||
private static void versionUpdateInterval() {
|
||||
versionUpdateInterval = getSeconds(getString("alternative.version-update-interval", "3600s")) * 1000; // 1 hour
|
||||
}
|
||||
|
||||
public static boolean sendLightOnlyChunkSection;
|
||||
private static void sendLightOnlyChunkSection() {
|
||||
sendLightOnlyChunkSection = getBoolean("core.send-light-only-chunk-sections", true);
|
||||
}
|
||||
|
||||
public static boolean forceHardcoreDifficulty;
|
||||
private static void forceHardcoreDifficulty() {
|
||||
forceHardcoreDifficulty = getBoolean("alternative.force-difficulty-on-hardcore", true);
|
||||
}
|
||||
|
||||
public static int fileIOThreads;
|
||||
private static void fileIOThreads() {
|
||||
fileIOThreads = getInt("core.chunk-save-threads", 2);
|
||||
}
|
||||
|
||||
public static int parallelMode;
|
||||
private static void parallelMode() {
|
||||
parallelMode = getInt("core.parallel-mode", 1);
|
||||
}
|
||||
|
||||
public static boolean noChunksPastWorldBorder = true;
|
||||
private static void noChunksPastWorldBorder() {
|
||||
noChunksPastWorldBorder = getBoolean("core.no-chunks-past-world-border", noChunksPastWorldBorder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package io.akarin.server.core;
|
||||
|
||||
import io.akarin.api.Akari;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.EnumDifficulty;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PacketPlayOutKeepAlive;
|
||||
import net.minecraft.server.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.PacketPlayOutUpdateTime;
|
||||
import net.minecraft.server.PlayerConnection;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
public class AkarinSlackScheduler extends Thread {
|
||||
public static AkarinSlackScheduler get() {
|
||||
return Singleton.instance;
|
||||
}
|
||||
|
||||
public static void boot() {
|
||||
Singleton.instance.setName("Akarin Slack Scheduler Thread");
|
||||
Singleton.instance.setPriority(MIN_PRIORITY);
|
||||
Singleton.instance.setDaemon(true);
|
||||
Singleton.instance.start();
|
||||
public void boot() {
|
||||
setName("Akarin Slack Scheduler Thread");
|
||||
setDaemon(true);
|
||||
start();
|
||||
Akari.logger.info("Slack scheduler service started");
|
||||
}
|
||||
|
||||
@@ -24,49 +29,80 @@ public class AkarinSlackScheduler extends Thread {
|
||||
private static final AkarinSlackScheduler instance = new AkarinSlackScheduler();
|
||||
}
|
||||
|
||||
/*
|
||||
* Timers
|
||||
*/
|
||||
private long updateTime;
|
||||
private long resendPlayersInfo;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
|
||||
// Send time updates to everyone, it will get the right time from the world the player is in.
|
||||
if (++updateTime == AkarinGlobalConfig.timeUpdateInterval * 10) {
|
||||
while (server.isRunning()) {
|
||||
long startProcessTiming = System.currentTimeMillis();
|
||||
// Send time updates to everyone, it will get the right time from the world the player is in.
|
||||
// Time update, from MinecraftServer#D
|
||||
if (++updateTime >= AkarinGlobalConfig.timeUpdateInterval) {
|
||||
for (EntityPlayer player : server.getPlayerList().players) {
|
||||
// Add support for per player time
|
||||
player.playerConnection.sendPacket(new PacketPlayOutUpdateTime(player.world.getTime(), player.getPlayerTime(), player.world.getGameRules().getBoolean("doDaylightCycle")));
|
||||
}
|
||||
updateTime = 0;
|
||||
}
|
||||
|
||||
// Keep alive, from PlayerConnection#e
|
||||
for (EntityPlayer player : server.getPlayerList().players) {
|
||||
player.playerConnection.sendPacket(new PacketPlayOutUpdateTime(player.world.getTime(), player.getPlayerTime(), player.world.getGameRules().getBoolean("doDaylightCycle"))); // Add support for per player time
|
||||
}
|
||||
updateTime = 0;
|
||||
}
|
||||
|
||||
for (EntityPlayer player : server.getPlayerList().players) {
|
||||
PlayerConnection conn = player.playerConnection;
|
||||
// Paper - give clients a longer time to respond to pings as per pre 1.12.2 timings
|
||||
// This should effectively place the keepalive handling back to "as it was" before 1.12.2
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long elapsedTime = currentTime - conn.getLastPing();
|
||||
if (conn.isPendingPing()) {
|
||||
// We're pending a ping from the client
|
||||
if (!conn.processedDisconnect && elapsedTime >= AkarinGlobalConfig.keepAliveTimeout * 1000L) { // check keepalive limit, don't fire if already disconnected
|
||||
Akari.callbackQueue.add(() -> {
|
||||
Akari.logger.warn("{} was kicked due to keepalive timeout!", conn.player.getName()); // more info
|
||||
conn.disconnect("disconnect.timeout");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (elapsedTime >= AkarinGlobalConfig.keepAliveSendInterval * 1000L) { // 15 seconds default
|
||||
conn.setPendingPing(true);
|
||||
conn.setLastPing(currentTime);
|
||||
conn.setKeepAliveID(currentTime);
|
||||
conn.sendPacket(new PacketPlayOutKeepAlive(conn.getKeepAliveID()));
|
||||
PlayerConnection conn = player.playerConnection;
|
||||
// Paper - give clients a longer time to respond to pings as per pre 1.12.2 timings
|
||||
// This should effectively place the keepalive handling back to "as it was" before 1.12.2
|
||||
long currentTime = System.nanoTime() / 1000000L;
|
||||
long elapsedTime = currentTime - conn.getLastPing();
|
||||
if (conn.isPendingPing()) {
|
||||
// We're pending a ping from the client
|
||||
if (!conn.processedDisconnect && elapsedTime >= AkarinGlobalConfig.keepAliveTimeout) { // check keepalive limit, don't fire if already disconnected
|
||||
Akari.callbackQueue.add(() -> {
|
||||
Akari.logger.warn("{} was kicked due to keepalive timeout!", conn.player.getName()); // more info
|
||||
conn.disconnect("disconnect.timeout");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (elapsedTime >= AkarinGlobalConfig.keepAliveSendInterval) { // 15 seconds default
|
||||
conn.setPendingPing(true);
|
||||
conn.setLastPing(currentTime);
|
||||
conn.setKeepAliveID(currentTime);
|
||||
conn.sendPacket(new PacketPlayOutKeepAlive(conn.getKeepAliveID())); // 15s lagg you should stop your server
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
Akari.logger.warn("Slack scheduler thread was interrupted unexpectly!");
|
||||
ex.printStackTrace();
|
||||
// Force hardcore difficulty, from WorldServer#doTick
|
||||
if (AkarinGlobalConfig.forceHardcoreDifficulty)
|
||||
for (WorldServer world : server.worlds) {
|
||||
if (world.getWorldData().isHardcore() && world.getDifficulty() != EnumDifficulty.HARD) {
|
||||
world.getWorldData().setDifficulty(EnumDifficulty.HARD);
|
||||
}
|
||||
}
|
||||
|
||||
// Update player info, from PlayerList#tick
|
||||
if (++resendPlayersInfo > AkarinGlobalConfig.playersInfoUpdateInterval) {
|
||||
for (EntityPlayer player : server.getPlayerList().players) {
|
||||
player.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, Iterables.filter(server.getPlayerList().players, new Predicate<EntityPlayer>() {
|
||||
@Override
|
||||
public boolean apply(EntityPlayer each) {
|
||||
return player.getBukkitEntity().canSee(each.getBukkitEntity());
|
||||
}
|
||||
})));
|
||||
}
|
||||
resendPlayersInfo = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
long sleepFixed = 100 - (System.currentTimeMillis() - startProcessTiming);
|
||||
if (sleepFixed > 0) Thread.sleep(sleepFixed);
|
||||
} catch (InterruptedException interrupted) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package io.akarin.server.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelException;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import net.minecraft.server.EnumProtocolDirection;
|
||||
import net.minecraft.server.HandshakeListener;
|
||||
import net.minecraft.server.LegacyPingHandler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.PacketDecoder;
|
||||
import net.minecraft.server.PacketEncoder;
|
||||
import net.minecraft.server.PacketPrepender;
|
||||
import net.minecraft.server.PacketSplitter;
|
||||
|
||||
public class ChannelAdapter extends ChannelInitializer<Channel> {
|
||||
private final List<NetworkManager> managers;
|
||||
|
||||
public ChannelAdapter(List<NetworkManager> list) {
|
||||
managers = list;
|
||||
}
|
||||
|
||||
public static ChannelAdapter create(List<NetworkManager> managers) {
|
||||
return new ChannelAdapter(managers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(Channel channel) {
|
||||
try {
|
||||
channel.config().setOption(ChannelOption.TCP_NODELAY, true);
|
||||
} catch (ChannelException ex) {
|
||||
;
|
||||
}
|
||||
channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30))
|
||||
.addLast("legacy_query", new LegacyPingHandler(MinecraftServer.getServer().getServerConnection()))
|
||||
.addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder(EnumProtocolDirection.SERVERBOUND))
|
||||
.addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder(EnumProtocolDirection.CLIENTBOUND));
|
||||
|
||||
NetworkManager manager = new NetworkManager(EnumProtocolDirection.SERVERBOUND);
|
||||
managers.add(manager);
|
||||
|
||||
channel.pipeline().addLast("packet_handler", manager);
|
||||
manager.setPacketListener(new HandshakeListener(MinecraftServer.getServer(), manager));
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import io.akarin.api.Akari;
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
|
||||
@Mixin(value = Main.class, remap = false)
|
||||
public class Bootstrap {
|
||||
public abstract class Bootstrap {
|
||||
@Inject(method = "main([Ljava/lang/String;)V", at = @At("HEAD"))
|
||||
private static void premain(CallbackInfo info) {
|
||||
AkarinGlobalConfig.init(new File("akarin.yml"));
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Overwrite;
|
||||
import net.minecraft.server.EULA;
|
||||
|
||||
@Mixin(value = EULA.class, remap = false)
|
||||
public class DummyEula {
|
||||
public abstract class DummyEula {
|
||||
/**
|
||||
* Read then check the EULA file <i>formerly</i>
|
||||
* @param file
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.destroystokyo.paper.Metrics;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(targets = "com.destroystokyo.paper.Metrics$PaperMetrics", remap = false)
|
||||
public class MetricsBootstrap {
|
||||
public abstract class MetricsBootstrap {
|
||||
@Overwrite
|
||||
static void startMetrics() {
|
||||
// Get the config file
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.destroystokyo.paper.Metrics;
|
||||
import com.destroystokyo.paper.Metrics.CustomChart;
|
||||
|
||||
@Mixin(value = Metrics.class, remap = false)
|
||||
public class MixinMetrics {
|
||||
public abstract class MixinMetrics {
|
||||
// The url to which the data is sent - bukkit/Torch (keep our old name)
|
||||
private final static String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.akarin.server.mixin.bootstrap;
|
||||
|
||||
import org.spigotmc.RestartCommand;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
|
||||
@Mixin(value = RestartCommand.class, remap = false)
|
||||
public abstract class MixinRestartCommand {
|
||||
@Inject(method = "restart()V", at = @At("HEAD"))
|
||||
private static void beforeRestart(CallbackInfo ci) {
|
||||
if (AkarinGlobalConfig.noResponseDoGC) {
|
||||
Akari.logger.warn("Attempting to garbage collect, may takes a few seconds");
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import io.akarin.api.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import io.akarin.api.internal.Akari;
|
||||
import net.minecraft.server.BiomeBase;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.BlockFire;
|
||||
@@ -25,7 +24,7 @@ import net.minecraft.server.PotionRegistry;
|
||||
import net.minecraft.server.SoundEffect;
|
||||
|
||||
@Mixin(value = DispenserRegistry.class, remap = false)
|
||||
public class ParallelRegistry {
|
||||
public abstract class ParallelRegistry {
|
||||
/**
|
||||
* Registry order: SoundEffect -> Block
|
||||
*/
|
||||
@@ -40,8 +39,6 @@ public class ParallelRegistry {
|
||||
*/
|
||||
private static final ExecutorService STAGE_STANDALONE = Executors.newFixedThreadPool(3, Akari.STAGE_FACTORY);
|
||||
|
||||
private static final int TERMINATION_IN_SEC = AkarinGlobalConfig.registryTerminationSeconds;
|
||||
|
||||
// We should keep the original order in codes thought orderless in runtime
|
||||
@Redirect(method = "c()V", at = @At(
|
||||
value = "INVOKE",
|
||||
@@ -131,11 +128,12 @@ public class ParallelRegistry {
|
||||
// Shutdown BLOCK and STANDALONE stage
|
||||
STAGE_STANDALONE.shutdown();
|
||||
STAGE_BLOCK.shutdown();
|
||||
STAGE_BLOCK.awaitTermination(TERMINATION_IN_SEC, TimeUnit.SECONDS);
|
||||
STAGE_BLOCK.awaitTermination(10, TimeUnit.MINUTES);
|
||||
|
||||
STAGE_BLOCK_BASE.shutdown(); // This must after STAGE_BLOCK terminated
|
||||
STAGE_BLOCK_BASE.awaitTermination(TERMINATION_IN_SEC, TimeUnit.SECONDS);
|
||||
STAGE_BLOCK_BASE.awaitTermination(20, TimeUnit.MINUTES);
|
||||
|
||||
STAGE_STANDALONE.awaitTermination(TERMINATION_IN_SEC, TimeUnit.SECONDS); // Behind the shutdown of BLOCK_BASE should faster
|
||||
STAGE_STANDALONE.awaitTermination(30, TimeUnit.MINUTES); // Behind the shutdown of BLOCK_BASE should faster
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.spigotmc.RestartCommand;
|
||||
import org.spigotmc.WatchdogThread;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -20,9 +19,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = WatchdogThread.class, remap = false)
|
||||
public class Watchcat extends Thread {
|
||||
public abstract class Watchcat extends Thread {
|
||||
@Shadow private static WatchdogThread instance;
|
||||
@Shadow private @Final long timeoutTime;
|
||||
@Shadow private @Final long earlyWarningEvery; // Paper - Timeout time for just printing a dump but not restarting
|
||||
@Shadow private @Final long earlyWarningDelay; // Paper
|
||||
@Shadow public static volatile boolean hasStarted; // Paper
|
||||
@Shadow private long lastEarlyWarning; // Paper - Keep track of short dump times to avoid spamming console with short dumps
|
||||
@Shadow private @Final boolean restart;
|
||||
@Shadow private volatile long lastTick;
|
||||
@Shadow private volatile boolean stopping;
|
||||
@@ -38,48 +41,73 @@ public class Watchcat extends Thread {
|
||||
@Overwrite
|
||||
public void run() {
|
||||
while (!stopping) {
|
||||
//
|
||||
if (lastTick != 0 && System.currentTimeMillis() > lastTick + timeoutTime && !Boolean.getBoolean("disable.watchdog")) { // Paper - Add property to disable
|
||||
Logger log = Bukkit.getServer().getLogger();
|
||||
log.log(Level.SEVERE, "Server has stopped responding!");
|
||||
log.log(Level.SEVERE, "Please report this to https://github.com/Akarin-project/Akarin/issues");
|
||||
log.log(Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports");
|
||||
log.log(Level.SEVERE, "Akarin version: " + Bukkit.getServer().getVersion());
|
||||
//
|
||||
if (net.minecraft.server.World.haveWeSilencedAPhysicsCrash) {
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed");
|
||||
log.log(Level.SEVERE, "near " + net.minecraft.server.World.blockLocation);
|
||||
}
|
||||
// Paper start - Warn in watchdog if an excessive velocity was ever set
|
||||
if (CraftServer.excessiveVelEx != null) {
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity");
|
||||
log.log(Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated");
|
||||
log.log(Level.SEVERE, CraftServer.excessiveVelEx.getMessage());
|
||||
for (StackTraceElement stack : CraftServer.excessiveVelEx.getStackTrace()) {
|
||||
log.log(Level.SEVERE, "\t\t" + stack);
|
||||
}
|
||||
}
|
||||
// Paper start
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if ( lastTick != 0 && currentTime > lastTick + earlyWarningEvery && !Boolean.getBoolean("disable.watchdog") )
|
||||
{
|
||||
boolean isLongTimeout = currentTime > lastTick + timeoutTime;
|
||||
// Don't spam early warning dumps
|
||||
if (!isLongTimeout && (earlyWarningEvery <= 0 || !hasStarted || currentTime < lastEarlyWarning + earlyWarningEvery || currentTime < lastTick + earlyWarningDelay))
|
||||
continue;
|
||||
lastEarlyWarning = currentTime;
|
||||
// Paper end
|
||||
Logger log = Bukkit.getServer().getLogger();
|
||||
// Paper start - Different message when it's a short timeout
|
||||
if (isLongTimeout) {
|
||||
log.log(Level.SEVERE, "The server has stopped responding!");
|
||||
log.log(Level.SEVERE, "Please report this to https://github.com/Akarin-project/Akarin/issues"); // Akarin
|
||||
log.log(Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports");
|
||||
log.log(Level.SEVERE, "Akarin version: " + Bukkit.getServer().getVersion()); // Akarin
|
||||
//
|
||||
if (net.minecraft.server.World.haveWeSilencedAPhysicsCrash) {
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed");
|
||||
log.log(Level.SEVERE, "near " + net.minecraft.server.World.blockLocation);
|
||||
}
|
||||
// Paper start - Warn in watchdog if an excessive velocity was ever set
|
||||
if (org.bukkit.craftbukkit.CraftServer.excessiveVelEx != null) {
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity");
|
||||
log.log(Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated");
|
||||
log.log(Level.SEVERE, org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getMessage());
|
||||
for (StackTraceElement stack : org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getStackTrace()) {
|
||||
log.log(Level.SEVERE, "\t\t" + stack);
|
||||
}
|
||||
}
|
||||
// Paper end
|
||||
} else {
|
||||
// log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---"); // Akarin
|
||||
log.log(Level.SEVERE, "The server has not responded for " + (currentTime - lastTick) / 1000 + " seconds! Creating thread dump");
|
||||
}
|
||||
// Paper end - Different message for short timeout
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Akarin!):");
|
||||
dumpThread(ManagementFactory.getThreadMXBean().getThreadInfo(MinecraftServer.getServer().primaryThread.getId(), Integer.MAX_VALUE), log);
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
//
|
||||
log.log(Level.SEVERE, "Entire Thread Dump:");
|
||||
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
|
||||
for (ThreadInfo thread : threads) {
|
||||
dumpThread(thread, log);
|
||||
// Paper start - Only print full dump on long timeouts
|
||||
if (isLongTimeout) {
|
||||
log.log(Level.SEVERE, "Entire Thread Dump:");
|
||||
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
|
||||
for (ThreadInfo thread : threads) {
|
||||
dumpThread(thread, log);
|
||||
}
|
||||
} else {
|
||||
// log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---"); // Akarin
|
||||
}
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
log.log(Level.SEVERE, "------------------------------");
|
||||
|
||||
if (restart) RestartCommand.restart();
|
||||
break;
|
||||
if ( isLongTimeout )
|
||||
{
|
||||
if (restart) {
|
||||
RestartCommand.restart();
|
||||
}
|
||||
break;
|
||||
} // Paper end
|
||||
}
|
||||
|
||||
try {
|
||||
sleep(9000); // Akarin
|
||||
sleep(1000); // Paper - Reduce check time to every second instead of every ten seconds, more consistent and allows for short timeout
|
||||
} catch (InterruptedException ex) {
|
||||
interrupt();
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spigotmc.AsyncCatcher;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(value = AsyncCatcher.class, remap = false)
|
||||
public class DesyncCatcher {
|
||||
@Shadow public static boolean enabled;
|
||||
|
||||
@Overwrite
|
||||
public static void catchOp(String reason) {
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spigotmc.AsyncCatcher;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
|
||||
@Mixin(value = AsyncCatcher.class, remap = false)
|
||||
public abstract class MixinAsyncCatcher {
|
||||
@Shadow public static boolean enabled;
|
||||
|
||||
@Overwrite
|
||||
public static void catchOp(String reason) {
|
||||
if (enabled) {
|
||||
if (Akari.isPrimaryThread()) return;
|
||||
|
||||
if (AkarinGlobalConfig.throwOnAsyncCaught) {
|
||||
throw new IllegalStateException("Asynchronous " + reason + "!");
|
||||
} else {
|
||||
Akari.logger.warn("Asynchronous " + reason + "!");
|
||||
Thread.dumpStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.server.BlockMinecartDetector;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = BlockMinecartDetector.class, remap = false)
|
||||
public abstract class MixinBlockMinecartDetector {
|
||||
@Inject(at = @At("HEAD"), method = "e", cancellable = true)
|
||||
private void e(World world, BlockPosition blockposition, IBlockData iblockdata, CallbackInfo ci) {
|
||||
if (iblockdata.getBlock() != (Object)this) ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.Chunk;
|
||||
|
||||
@Mixin(value = ChunkIOExecutor.class, remap = false)
|
||||
public class MixinChunkIOExecutor {
|
||||
public abstract class MixinChunkIOExecutor {
|
||||
@Shadow @Final static int BASE_THREADS;
|
||||
@Shadow @Mutable @Final static int PLAYERS_PER_THREAD;
|
||||
@Shadow @Final private static AsynchronousExecutor<?, Chunk, Runnable, RuntimeException> instance;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.ChunkSection;
|
||||
|
||||
@Mixin(value = ChunkSection.class, remap = false)
|
||||
public abstract class MixinChunkSection {
|
||||
@Shadow private int nonEmptyBlockCount;
|
||||
|
||||
@Overwrite // OBFHELPER: isEmpty
|
||||
public boolean a() {
|
||||
return AkarinGlobalConfig.sendLightOnlyChunkSection ? false : nonEmptyBlockCount == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.CommandAbstract;
|
||||
import net.minecraft.server.CommandBan;
|
||||
import net.minecraft.server.CommandException;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ExceptionUsage;
|
||||
import net.minecraft.server.GameProfileBanEntry;
|
||||
import net.minecraft.server.ICommand;
|
||||
import net.minecraft.server.ICommandListener;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = CommandBan.class, remap = false)
|
||||
public abstract class MixinCommandBan {
|
||||
@Overwrite
|
||||
public void execute(MinecraftServer server, ICommandListener sender, String[] args) throws CommandException {
|
||||
if (args.length >= 1 && args[0].length() > 1) {
|
||||
GameProfile profile = server.getUserCache().getProfile(args[0]);
|
||||
|
||||
if (profile == null) {
|
||||
throw new CommandException("commands.ban.failed", new Object[] {args[0]});
|
||||
} else {
|
||||
// Akarin start - use string
|
||||
boolean hasReason = true; // Akarin
|
||||
String message = null;
|
||||
if (args.length >= 2) {
|
||||
message = "";
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
message = message + args[i];
|
||||
}
|
||||
} else {
|
||||
hasReason = false; // Akarin
|
||||
message = Akari.EMPTY_STRING; // Akarin - modify message
|
||||
}
|
||||
// Akarin end
|
||||
|
||||
GameProfileBanEntry entry = new GameProfileBanEntry(profile, (Date) null, sender.getName(), (Date) null, message);
|
||||
|
||||
server.getPlayerList().getProfileBans().add(entry);
|
||||
EntityPlayer entityplayer = server.getPlayerList().getPlayer(args[0]);
|
||||
|
||||
if (entityplayer != null) {
|
||||
entityplayer.playerConnection.disconnect(hasReason ? message : AkarinGlobalConfig.messageBan);
|
||||
}
|
||||
|
||||
CommandAbstract.a(sender, (ICommand) this, "commands.ban.success", args[0]); // OBFHELPER: notifyCommandListener
|
||||
}
|
||||
} else {
|
||||
throw new ExceptionUsage("commands.ban.usage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.CommandAbstract;
|
||||
import net.minecraft.server.CommandBanIp;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ICommand;
|
||||
import net.minecraft.server.ICommandListener;
|
||||
import net.minecraft.server.IpBanEntry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = CommandBanIp.class, remap = false)
|
||||
public abstract class MixinCommandBanIp {
|
||||
@Overwrite // OBFHELPER: banIp
|
||||
protected void a(MinecraftServer server, ICommandListener sender, String args, @Nullable String banReason) {
|
||||
// Akarin start - modify message
|
||||
boolean hasReason = true;
|
||||
if (banReason == null) {
|
||||
banReason = Akari.EMPTY_STRING;
|
||||
hasReason = false;
|
||||
}
|
||||
// Akarin end
|
||||
IpBanEntry ipbanentry = new IpBanEntry(args, (Date) null, sender.getName(), (Date) null, banReason);
|
||||
|
||||
server.getPlayerList().getIPBans().add(ipbanentry);
|
||||
List<EntityPlayer> withIpPlayers = server.getPlayerList().b(args); // OBFHELPER: getPlayersMatchingAddress
|
||||
String[] banPlayerNames = new String[withIpPlayers.size()];
|
||||
|
||||
for (int i = 0; i < banPlayerNames.length; i++) {
|
||||
EntityPlayer each = withIpPlayers.get(i);
|
||||
banPlayerNames[i] = each.getName();
|
||||
each.playerConnection.disconnect(hasReason ? banReason : AkarinGlobalConfig.messageBanIp); // Akarin
|
||||
}
|
||||
|
||||
if (withIpPlayers.isEmpty()) {
|
||||
CommandAbstract.a(sender, (ICommand) this, "commands.banip.success", args); // OBFHELPER: notifyCommandListener
|
||||
} else {
|
||||
CommandAbstract.a(sender, (ICommand) this, "commands.banip.success.players", args, CommandAbstract.a(banPlayerNames)); // OBFHELPER: notifyCommandListener - joinNiceString
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.CommandAbstract;
|
||||
import net.minecraft.server.CommandException;
|
||||
import net.minecraft.server.CommandKick;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ExceptionPlayerNotFound;
|
||||
import net.minecraft.server.ExceptionUsage;
|
||||
import net.minecraft.server.ICommand;
|
||||
import net.minecraft.server.ICommandListener;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = CommandKick.class, remap = false)
|
||||
public abstract class MixinCommandKick {
|
||||
@Overwrite
|
||||
public void execute(MinecraftServer server, ICommandListener sender, String[] args) throws CommandException {
|
||||
if (args.length > 0 && args[0].length() > 1) {
|
||||
EntityPlayer target = server.getPlayerList().getPlayer(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
throw new ExceptionPlayerNotFound("commands.generic.player.notFound", args[0]);
|
||||
} else {
|
||||
if (args.length >= 2) {
|
||||
// Akarin start - use string
|
||||
String message = "";
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
message = message + args[i];
|
||||
}
|
||||
target.playerConnection.disconnect(message);
|
||||
CommandAbstract.a(sender, (ICommand) this, "commands.kick.success.reason", target.getName(), message); // OBFHELPER: notifyCommandListener
|
||||
// Akarin end
|
||||
} else {
|
||||
target.playerConnection.disconnect(AkarinGlobalConfig.messageKick); // Akarin
|
||||
CommandAbstract.a(sender, (ICommand) this, "commands.kick.success", target.getName()); // OBFHELPER: notifyCommandListener
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new ExceptionUsage("commands.kick.usage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,19 +7,40 @@ import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = CraftServer.class, remap = false)
|
||||
public class MixinCraftServer {
|
||||
public abstract class MixinCraftServer {
|
||||
@Shadow @Final @Mutable private String serverName;
|
||||
@Shadow @Final @Mutable private String serverVersion;
|
||||
@Shadow @Final protected MinecraftServer console;
|
||||
private boolean needApplyServerName = true;
|
||||
private boolean needApplyServerVersion = true;
|
||||
|
||||
@Overwrite
|
||||
public String getName() {
|
||||
// We cannot apply the name modification in <init> method,
|
||||
// cause the initializer will be added to the tail
|
||||
if (needApplyServerName) {
|
||||
serverName = "Akarin";
|
||||
serverName = AkarinGlobalConfig.serverBrandName.equals(Akari.EMPTY_STRING) ? "Akarin" : AkarinGlobalConfig.serverBrandName;
|
||||
needApplyServerName = false;
|
||||
}
|
||||
return serverName;
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public String getVersion() {
|
||||
if (needApplyServerVersion) {
|
||||
serverVersion = AkarinGlobalConfig.serverBrandName.equals(Akari.EMPTY_STRING) ? serverVersion : serverVersion.replace("Akarin", AkarinGlobalConfig.serverBrandName);
|
||||
needApplyServerVersion = false;
|
||||
}
|
||||
return serverVersion + " (MC: " + console.getVersion() + ")";
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean isPrimaryThread() {
|
||||
return Akari.isPrimaryThread();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.MobEffect;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
import net.minecraft.server.MobEffects;
|
||||
|
||||
@Mixin(value = EntityLiving.class, remap = false)
|
||||
public abstract class MixinEntityLiving {
|
||||
@Shadow public abstract boolean hasEffect(MobEffectList mobeffectlist);
|
||||
@Shadow @Nullable public abstract MobEffect getEffect(MobEffectList mobeffectlist);
|
||||
@Shadow protected abstract float ct();
|
||||
protected long lastJumpTime = 0L; // Dionysus - Backport ArrowDMG fix
|
||||
|
||||
@Overwrite
|
||||
protected void cu() {
|
||||
// Dionysus start - Backport ArrowDMG fix
|
||||
long time = System.nanoTime();
|
||||
boolean canCrit = true;
|
||||
if ((Object)this instanceof EntityPlayer) {
|
||||
canCrit = false;
|
||||
if (time - lastJumpTime > (long)(0.250e9)) {
|
||||
lastJumpTime = time;
|
||||
canCrit = true;
|
||||
}
|
||||
}
|
||||
// Dionysus end - Backport ArrowDMG fix
|
||||
((EntityLiving)(Object)this).motY = (double) ct();
|
||||
if (hasEffect(MobEffects.JUMP)) {
|
||||
((EntityLiving)(Object)this).motY += (double) ((float) (getEffect(MobEffects.JUMP).getAmplifier() + 1) * 0.1F);
|
||||
}
|
||||
|
||||
if (canCrit&&((EntityLiving)(Object)this).isSprinting()) {
|
||||
float f = ((EntityLiving)(Object)this).yaw * 0.017453292F;
|
||||
|
||||
((EntityLiving)(Object)this).motX -= (double) (MathHelper.sin(f) * 0.2F);
|
||||
((EntityLiving)(Object)this).motZ += (double) (MathHelper.cos(f) * 0.2F);
|
||||
}
|
||||
|
||||
((EntityLiving)(Object)this).impulse = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.destroystokyo.paper.PaperConfig;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.FileIOThread;
|
||||
import net.minecraft.server.IAsyncChunkSaver;
|
||||
|
||||
@Mixin(value = FileIOThread.class, remap = false)
|
||||
public abstract class MixinFileIOThread {
|
||||
private final Executor executor = Executors.newFixedThreadPool(AkarinGlobalConfig.fileIOThreads, new ThreadFactoryBuilder().setNameFormat("Akarin File IO Thread - %1$d").setPriority(1).build());
|
||||
private final AtomicInteger queuedChunkCounter = new AtomicInteger(0);
|
||||
|
||||
@Shadow(aliases = "e") private volatile boolean isAwaitFinish;
|
||||
|
||||
@Overwrite // OBFHELPER: saveChunk
|
||||
public void a(IAsyncChunkSaver iasyncchunksaver) {
|
||||
queuedChunkCounter.incrementAndGet();
|
||||
executor.execute(() -> writeChunk(iasyncchunksaver));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a chunk, re-add to the queue if unsuccessful
|
||||
*/
|
||||
private void writeChunk(IAsyncChunkSaver iasyncchunksaver) {
|
||||
if (!iasyncchunksaver.a()) { // PAIL: WriteNextIO() -> Returns if the write was unsuccessful
|
||||
queuedChunkCounter.decrementAndGet();
|
||||
|
||||
if (PaperConfig.enableFileIOThreadSleep) {
|
||||
try {
|
||||
Thread.sleep(isAwaitFinish ? 0L : 2L);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
writeChunk(iasyncchunksaver);
|
||||
}
|
||||
}
|
||||
|
||||
@Overwrite // OBFHELPER: waitForFinish
|
||||
public void b() throws InterruptedException {
|
||||
isAwaitFinish = true;
|
||||
while (queuedChunkCounter.get() != 0) Thread.sleep(9L);
|
||||
isAwaitFinish = false;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,38 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
import org.spigotmc.AsyncCatcher;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import net.minecraft.server.MCUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = MCUtil.class, remap = false)
|
||||
public class MixinMCUtil {
|
||||
public abstract class MixinMCUtil {
|
||||
@Overwrite
|
||||
public static <T> T ensureMain(String reason, Supplier<T> run) {
|
||||
if (AsyncCatcher.enabled && !Akari.isPrimaryThread()) {
|
||||
new IllegalStateException("Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace();
|
||||
Waitable<T> wait = new Waitable<T>() {
|
||||
@Override
|
||||
protected T evaluate() {
|
||||
return run.get();
|
||||
}
|
||||
};
|
||||
MinecraftServer.getServer().processQueue.add(wait);
|
||||
try {
|
||||
return wait.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return run.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,18 @@ package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
@@ -16,9 +24,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import co.aikar.timings.MinecraftTimings;
|
||||
import io.akarin.api.Akari;
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.api.internal.Akari.AssignableFactory;
|
||||
import io.akarin.api.internal.mixin.IMixinWorldServer;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import io.akarin.server.core.AkarinSlackScheduler;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.CrashReport;
|
||||
import net.minecraft.server.CustomFunctionData;
|
||||
import net.minecraft.server.ITickable;
|
||||
@@ -32,12 +43,38 @@ import net.minecraft.server.TileEntityHopper;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = MinecraftServer.class, remap = false)
|
||||
public class MixinMinecraftServer {
|
||||
public abstract class MixinMinecraftServer {
|
||||
@Shadow @Final public Thread primaryThread;
|
||||
private boolean tickedPrimaryEntities;
|
||||
private int cachedWorldSize;
|
||||
|
||||
@Overwrite
|
||||
public String getServerModName() {
|
||||
return "Akarin";
|
||||
}
|
||||
|
||||
@Inject(method = "run()V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/MinecraftServer.aw()J",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void prerun(CallbackInfo info) {
|
||||
primaryThread.setPriority(AkarinGlobalConfig.primaryThreadPriority < Thread.NORM_PRIORITY ? Thread.NORM_PRIORITY :
|
||||
(AkarinGlobalConfig.primaryThreadPriority > Thread.MAX_PRIORITY ? 10 : AkarinGlobalConfig.primaryThreadPriority));
|
||||
Akari.resizeTickExecutors((cachedWorldSize = worlds.size()));
|
||||
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
//TileEntityHopper.skipHopperEvents = world.paperConfig.disableHopperMoveEvents || InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0;
|
||||
}
|
||||
AkarinSlackScheduler.get().boot();
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean isMainThread() {
|
||||
return Akari.isPrimaryThread();
|
||||
}
|
||||
|
||||
/*
|
||||
* Forcely disable snooper
|
||||
*/
|
||||
@@ -47,35 +84,81 @@ public class MixinMinecraftServer {
|
||||
@Overwrite
|
||||
public void b(MojangStatisticsGenerator generator) {}
|
||||
|
||||
@Inject(method = "run()V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/MinecraftServer.aw()J",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void prerun(CallbackInfo info) {
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
TileEntityHopper.skipHopperEvents = world.paperConfig.disableHopperMoveEvents || InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0;
|
||||
}
|
||||
/*
|
||||
* Parallel spawn chunks generation
|
||||
*/
|
||||
@Shadow public abstract boolean isRunning();
|
||||
@Shadow(aliases = "a_") protected abstract void output(String s, int i);
|
||||
@Shadow(aliases = "t") protected abstract void enablePluginsPostWorld();
|
||||
|
||||
AkarinSlackScheduler.boot();
|
||||
private void prepareChunks(WorldServer world, int index) {
|
||||
MinecraftServer.LOGGER.info("Preparing start region for level " + index + " (Seed: " + world.getSeed() + ")");
|
||||
BlockPosition spawnPos = world.getSpawn();
|
||||
long lastRecord = System.currentTimeMillis();
|
||||
|
||||
int preparedChunks = 0;
|
||||
short radius = world.paperConfig.keepLoadedRange;
|
||||
for (int skipX = -radius; skipX <= radius && isRunning(); skipX += 16) {
|
||||
for (int skipZ = -radius; skipZ <= radius && isRunning(); skipZ += 16) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (now - lastRecord > 1000L) {
|
||||
output("Preparing spawn area (level " + index + ") ", preparedChunks * 100 / 625);
|
||||
lastRecord = now;
|
||||
}
|
||||
|
||||
preparedChunks++;
|
||||
world.getChunkProviderServer().getChunkAt(spawnPos.getX() + skipX >> 4, spawnPos.getZ() + skipZ >> 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
protected void l() throws InterruptedException {
|
||||
ExecutorCompletionService<?> executor = new ExecutorCompletionService<>(Executors.newFixedThreadPool(worlds.size(), new AssignableFactory("Akarin Parallel Terrain Generation Thread - $")));
|
||||
|
||||
for (int index = 0; index < worlds.size(); index++) {
|
||||
WorldServer world = this.worlds.get(index);
|
||||
if (!world.getWorld().getKeepSpawnInMemory()) continue;
|
||||
|
||||
int fIndex = index;
|
||||
executor.submit(() -> prepareChunks(world, fIndex), null);
|
||||
}
|
||||
|
||||
for (WorldServer world : this.worlds) {
|
||||
if (world.getWorld().getKeepSpawnInMemory()) executor.take();
|
||||
}
|
||||
if (WorldLoadEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
||||
for (WorldServer world : this.worlds) {
|
||||
this.server.getPluginManager().callEvent(new WorldLoadEvent(world.getWorld()));
|
||||
}
|
||||
}
|
||||
|
||||
enablePluginsPostWorld();
|
||||
}
|
||||
|
||||
/*
|
||||
* Parallel world ticking
|
||||
*/
|
||||
@Shadow public CraftServer server;
|
||||
@Shadow @Mutable protected Queue<FutureTask<?>> j;
|
||||
@Shadow public Queue<Runnable> processQueue;
|
||||
@Shadow private int ticks;
|
||||
@Shadow public List<WorldServer> worlds;
|
||||
@Shadow private PlayerList v;
|
||||
@Shadow @Final private List<ITickable> o;
|
||||
@Shadow(aliases = "v") private PlayerList playerList;
|
||||
@Shadow(aliases = "o") @Final private List<ITickable> tickables;
|
||||
|
||||
@Shadow public PlayerList getPlayerList() { return null; }
|
||||
@Shadow public ServerConnection an() { return null; }
|
||||
@Shadow public CustomFunctionData aL() { return null; }
|
||||
@Shadow public abstract PlayerList getPlayerList();
|
||||
@Shadow(aliases = "an") public abstract ServerConnection serverConnection();
|
||||
@Shadow(aliases = "aL") public abstract CustomFunctionData functionManager();
|
||||
|
||||
private void tickEntities(WorldServer world) {
|
||||
private boolean tickEntities(WorldServer world) {
|
||||
try {
|
||||
world.timings.tickEntities.startTiming();
|
||||
world.tickEntities();
|
||||
world.timings.tickEntities.stopTiming();
|
||||
world.getTracker().updatePlayers();
|
||||
world.explosionDensityCache.clear(); // Paper - Optimize explosions
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport;
|
||||
try {
|
||||
@@ -86,11 +169,14 @@ public class MixinMinecraftServer {
|
||||
world.a(crashreport);
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void tickWorld(WorldServer world) {
|
||||
try {
|
||||
world.timings.doTick.startTiming();
|
||||
world.doTick();
|
||||
world.timings.doTick.stopTiming();
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport;
|
||||
try {
|
||||
@@ -104,7 +190,7 @@ public class MixinMinecraftServer {
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public void D() throws InterruptedException {
|
||||
public void D() throws InterruptedException, ExecutionException, CancellationException {
|
||||
Runnable runnable;
|
||||
Akari.callbackTiming.startTiming();
|
||||
while ((runnable = Akari.callbackQueue.poll()) != null) runnable.run();
|
||||
@@ -130,75 +216,108 @@ public class MixinMinecraftServer {
|
||||
ChunkIOExecutor.tick();
|
||||
MinecraftTimings.chunkIOTickTimer.stopTiming();
|
||||
|
||||
Akari.worldTiming.startTiming();
|
||||
if (AkarinGlobalConfig.legacyWorldTimings) {
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
worlds.get(i).timings.tickEntities.startTiming();
|
||||
worlds.get(i).timings.doTick.startTiming();
|
||||
}
|
||||
}
|
||||
Akari.silentTiming = true; // Disable timings
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
// Never tick one world concurrently!
|
||||
// TODO better treat world index
|
||||
for (int i = 1; i <= worlds.size(); ++i) {
|
||||
WorldServer world = worlds.get(i < worlds.size() ? i : 0);
|
||||
synchronized (world.tickLock) {
|
||||
if (cachedWorldSize != worlds.size()) Akari.resizeTickExecutors((cachedWorldSize = worlds.size()));
|
||||
switch (AkarinGlobalConfig.parallelMode) {
|
||||
case 1:
|
||||
case 2:
|
||||
default:
|
||||
// Never tick one world concurrently!
|
||||
for (int i = 0; i < cachedWorldSize; i++) {
|
||||
// Impl Note:
|
||||
// Entities ticking: index 1 -> ... -> 0 (parallel)
|
||||
// World ticking: index 0 -> ... (parallel)
|
||||
int interlace = i + 1;
|
||||
WorldServer entityWorld = worlds.get(interlace < cachedWorldSize ? interlace : 0);
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
synchronized (((IMixinWorldServer) entityWorld).lock()) {
|
||||
tickEntities(entityWorld);
|
||||
}
|
||||
}, null/*new TimingSignal(entityWorld, true)*/);
|
||||
|
||||
if (AkarinGlobalConfig.parallelMode != 1) {
|
||||
int fi = i;
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
WorldServer world = worlds.get(fi);
|
||||
synchronized (((IMixinWorldServer) world).lock()) {
|
||||
tickWorld(world);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (AkarinGlobalConfig.parallelMode == 1)
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
for (int i = 0; i < cachedWorldSize; i++) {
|
||||
WorldServer world = worlds.get(i);
|
||||
synchronized (((IMixinWorldServer) world).lock()) {
|
||||
tickWorld(world);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
for (int i = (AkarinGlobalConfig.parallelMode == 1 ? cachedWorldSize + 1 : cachedWorldSize * 2); i --> 0 ;) {
|
||||
Akari.STAGE_TICK.take();
|
||||
}
|
||||
|
||||
/* for (int i = (AkarinGlobalConfig.parallelMode == 1 ? cachedWorldSize : cachedWorldSize * 2); i --> 0 ;) {
|
||||
long startTiming = System.nanoTime();
|
||||
TimingSignal signal = Akari.STAGE_TICK.take().get();
|
||||
IMixinTimingHandler timing = (IMixinTimingHandler) (signal.isEntities ? signal.tickedWorld.timings.tickEntities : signal.tickedWorld.timings.doTick);
|
||||
timing.stopTiming(startTiming); // The overlap will be ignored
|
||||
} */
|
||||
|
||||
break;
|
||||
case 0:
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
for (int i = 1; i <= cachedWorldSize; ++i) {
|
||||
WorldServer world = worlds.get(i < cachedWorldSize ? i : 0);
|
||||
synchronized (((IMixinWorldServer) world).lock()) {
|
||||
tickEntities(world);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
Akari.STAGE_TICK.submit(() -> {
|
||||
for (int i = 0; i < cachedWorldSize; ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
synchronized (((IMixinWorldServer) world).lock()) {
|
||||
tickWorld(world);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
Akari.STAGE_TICK.take();
|
||||
Akari.STAGE_TICK.take();
|
||||
break;
|
||||
case -1:
|
||||
for (int i = 0; i < cachedWorldSize; ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
tickWorld(world);
|
||||
tickEntities(world);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
synchronized (world.tickLock) {
|
||||
tickWorld(world);
|
||||
}
|
||||
}
|
||||
|
||||
Akari.STAGE_TICK.take();
|
||||
Akari.silentTiming = false; // Enable timings
|
||||
Akari.worldTiming.stopTiming();
|
||||
if (AkarinGlobalConfig.legacyWorldTimings) {
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
worlds.get(i).timings.tickEntities.stopTiming();
|
||||
worlds.get(i).timings.doTick.startTiming();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Akari.callbackTiming.startTiming();
|
||||
while ((runnable = Akari.callbackQueue.poll()) != null) runnable.run();
|
||||
Akari.callbackTiming.stopTiming();
|
||||
|
||||
for (int i = 0; i < worlds.size(); ++i) {
|
||||
WorldServer world = worlds.get(i);
|
||||
tickConflictSync(world);
|
||||
|
||||
world.getTracker().updatePlayers();
|
||||
world.explosionDensityCache.clear(); // Paper - Optimize explosions
|
||||
}
|
||||
|
||||
MinecraftTimings.connectionTimer.startTiming();
|
||||
this.an().c();
|
||||
serverConnection().c();
|
||||
MinecraftTimings.connectionTimer.stopTiming();
|
||||
|
||||
MinecraftTimings.playerListTimer.startTiming();
|
||||
this.v.tick();
|
||||
MinecraftTimings.playerListTimer.stopTiming();
|
||||
Akari.callbackTiming.startTiming();
|
||||
while ((runnable = Akari.callbackQueue.poll()) != null) runnable.run();
|
||||
Akari.callbackTiming.stopTiming();
|
||||
|
||||
MinecraftTimings.commandFunctionsTimer.startTiming();
|
||||
this.aL().e();
|
||||
functionManager().e();
|
||||
MinecraftTimings.commandFunctionsTimer.stopTiming();
|
||||
|
||||
MinecraftTimings.tickablesTimer.startTiming();
|
||||
for (int i = 0; i < this.o.size(); ++i) {
|
||||
this.o.get(i).e();
|
||||
for (int i = 0; i < this.tickables.size(); ++i) {
|
||||
tickables.get(i).e();
|
||||
}
|
||||
MinecraftTimings.tickablesTimer.stopTiming();
|
||||
}
|
||||
|
||||
public void tickConflictSync(WorldServer world) {
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.ChunkCoordIntPair;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.PacketPlayOutMapChunk;
|
||||
import net.minecraft.server.PlayerChunk;
|
||||
import net.minecraft.server.PlayerChunkMap;
|
||||
import net.minecraft.server.WorldBorder;
|
||||
|
||||
@Mixin(value = PlayerChunk.class, remap = false)
|
||||
public abstract class MixinPlayerChunk {
|
||||
@Shadow @Final private static Logger a;
|
||||
@Shadow @Final private ChunkCoordIntPair location;
|
||||
@Shadow @Final private PlayerChunkMap playerChunkMap;
|
||||
@Shadow @Final public List<EntityPlayer> c;
|
||||
@Shadow public Chunk chunk;
|
||||
@Shadow private int dirtyCount;
|
||||
@Shadow private int h;
|
||||
@Shadow private long i;
|
||||
@Shadow private boolean done;
|
||||
|
||||
@Shadow public abstract void sendChunk(EntityPlayer entityplayer);
|
||||
|
||||
@Overwrite
|
||||
public void a(final EntityPlayer entityplayer) { // CraftBukkit - added final to argument
|
||||
if (this.c.contains(entityplayer)) {
|
||||
a.debug("Failed to add player. {} already is in chunk {}, {}", entityplayer, Integer.valueOf(this.location.x), Integer.valueOf(this.location.z));
|
||||
return;
|
||||
}
|
||||
if (AkarinGlobalConfig.noChunksPastWorldBorder) {
|
||||
WorldBorder worldborder = playerChunkMap.getWorld().getWorldBorder();
|
||||
int centerchunkx = ((int)worldborder.getCenterX()) >> 4;
|
||||
int centerchunkz = ((int)worldborder.getCenterZ()) >> 4;
|
||||
int sizechunks = ((int)worldborder.getSize()) >> 5;
|
||||
++sizechunks;
|
||||
if(location.x<centerchunkx - sizechunks||location.x>=centerchunkx + sizechunks||location.z<centerchunkz - sizechunks||location.z>=centerchunkz + sizechunks) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.c.isEmpty()) {
|
||||
this.i = this.playerChunkMap.getWorld().getTime();
|
||||
}
|
||||
|
||||
this.c.add(entityplayer);
|
||||
|
||||
if (this.done) {
|
||||
this.sendChunk(entityplayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean b() {
|
||||
if (this.done) {
|
||||
return true;
|
||||
}
|
||||
if (this.chunk == null) {
|
||||
return false;
|
||||
}
|
||||
if (!this.chunk.isReady()) {
|
||||
return false;
|
||||
}
|
||||
if (!this.chunk.world.chunkPacketBlockController.onChunkPacketCreate(this.chunk, '\uffff', false)) { // Paper - Anti-Xray - Load nearby chunks if necessary
|
||||
return false;
|
||||
}
|
||||
this.dirtyCount = 0;
|
||||
this.h = 0;
|
||||
this.done = true;
|
||||
if (c.isEmpty()) return true; // Akarin - Fixes MC-120780
|
||||
PacketPlayOutMapChunk packetplayoutmapchunk = new PacketPlayOutMapChunk(this.chunk, '\uffff');
|
||||
Iterator<EntityPlayer> iterator = this.c.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityPlayer entityplayer = iterator.next();
|
||||
|
||||
entityplayer.playerConnection.sendPacket(packetplayoutmapchunk);
|
||||
this.playerChunkMap.getWorld().getTracker().a(entityplayer, this.chunk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import co.aikar.timings.MinecraftTimings;
|
||||
import co.aikar.timings.Timing;
|
||||
import io.akarin.api.internal.Akari;
|
||||
import net.minecraft.server.CancelledPacketHandleException;
|
||||
import net.minecraft.server.IAsyncTaskHandler;
|
||||
import net.minecraft.server.Packet;
|
||||
import net.minecraft.server.PacketListener;
|
||||
import net.minecraft.server.PlayerConnectionUtils;
|
||||
|
||||
@Mixin(value = PlayerConnectionUtils.class, remap = false)
|
||||
public abstract class MixinPlayerConnectionUtils {
|
||||
@Overwrite
|
||||
public static <T extends PacketListener> void ensureMainThread(final Packet<T> packet, final T listener, IAsyncTaskHandler iasynctaskhandler) throws CancelledPacketHandleException {
|
||||
if (!iasynctaskhandler.isMainThread()) {
|
||||
Timing timing = MinecraftTimings.getPacketTiming(packet);
|
||||
// MinecraftServer#postToMainThread inlined thread check, no twice
|
||||
Akari.callbackQueue.add(() -> {
|
||||
try (Timing ignored = timing.startTiming()) {
|
||||
packet.a(listener);
|
||||
}
|
||||
});
|
||||
throw CancelledPacketHandleException.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.TileEntityLootable;
|
||||
|
||||
@Mixin(value = TileEntityLootable.class, remap = false)
|
||||
public abstract class MixinTileEntityLootable {
|
||||
@Inject(at = @At("HEAD"), method = "b(Lnet/minecraft/server/EntityHuman;Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfo;)V", cancellable = true)
|
||||
private void b(EntityHuman entityhuman, CallbackInfo ci) {
|
||||
if (entityhuman == null) ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.api.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
|
||||
@Mixin(targets = "co.aikar.timings.TimingHandler", remap = false)
|
||||
public class MixinTimingHandler {
|
||||
@Shadow @Final String name;
|
||||
@Shadow private boolean enabled;
|
||||
@Shadow private volatile long start;
|
||||
@Shadow private volatile int timingDepth;
|
||||
|
||||
@Overwrite
|
||||
public void stopTimingIfSync() {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
stopTiming(true); // Avoid twice thread check
|
||||
}
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public void stopTiming() {
|
||||
// Akarin start - avoid twice thread check
|
||||
stopTiming(false);
|
||||
}
|
||||
|
||||
@Shadow void addDiff(long diff) {}
|
||||
|
||||
public void stopTiming(boolean sync) {
|
||||
if (enabled && --timingDepth == 0 && start != 0) {
|
||||
if (Akari.silentTiming) { // It must be off-main thread now
|
||||
start = 0;
|
||||
return;
|
||||
} else {
|
||||
if (!sync && !Bukkit.isPrimaryThread()) {
|
||||
if (AkarinGlobalConfig.silentAsyncTimings) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "stopTiming called async for " + name);
|
||||
new Throwable().printStackTrace();
|
||||
}
|
||||
start = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
addDiff(System.nanoTime() - start);
|
||||
start = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,58 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.defaults.VersionCommand;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.api.Akari;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import io.akarin.api.internal.Akari;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.MCUtil;
|
||||
|
||||
@Mixin(value = VersionCommand.class, remap = false)
|
||||
public class MixinVersionCommand {
|
||||
@Shadow private static int getFromRepo(String repo, String hash) { return 0; }
|
||||
public abstract class MixinVersionCommand {
|
||||
@Overwrite
|
||||
private static int getFromRepo(String repo, String hash) {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/ver/1.12.2..." + hash).openConnection();
|
||||
connection.connect();
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return -2; // Unknown commit
|
||||
try (
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))
|
||||
) {
|
||||
JSONObject obj = (JSONObject) new JSONParser().parse(reader);
|
||||
String status = (String) obj.get("status");
|
||||
switch (status) {
|
||||
case "identical":
|
||||
return 0;
|
||||
case "behind":
|
||||
return ((Number) obj.get("behind_by")).intValue();
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
} catch (ParseException | NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match current version with repository and calculate the distance
|
||||
@@ -59,6 +96,9 @@ public class MixinVersionCommand {
|
||||
// This should be lying in 'obtainVersion' method, but bump for faster returning
|
||||
if (customVersion) return;
|
||||
|
||||
synchronized (versionWaiters) {
|
||||
versionWaiters.add(sender);
|
||||
}
|
||||
if (versionObtaining) return;
|
||||
// The volatile guarantees the safety between different threads.
|
||||
// Remembers that we are still on main thread now,
|
||||
@@ -70,7 +110,7 @@ public class MixinVersionCommand {
|
||||
|
||||
if (hasVersion) {
|
||||
long current = System.currentTimeMillis();
|
||||
if (current - lastCheckMillis > 7200000 /* 2 hours */) {
|
||||
if (current - lastCheckMillis > AkarinGlobalConfig.versionUpdateInterval) {
|
||||
lastCheckMillis = current;
|
||||
hasVersion = false;
|
||||
} else {
|
||||
@@ -100,11 +140,9 @@ public class MixinVersionCommand {
|
||||
// We post all things because a custom version is rare (expiring is not rare),
|
||||
// and we'd better post this task as early as we can, since it's a will (horrible destiny).
|
||||
MCUtil.scheduleAsyncTask(() -> {
|
||||
// This should be lying in 'sendVersion' method, but comes here for relax main thread
|
||||
versionWaiters.add(sender);
|
||||
sender.sendMessage("Checking version, please wait...");
|
||||
|
||||
String version = Bukkit.getVersion();
|
||||
String version = Akari.getServerVersion();
|
||||
if (version == null) {
|
||||
version = "Unique"; // Custom - > Unique
|
||||
customVersion = true;
|
||||
@@ -140,9 +178,11 @@ public class MixinVersionCommand {
|
||||
versionMessage = message;
|
||||
hasVersion = true;
|
||||
|
||||
for (CommandSender sender : versionWaiters) {
|
||||
sender.sendMessage(versionMessage);
|
||||
synchronized (versionWaiters) {
|
||||
for (CommandSender sender : versionWaiters) {
|
||||
sender.sendMessage(versionMessage);
|
||||
}
|
||||
versionWaiters.clear();
|
||||
}
|
||||
versionWaiters.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.AxisAlignedBB;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
/**
|
||||
* Fixes MC-103516(https://bugs.mojang.com/browse/MC-103516)
|
||||
*/
|
||||
@Mixin(value = World.class, remap = false)
|
||||
public abstract class MixinWorld {
|
||||
@Shadow public abstract List<Entity> getEntities(@Nullable Entity entity, AxisAlignedBB box);
|
||||
|
||||
/**
|
||||
* Returns true if there are no solid, live entities in the specified AxisAlignedBB, excluding the given entity
|
||||
*/
|
||||
@Overwrite
|
||||
public boolean a(AxisAlignedBB box, @Nullable Entity target) { // OBFHELPER: checkNoEntityCollision
|
||||
List<Entity> list = this.getEntities(null, box);
|
||||
|
||||
for (Entity each : list) {
|
||||
if (!each.dead && each.i && each != target && (target == null || !each.x(target))) { // OBFHELPER: preventEntitySpawning - isRidingSameEntity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.WorldBorder;
|
||||
|
||||
@Mixin(value = WorldBorder.class, remap = false)
|
||||
public abstract class MixinWorldBorder {
|
||||
@Shadow
|
||||
public abstract boolean isInBounds(BlockPosition blockposition);
|
||||
|
||||
@Overwrite
|
||||
public boolean isBlockInBounds(int chunkX, int chunkZ) {
|
||||
BlockPosition.MutableBlockPosition mutPos = new BlockPosition.MutableBlockPosition(); // Dionysus - avoid collisions with other threads
|
||||
mutPos.setValues(chunkX, 64, chunkZ);
|
||||
return isInBounds(mutPos);
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean isChunkInBounds(int chunkX, int chunkZ) {
|
||||
BlockPosition.MutableBlockPosition mutPos = new BlockPosition.MutableBlockPosition(); // Dionysus - avoid collisions with other threads // threads
|
||||
mutPos.setValues(((chunkX << 4) + 15), 64, (chunkZ << 4) + 15);
|
||||
return isInBounds(mutPos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.WorldManager;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = WorldManager.class, remap = false)
|
||||
public abstract class MixinWorldManager {
|
||||
@Shadow @Final private WorldServer world;
|
||||
|
||||
@Overwrite
|
||||
public void a(Entity entity) {
|
||||
this.world.getTracker().entriesLock.writeLock().lock(); // Akarin
|
||||
this.world.getTracker().track(entity);
|
||||
this.world.getTracker().entriesLock.writeLock().unlock(); // Akarin
|
||||
|
||||
if (entity instanceof EntityPlayer) {
|
||||
this.world.worldProvider.a((EntityPlayer) entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import io.akarin.api.internal.mixin.IMixinWorldServer;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = WorldServer.class, remap = false)
|
||||
public abstract class MixinWorldServer implements IMixinWorldServer {
|
||||
private final Object tickLock = new Object();
|
||||
|
||||
@Override
|
||||
public Object lock() {
|
||||
return tickLock;
|
||||
}
|
||||
|
||||
private final Random sharedRandom = new io.akarin.api.internal.utils.random.LightRandom() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean locked = false;
|
||||
@Override
|
||||
public synchronized void setSeed(long seed) {
|
||||
if (locked) {
|
||||
LogManager.getLogger().error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable());
|
||||
} else {
|
||||
super.setSeed(seed);
|
||||
locked = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Random rand() {
|
||||
return sharedRandom;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package io.akarin.server.mixin.core;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.ItemMonsterEgg;
|
||||
|
||||
@Mixin(value = ItemMonsterEgg.class, remap = false)
|
||||
public class MonsterEggGuardian {
|
||||
|
||||
@Redirect(method = "a", at = @At(
|
||||
value = "FIELD",
|
||||
target = "net/minecraft/server/Blocks.MOB_SPAWNER:Lnet/minecraft/server/Block;",
|
||||
opcode = Opcodes.GETSTATIC
|
||||
))
|
||||
private boolean configurable(Block target) {
|
||||
return target == Blocks.MOB_SPAWNER && AkarinGlobalConfig.allowSpawnerModify;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package io.akarin.server.mixin.cps;
|
||||
|
||||
import org.spigotmc.SlackActivityAccountant;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.ChunkProviderServer;
|
||||
import net.minecraft.server.IChunkLoader;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = ChunkProviderServer.class, remap = false)
|
||||
public abstract class MixinChunkProviderServer {
|
||||
@Shadow @Final public WorldServer world;
|
||||
@Shadow public Long2ObjectOpenHashMap<Chunk> chunks;
|
||||
|
||||
public void unload(Chunk chunk) {
|
||||
if (this.world.worldProvider.c(chunk.locX, chunk.locZ)) {
|
||||
// Akarin - avoid using the queue and simply check the unloaded flag during unloads
|
||||
// this.unloadQueue.add(Long.valueOf(ChunkCoordIntPair.a(chunk.locX, chunk.locZ)));
|
||||
chunk.setShouldUnload(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Shadow public abstract boolean unloadChunk(Chunk chunk, boolean save);
|
||||
@Shadow @Final private IChunkLoader chunkLoader;
|
||||
@Shadow @Final private static double UNLOAD_QUEUE_RESIZE_FACTOR;
|
||||
|
||||
@Overwrite
|
||||
public boolean unloadChunks() {
|
||||
if (!this.world.savingDisabled) {
|
||||
long now = System.currentTimeMillis();
|
||||
long unloadAfter = world.paperConfig.delayChunkUnloadsBy;
|
||||
SlackActivityAccountant activityAccountant = world.getMinecraftServer().slackActivityAccountant;
|
||||
activityAccountant.startActivity(0.5);
|
||||
|
||||
ObjectIterator<Entry<Chunk>> it = chunks.long2ObjectEntrySet().fastIterator();
|
||||
int remainingChunks = chunks.size();
|
||||
int targetSize = Math.min(remainingChunks - 100, (int) (remainingChunks * UNLOAD_QUEUE_RESIZE_FACTOR)); // Paper - Make more aggressive
|
||||
|
||||
while (it.hasNext()) {
|
||||
Entry<Chunk> entry = it.next();
|
||||
Chunk chunk = entry.getValue();
|
||||
|
||||
if (chunk != null && chunk.isUnloading()) {
|
||||
if (chunk.scheduledForUnload != null) {
|
||||
if (now - chunk.scheduledForUnload <= unloadAfter) continue;
|
||||
}
|
||||
|
||||
if (unloadChunk(chunk, true)) {
|
||||
it.remove();
|
||||
}
|
||||
chunk.setShouldUnload(false);
|
||||
chunk.scheduledForUnload = null;
|
||||
|
||||
if (--remainingChunks <= targetSize && activityAccountant.activityTimeIsExhausted()) break;
|
||||
}
|
||||
}
|
||||
activityAccountant.endActivity();
|
||||
this.chunkLoader.b(); // OBFHELPER: chunkTick
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Redirect(method = "unloadChunk", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "it/unimi/dsi/fastutil/longs/Long2ObjectOpenHashMap.remove(J)Ljava/lang/Object;"
|
||||
))
|
||||
private Object remove(Long2ObjectOpenHashMap<Chunk> chunks, long chunkHash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public String getName() {
|
||||
return "ServerChunkCache: " + chunks.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.akarin.server.mixin.cps;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = CraftWorld.class, remap = false)
|
||||
public abstract class MixinCraftWorld {
|
||||
@Shadow @Final private WorldServer world;
|
||||
|
||||
@Redirect(method = "processChunkGC()V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "java/util/Set.contains(Ljava/lang/Object;)Z",
|
||||
opcode = Opcodes.INVOKEINTERFACE
|
||||
))
|
||||
public boolean checkUnloading(Set<Long> set, Object chunkHash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Redirect(method = "regenerateChunk", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "java/util/Set.remove(Ljava/lang/Object;)Z",
|
||||
opcode = Opcodes.INVOKEINTERFACE
|
||||
))
|
||||
public boolean regenChunk(Set<Long> set, Object chunkHash) {
|
||||
Chunk chunk = world.getChunkProviderServer().chunks.get(chunkHash);
|
||||
if (chunk != null) chunk.setShouldUnload(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package io.akarin.server.mixin.nsc;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import net.minecraft.server.PlayerConnection;
|
||||
|
||||
@Mixin(value = PlayerConnection.class, remap = false)
|
||||
public class MixinPlayerConnection {
|
||||
@Overwrite
|
||||
private long d() {
|
||||
return System.currentTimeMillis(); // nanoTime() / 1000000L
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spigotmc.SpigotConfig;
|
||||
@@ -17,41 +18,52 @@ import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import io.akarin.api.LocalAddress;
|
||||
import io.akarin.api.internal.LocalAddress;
|
||||
import io.akarin.server.core.AkarinGlobalConfig;
|
||||
import io.akarin.server.core.ChannelAdapter;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelException;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.ServerChannel;
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.minecraft.server.ChatComponentText;
|
||||
import net.minecraft.server.EnumProtocolDirection;
|
||||
import net.minecraft.server.HandshakeListener;
|
||||
import net.minecraft.server.LegacyPingHandler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.PacketDecoder;
|
||||
import net.minecraft.server.PacketEncoder;
|
||||
import net.minecraft.server.PacketPlayOutKickDisconnect;
|
||||
import net.minecraft.server.PacketPrepender;
|
||||
import net.minecraft.server.PacketSplitter;
|
||||
import net.minecraft.server.ServerConnection;
|
||||
|
||||
@Mixin(value = ServerConnection.class, remap = false)
|
||||
public class NonblockingServerConnection {
|
||||
public abstract class NonblockingServerConnection {
|
||||
private final static Logger logger = LogManager.getLogger("NSC");
|
||||
|
||||
/**
|
||||
* Contains all endpoints added to this NetworkSystem
|
||||
*/
|
||||
@Shadow @Mutable @Final private List<ChannelFuture> g;
|
||||
@Shadow(aliases = "g") @Mutable @Final private List<ChannelFuture> endPoints;
|
||||
/**
|
||||
* A list containing all NetworkManager instances of all endpoints
|
||||
*/
|
||||
@Shadow @Mutable @Final private List<NetworkManager> h;
|
||||
@Shadow(aliases = "h") @Mutable @Final private List<NetworkManager> networkManagers;
|
||||
|
||||
@Overwrite
|
||||
private void addPending() {} // just keep compatibility
|
||||
|
||||
@Shadow @Final private MinecraftServer f;
|
||||
@Shadow(aliases = "f") @Final private MinecraftServer server;
|
||||
|
||||
/**
|
||||
* Adds channels (endpoint) that listens on publicly accessible network ports
|
||||
@@ -65,7 +77,7 @@ public class NonblockingServerConnection {
|
||||
Class<? extends ServerChannel> channelClass;
|
||||
EventLoopGroup loopGroup;
|
||||
|
||||
if (Epoll.isAvailable() && this.f.af()) { // PAIL: MinecraftServer::useNativeTransport
|
||||
if (Epoll.isAvailable() && this.server.af()) { // OBFHELPER: MinecraftServer::useNativeTransport
|
||||
channelClass = EpollServerSocketChannel.class;
|
||||
loopGroup = ServerConnection.b.c();
|
||||
logger.info("Using epoll channel type");
|
||||
@@ -75,8 +87,27 @@ public class NonblockingServerConnection {
|
||||
logger.info("Using nio channel type");
|
||||
}
|
||||
|
||||
ServerBootstrap bootstrap = new ServerBootstrap().channel(channelClass).childHandler(ChannelAdapter.create(h)).group(loopGroup);
|
||||
synchronized (g) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap().channel(channelClass).childHandler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel channel) throws Exception {
|
||||
try {
|
||||
channel.config().setOption(ChannelOption.TCP_NODELAY, true);
|
||||
} catch (ChannelException ex) {
|
||||
;
|
||||
}
|
||||
channel.pipeline().addLast("timeout", new ReadTimeoutHandler(30))
|
||||
.addLast("legacy_query", new LegacyPingHandler(MinecraftServer.getServer().getServerConnection()))
|
||||
.addLast("splitter", new PacketSplitter()).addLast("decoder", new PacketDecoder(EnumProtocolDirection.SERVERBOUND))
|
||||
.addLast("prepender", new PacketPrepender()).addLast("encoder", new PacketEncoder(EnumProtocolDirection.CLIENTBOUND));
|
||||
|
||||
NetworkManager manager = new NetworkManager(EnumProtocolDirection.SERVERBOUND);
|
||||
networkManagers.add(manager);
|
||||
|
||||
channel.pipeline().addLast("packet_handler", manager);
|
||||
manager.setPacketListener(new HandshakeListener(MinecraftServer.getServer(), manager));
|
||||
}
|
||||
}).group(loopGroup);
|
||||
synchronized (endPoints) {
|
||||
data.addAll(Lists.transform(AkarinGlobalConfig.extraAddress, s -> {
|
||||
String[] info = s.split(":");
|
||||
try {
|
||||
@@ -87,19 +118,19 @@ public class NonblockingServerConnection {
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
data.forEach(address -> g.add(bootstrap.localAddress(address.host(), address.port()).bind().syncUninterruptibly())); // supports multi-port bind
|
||||
data.forEach(address -> endPoints.add(bootstrap.localAddress(address.host(), address.port()).bind().syncUninterruptibly())); // supports multi-port bind
|
||||
}
|
||||
}
|
||||
|
||||
@Shadow public volatile boolean d; // PAIL: neverTerminate
|
||||
@Shadow public volatile boolean d; // OBFHELPER: neverTerminate
|
||||
/**
|
||||
* Shuts down all open endpoints
|
||||
*/
|
||||
public void b() {
|
||||
this.d = false;
|
||||
try {
|
||||
synchronized (g) { // safe fixes
|
||||
for (ChannelFuture channel : g) channel.channel().close().sync();
|
||||
synchronized (endPoints) { // safe fixes
|
||||
for (ChannelFuture channel : endPoints) channel.channel().close().sync();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("Interrupted whilst closing channel");
|
||||
@@ -108,15 +139,15 @@ public class NonblockingServerConnection {
|
||||
|
||||
public void processPackets(NetworkManager manager) {
|
||||
try {
|
||||
manager.a(); // PAIL: NetworkManager::processReceivedPackets
|
||||
manager.a(); // OBFHELPER: NetworkManager::processReceivedPackets
|
||||
} catch (Exception ex) {
|
||||
logger.warn("Failed to handle packet for {}", new Object[] { manager.getSocketAddress(), ex });
|
||||
final ChatComponentText kick = new ChatComponentText("Internal server error");
|
||||
logger.warn("Failed to handle packet for {}", manager.getSocketAddress(), ex);
|
||||
final ChatComponentText message = new ChatComponentText("Internal server error");
|
||||
|
||||
manager.sendPacket(new PacketPlayOutKickDisconnect(kick), new GenericFutureListener<Future<? super Void>>() {
|
||||
manager.sendPacket(new PacketPlayOutKickDisconnect(message), new GenericFutureListener<Future<? super Void>>() {
|
||||
@Override
|
||||
public void operationComplete(Future<? super Void> future) throws Exception {
|
||||
manager.close(kick);
|
||||
manager.close(message);
|
||||
}
|
||||
}, new GenericFutureListener[0]);
|
||||
manager.stopReading();
|
||||
@@ -128,16 +159,16 @@ public class NonblockingServerConnection {
|
||||
*/
|
||||
@Overwrite
|
||||
public void c() throws InterruptedException {
|
||||
synchronized (h) {
|
||||
synchronized (networkManagers) {
|
||||
// Spigot - This prevents players from 'gaming' the server, and strategically relogging to increase their position in the tick order
|
||||
if (SpigotConfig.playerShuffle > 0 && MinecraftServer.currentTick % SpigotConfig.playerShuffle == 0) {
|
||||
Collections.shuffle(h);
|
||||
Collections.shuffle(networkManagers);
|
||||
}
|
||||
|
||||
Iterator<NetworkManager> it = h.iterator();
|
||||
Iterator<NetworkManager> it = networkManagers.iterator();
|
||||
while (it.hasNext()) {
|
||||
NetworkManager manager = it.next();
|
||||
if (manager.h()) continue; // PAIL: NetworkManager::hasNoChannel
|
||||
if (manager.h()) continue; // OBFHELPER: NetworkManager::hasNoChannel
|
||||
|
||||
if (manager.isConnected()) {
|
||||
processPackets(manager);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package io.akarin.server.mixin.nsc;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import io.akarin.api.CheckedConcurrentLinkedQueue;
|
||||
import com.googlecode.concurentlocks.ReentrantReadWriteUpdateLock;
|
||||
|
||||
import io.akarin.api.internal.utils.CheckedConcurrentLinkedQueue;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
@@ -18,26 +18,27 @@ import net.minecraft.server.Packet;
|
||||
import net.minecraft.server.PacketPlayOutMapChunk;
|
||||
|
||||
@Mixin(value = NetworkManager.class, remap = false)
|
||||
public class OptimisticNetworkManager {
|
||||
public abstract class OptimisticNetworkManager {
|
||||
@Shadow public Channel channel;
|
||||
@Shadow @Final private Queue<NetworkManager.QueuedPacket> i;
|
||||
@Shadow @Final private ReentrantReadWriteLock j;
|
||||
@Shadow(aliases = "i") @Final private Queue<NetworkManager.QueuedPacket> packets;
|
||||
@Shadow(aliases = "j") @Final private ReentrantReadWriteUpdateLock queueLock;
|
||||
|
||||
@Shadow private Queue<NetworkManager.QueuedPacket> getPacketQueue() { return null; }
|
||||
@Shadow private void dispatchPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>>[] genericFutureListeners) {}
|
||||
@Shadow public abstract Queue<NetworkManager.QueuedPacket> getPacketQueue();
|
||||
@Shadow public abstract void dispatchPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>>[] genericFutureListeners);
|
||||
|
||||
private static final QueuedPacket SIGNAL_PACKET = new QueuedPacket(null, null);
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final QueuedPacket SIGNAL_PACKET = new QueuedPacket(null);
|
||||
|
||||
@Overwrite
|
||||
@Overwrite // OBFHELPER: trySendQueue
|
||||
private boolean m() {
|
||||
if (this.channel != null && this.channel.isOpen()) {
|
||||
if (this.i.isEmpty()) { // return if the packet queue is empty so that the write lock by Anti-Xray doesn't affect the vanilla performance at all
|
||||
if (this.packets.isEmpty()) { // return if the packet queue is empty so that the write lock by Anti-Xray doesn't affect the vanilla performance at all
|
||||
return true;
|
||||
}
|
||||
|
||||
this.j.readLock().lock();
|
||||
this.queueLock.updateLock().lock();
|
||||
try {
|
||||
while (!this.i.isEmpty()) {
|
||||
while (!this.packets.isEmpty()) {
|
||||
NetworkManager.QueuedPacket packet = ((CheckedConcurrentLinkedQueue<QueuedPacket>) getPacketQueue()).poll(item -> {
|
||||
return item.getPacket() instanceof PacketPlayOutMapChunk && !((PacketPlayOutMapChunk) item.getPacket()).isReady();
|
||||
}, SIGNAL_PACKET);
|
||||
@@ -51,7 +52,7 @@ public class OptimisticNetworkManager {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.j.readLock().unlock();
|
||||
this.queueLock.updateLock().unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.BlockChest;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.EnumDirection;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = BlockChest.class, remap = false)
|
||||
public abstract class MixinBlockChest extends Block {
|
||||
protected MixinBlockChest(Material material) {
|
||||
super(material);
|
||||
}
|
||||
@Shadow public abstract IBlockData e(World world, BlockPosition blockposition, IBlockData iblockdata);
|
||||
@Overwrite
|
||||
public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
||||
//((BlockChest)(Object)this).e(world, blockposition, iblockdata);
|
||||
e(world, blockposition, iblockdata);
|
||||
Iterator<EnumDirection> iterator = EnumDirection.EnumDirectionLimit.HORIZONTAL.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EnumDirection enumdirection = iterator.next();
|
||||
BlockPosition blockposition1 = blockposition.shift(enumdirection);
|
||||
// NeonPaper start - Dont load chunks for chests
|
||||
final IBlockData iblockdata1 = world.isLoaded(blockposition1) ? world.getType(blockposition1) : null;
|
||||
if (iblockdata1 == null) {
|
||||
continue;
|
||||
}
|
||||
// NeonPaper end
|
||||
|
||||
if (iblockdata1.getBlock() == this) {
|
||||
//((BlockChest)(Object)this).e(world, blockposition1, iblockdata1);
|
||||
e(world, blockposition1, iblockdata1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import net.minecraft.server.BlockFluids;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.BlockStationary;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = BlockStationary.class, remap = false)
|
||||
public abstract class MixinBlockStationary extends BlockFluids {
|
||||
protected MixinBlockStationary(Material material) {
|
||||
super(material);
|
||||
}
|
||||
@Overwrite
|
||||
private boolean d(World world, BlockPosition blockposition) {
|
||||
if (blockposition.getY() >= 0 && blockposition.getY() < 256) {
|
||||
IBlockData blockData = world.getTypeIfLoaded(blockposition);
|
||||
|
||||
if (blockData != null) {
|
||||
return blockData.getMaterial().isBurnable();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.Container;
|
||||
import net.minecraft.server.ContainerHorse;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityHorseAbstract;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.IInventory;
|
||||
|
||||
@Mixin(value = ContainerHorse.class, remap = false)
|
||||
public abstract class MixinContainerHorse extends Container {
|
||||
@Shadow private IInventory a;
|
||||
@Shadow private EntityHorseAbstract f;
|
||||
|
||||
@Overwrite
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
return this.a.a(entityhuman) && this.f.isAlive() && this.f.valid && this.f.g((Entity) entityhuman) < 8.0F; // NeonPaper! - Fix MC-161754
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.DataBits;
|
||||
|
||||
@Mixin(value = DataBits.class, remap = false)
|
||||
public abstract class MixinDataBits {
|
||||
@Shadow @Final private long[] a;
|
||||
@Shadow @Final private int b;
|
||||
@Shadow @Final private long c;
|
||||
|
||||
@Overwrite
|
||||
public void a(int i, int j) {
|
||||
int k = i * this.b;
|
||||
int l = k >> 6;
|
||||
int i1 = (i + 1) * this.b - 1 >> 6;
|
||||
int j1 = k ^ l << 6;
|
||||
|
||||
this.a[l] = this.a[l] & ~(this.c << j1) | ((long) j & this.c) << j1;
|
||||
if (l != i1) {
|
||||
int k1 = 64 - j1;
|
||||
int l1 = this.b - k1;
|
||||
|
||||
this.a[i1] = this.a[i1] >>> l1 << l1 | ((long) j & this.c) >> k1;
|
||||
}
|
||||
|
||||
}
|
||||
@Overwrite
|
||||
public int a(int i) {
|
||||
int j = i * this.b;
|
||||
int k = j >> 6;
|
||||
int l = (i + 1) * this.b - 1 >> 6;
|
||||
int i1 = j ^ k << 6;
|
||||
|
||||
if (k == l) {
|
||||
return (int) (this.a[k] >>> i1 & this.c);
|
||||
} else {
|
||||
int j1 = 64 - i1;
|
||||
|
||||
return (int) ((this.a[k] >>> i1 | this.a[l] << j1) & this.c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import net.minecraft.server.AxisAlignedBB;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = Entity.class, remap = false)
|
||||
public abstract class MixinEntity {
|
||||
@Shadow public World world;
|
||||
@Shadow public abstract AxisAlignedBB getBoundingBox();
|
||||
|
||||
@Shadow public boolean noclip;
|
||||
@Shadow public float R;
|
||||
@Shadow public double locX;
|
||||
@Shadow public double locZ;
|
||||
@Shadow public abstract boolean x(Entity entity);
|
||||
@Shadow public abstract boolean isVehicle();
|
||||
@Shadow public abstract void f(double d0, double d1, double d2);
|
||||
|
||||
private boolean isInLava;
|
||||
private int lastLavaCheck = Integer.MIN_VALUE;
|
||||
|
||||
@Overwrite // OBFHELPER: isInLava
|
||||
public boolean au() {
|
||||
/*
|
||||
* This originally comes from Migot (https://github.com/Poweruser/Migot/commit/cafbf1707107d2a3aa6232879f305975bb1f0285)
|
||||
* Thanks @Poweruser
|
||||
*/
|
||||
int currentTick = MinecraftServer.currentTick;
|
||||
if (this.lastLavaCheck != currentTick) {
|
||||
this.lastLavaCheck = currentTick;
|
||||
this.isInLava = this.world.a(this.getBoundingBox().grow(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), Material.LAVA);
|
||||
}
|
||||
return this.isInLava;
|
||||
}
|
||||
@Overwrite
|
||||
public void collide(Entity entity) {
|
||||
if (entity.noclip || this.noclip || this.x(entity)) return; // NeonPaper - Test this earlier
|
||||
double d0 = entity.locX - this.locX;
|
||||
double d1 = entity.locZ - this.locZ;
|
||||
double d2 = MathHelper.a(d0, d1);
|
||||
|
||||
if (d2 >= 0.009999999776482582D) {
|
||||
d2 = (double) MathHelper.sqrt(d2);
|
||||
d0 /= d2;
|
||||
d1 /= d2;
|
||||
double d3 = 1.0D / d2;
|
||||
|
||||
if (d3 > 1.0D) {
|
||||
d3 = 1.0D;
|
||||
}
|
||||
|
||||
d0 *= d3;
|
||||
d1 *= d3;
|
||||
d0 *= 0.05000000074505806D;
|
||||
d1 *= 0.05000000074505806D;
|
||||
d0 *= (double) (1.0F - this.R);
|
||||
d1 *= (double) (1.0F - this.R);
|
||||
if (!this.isVehicle()) {
|
||||
this.f(-d0, 0.0D, -d1);
|
||||
}
|
||||
|
||||
if (!entity.isVehicle()) {
|
||||
entity.f(d0, 0.0D, d1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,20 +42,21 @@ import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = EntityHorseAbstract.class, remap = false)
|
||||
public abstract class MixinEntityHorseAbstract extends Entity {
|
||||
@Shadow @Final private static DataWatcherObject<Optional<UUID>> bJ;
|
||||
@Shadow(aliases = "bJ") @Final private static DataWatcherObject<Optional<UUID>> OWNER_UNIQUE_ID;
|
||||
|
||||
@Nullable private Optional<UUID> cachedOwnerId;
|
||||
|
||||
@Nullable
|
||||
@Overwrite
|
||||
@Nullable public UUID getOwnerUUID() {
|
||||
if (cachedOwnerId == null) cachedOwnerId = datawatcher.get(bJ);
|
||||
public UUID getOwnerUUID() {
|
||||
if (cachedOwnerId == null) cachedOwnerId = datawatcher.get(OWNER_UNIQUE_ID);
|
||||
return cachedOwnerId.orNull();
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public void setOwnerUUID(@Nullable UUID uuid) {
|
||||
cachedOwnerId = Optional.fromNullable(uuid);
|
||||
datawatcher.set(bJ, cachedOwnerId);
|
||||
datawatcher.set(OWNER_UNIQUE_ID, cachedOwnerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.EntityCow;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.EntityItem;
|
||||
import net.minecraft.server.EntityMushroomCow;
|
||||
import net.minecraft.server.EnumHand;
|
||||
import net.minecraft.server.EnumParticle;
|
||||
import net.minecraft.server.ItemStack;
|
||||
import net.minecraft.server.Items;
|
||||
import net.minecraft.server.SoundEffects;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = EntityMushroomCow.class, remap = false)
|
||||
public abstract class MixinEntityMushroomCow extends EntityCow {
|
||||
|
||||
public MixinEntityMushroomCow(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
|
||||
ItemStack itemstack = entityhuman.b(enumhand);
|
||||
|
||||
if (itemstack.getItem() == Items.BOWL && this.getAge() >= 0 && !entityhuman.abilities.canInstantlyBuild) {
|
||||
itemstack.subtract(1);
|
||||
if (itemstack.isEmpty()) {
|
||||
entityhuman.a(enumhand, new ItemStack(Items.MUSHROOM_STEW));
|
||||
} else if (!entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_STEW))) {
|
||||
entityhuman.drop(new ItemStack(Items.MUSHROOM_STEW), false);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (itemstack.getItem() == Items.SHEARS && this.getAge() >= 0) {
|
||||
if (this.dead) return false; // Reaper - Fix cow dupe
|
||||
// CraftBukkit start
|
||||
PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity());
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
// CraftBukkit end
|
||||
this.die();
|
||||
this.world.addParticle(EnumParticle.EXPLOSION_LARGE, this.locX, this.locY + (double) (this.length / 2.0F), this.locZ, 0.0D, 0.0D, 0.0D, new int[0]);
|
||||
if (!this.world.isClientSide) {
|
||||
EntityCow entitycow = new EntityCow(this.world);
|
||||
|
||||
entitycow.setPositionRotation(this.locX, this.locY, this.locZ, this.yaw, this.pitch);
|
||||
entitycow.setHealth(this.getHealth());
|
||||
entitycow.aN = this.aN;
|
||||
if (this.hasCustomName()) {
|
||||
entitycow.setCustomName(this.getCustomName());
|
||||
}
|
||||
|
||||
this.world.addEntity(entitycow);
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
this.world.addEntity(new EntityItem(this.world, this.locX, this.locY + (double) this.length, this.locZ, new ItemStack(Blocks.RED_MUSHROOM)));
|
||||
}
|
||||
|
||||
itemstack.damage(1, entityhuman);
|
||||
this.a(SoundEffects.ei, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return super.a(entityhuman, enumhand);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,8 +46,9 @@ public abstract class MixinEntityTameableAnimal extends Entity {
|
||||
|
||||
@Nullable private Optional<UUID> cachedOwnerId;
|
||||
|
||||
@Nullable
|
||||
@Overwrite
|
||||
@Nullable public UUID getOwnerUUID() {
|
||||
public UUID getOwnerUUID() {
|
||||
if (cachedOwnerId == null) cachedOwnerId = datawatcher.get(by);
|
||||
return cachedOwnerId.orNull();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import net.minecraft.server.AxisAlignedBB;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.ChunkSection;
|
||||
import net.minecraft.server.DamageSource;
|
||||
import net.minecraft.server.EnchantmentProtection;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityFallingBlock;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityTNTPrimed;
|
||||
import net.minecraft.server.EnumParticle;
|
||||
import net.minecraft.server.Explosion;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.SoundCategory;
|
||||
import net.minecraft.server.SoundEffects;
|
||||
import net.minecraft.server.Vec3D;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.IEntitySelector;
|
||||
|
||||
@Mixin(value = Explosion.class, remap = false)
|
||||
public abstract class MixinExplosion {
|
||||
@Shadow private boolean a;
|
||||
@Shadow private boolean b;
|
||||
@Shadow private Random c = new Random();
|
||||
@Shadow private World world;
|
||||
@Shadow private double posX;
|
||||
@Shadow private double posY;
|
||||
@Shadow private double posZ;
|
||||
@Shadow public Entity source;
|
||||
@Shadow private float size;
|
||||
@Shadow private Map<EntityHuman, Vec3D> k;
|
||||
@Shadow public boolean wasCanceled = false; // CraftBukkit - add field
|
||||
@Shadow private List<BlockPosition> blocks;
|
||||
private final BlockPosition.MutableBlockPosition cachedPos = new BlockPosition.MutableBlockPosition();
|
||||
private int prevChunkX = Integer.MIN_VALUE;
|
||||
private int prevChunkZ = Integer.MIN_VALUE;
|
||||
private Chunk prevChunk;
|
||||
private static final com.google.common.base.Predicate<Entity> hitPredicate = entity -> IEntitySelector.d.apply(entity) && !entity.dead; // Dionysus - Paper - don't hit dead entities
|
||||
|
||||
@Overwrite
|
||||
public void a() {
|
||||
// CraftBukkit start
|
||||
if (this.size < 0.1F) {
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
// Dionysus start - optimize memory usage from explosions
|
||||
// CaffeineMC optimized raytracing loop
|
||||
// @author JellySquid
|
||||
// @author nopjmp
|
||||
// https://github.com/CaffeineMC/lithium-fabric
|
||||
// Using integer encoding for the block positions provides a massive speedup and prevents us from needing to
|
||||
// allocate a block position for every step we make along each ray, eliminating essentially all the memory
|
||||
// allocations of this function. The overhead of packing block positions into integer format is negligible
|
||||
// compared to a memory allocation and associated overhead of hashing real objects in a set.
|
||||
final LongOpenHashSet touched = new LongOpenHashSet(0);
|
||||
final Random random = this.world.random;
|
||||
for (int rayX = 0; rayX < 16; ++rayX) {
|
||||
boolean xPlane = rayX == 0 || rayX == 15;
|
||||
double vecX = (((float) rayX / 15.0F) * 2.0F) - 1.0F;
|
||||
|
||||
for (int rayY = 0; rayY < 16; ++rayY) {
|
||||
boolean yPlane = rayY == 0 || rayY == 15;
|
||||
double vecY = (((float) rayY / 15.0F) * 2.0F) - 1.0F;
|
||||
|
||||
for (int rayZ = 0; rayZ < 16; ++rayZ) {
|
||||
boolean zPlane = rayZ == 0 || rayZ == 15;
|
||||
|
||||
// We only fire rays from the surface of our origin volume
|
||||
if (xPlane || yPlane || zPlane) {
|
||||
double vecZ = (((float) rayZ / 15.0F) * 2.0F) - 1.0F;
|
||||
|
||||
this.performRayCast(random, vecX, vecY, vecZ, touched);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We can now iterate back over the set of positions we modified and re-build BlockPos objects from them
|
||||
// This will only allocate as many objects as there are in the set, where otherwise we would allocate them
|
||||
// each step of a every ray.
|
||||
((ArrayList<BlockPosition>)this.blocks).ensureCapacity(touched.size());
|
||||
for (Long longPos : touched) {
|
||||
this.blocks.add(BlockPosition.fromLong(longPos));
|
||||
}
|
||||
float f3 = this.size * 2.0F;
|
||||
|
||||
int i = MathHelper.floor(this.posX - (double) f3 - 1.0D);
|
||||
int j = MathHelper.floor(this.posX + (double) f3 + 1.0D);
|
||||
int l = MathHelper.floor(this.posY - (double) f3 - 1.0D);
|
||||
int i1 = MathHelper.floor(this.posY + (double) f3 + 1.0D);
|
||||
int j1 = MathHelper.floor(this.posZ - (double) f3 - 1.0D);
|
||||
int k1 = MathHelper.floor(this.posZ + (double) f3 + 1.0D);
|
||||
// Paper start - Fix lag from explosions processing dead entities
|
||||
List<Entity> list = this.world.getEntities(this.source, new AxisAlignedBB(i, l, j1, j, i1, k1), hitPredicate);
|
||||
// Paper end
|
||||
Vec3D vec3d = new Vec3D(this.posX, this.posY, this.posZ);
|
||||
|
||||
for (Entity entity : list) {
|
||||
|
||||
if (!entity.bB()) {
|
||||
double d7 = entity.e(this.posX, this.posY, this.posZ) / (double) f3;
|
||||
|
||||
if (d7 <= 1.0D) {
|
||||
double d8 = entity.locX - this.posX;
|
||||
double d9 = entity.locY + (double) entity.getHeadHeight() - this.posY;
|
||||
double d10 = entity.locZ - this.posZ;
|
||||
double d11 = MathHelper.sqrt(d8 * d8 + d9 * d9 + d10 * d10);
|
||||
|
||||
if (d11 != 0.0D) {
|
||||
d8 /= d11;
|
||||
d9 /= d11;
|
||||
d10 /= d11;
|
||||
double d12 = this.getBlockDensity(vec3d, entity.getBoundingBox()); // Paper - Optimize explosions
|
||||
double d13 = (1.0D - d7) * d12;
|
||||
|
||||
// CraftBukkit start
|
||||
// entity.damageEntity(DamageSource.explosion(this), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f3 + 1.0D)));
|
||||
CraftEventFactory.entityDamage = source;
|
||||
entity.forceExplosionKnockback = false;
|
||||
boolean wasDamaged = entity.damageEntity(DamageSource.explosion((Explosion)(Object)this), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f3 + 1.0D)));
|
||||
CraftEventFactory.entityDamage = null;
|
||||
if (!wasDamaged && !(entity instanceof EntityTNTPrimed || entity instanceof EntityFallingBlock) && !entity.forceExplosionKnockback) {
|
||||
continue;
|
||||
}
|
||||
// CraftBukkit end
|
||||
double d14 = d13;
|
||||
|
||||
if (entity instanceof EntityLiving) {
|
||||
d14 = entity instanceof EntityHuman && world.paperConfig.disableExplosionKnockback ? 0 : EnchantmentProtection.a((EntityLiving) entity, d13); // Paper - Disable explosion knockback
|
||||
}
|
||||
|
||||
entity.motX += d8 * d14;
|
||||
entity.motY += d9 * d14;
|
||||
entity.motZ += d10 * d14;
|
||||
if (entity instanceof EntityHuman) {
|
||||
EntityHuman entityhuman = (EntityHuman) entity;
|
||||
|
||||
if (!entityhuman.isSpectator() && (!entityhuman.z() && !world.paperConfig.disableExplosionKnockback || !entityhuman.abilities.isFlying)) { // Paper - Disable explosion knockback
|
||||
this.k.put(entityhuman, new Vec3D(d8 * d13, d9 * d13, d10 * d13));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void performRayCast(Random random, double vecX, double vecY, double vecZ, LongOpenHashSet touched) {
|
||||
double dist = Math.sqrt((vecX * vecX) + (vecY * vecY) + (vecZ * vecZ));
|
||||
|
||||
double normX = (vecX / dist) * 0.3D;
|
||||
double normY = (vecY / dist) * 0.3D;
|
||||
double normZ = (vecZ / dist) * 0.3D;
|
||||
|
||||
float strength = this.size * (0.7F + (random.nextFloat() * 0.6F));
|
||||
|
||||
double stepX = this.posX;
|
||||
double stepY = this.posY;
|
||||
double stepZ = this.posZ;
|
||||
|
||||
int prevX = Integer.MIN_VALUE;
|
||||
int prevY = Integer.MIN_VALUE;
|
||||
int prevZ = Integer.MIN_VALUE;
|
||||
|
||||
float prevResistance = 0.0F;
|
||||
|
||||
// Step through the ray until it is finally stopped
|
||||
while (strength > 0.0F) {
|
||||
int blockX = MathHelper.floor(stepX);
|
||||
int blockY = MathHelper.floor(stepY);
|
||||
int blockZ = MathHelper.floor(stepZ);
|
||||
|
||||
float resistance;
|
||||
|
||||
// Check whether or not we have actually moved into a new block this step. Due to how rays are stepped through,
|
||||
// over-sampling of the same block positions will occur. Changing this behaviour would introduce differences in
|
||||
// aliasing and sampling, which is unacceptable for our purposes. As a band-aid, we can simply re-use the
|
||||
// previous result and get a decent boost.
|
||||
if (prevX != blockX || prevY != blockY || prevZ != blockZ) {
|
||||
resistance = this.traverseBlock(strength, blockX, blockY, blockZ, touched);
|
||||
|
||||
prevX = blockX;
|
||||
prevY = blockY;
|
||||
prevZ = blockZ;
|
||||
|
||||
prevResistance = resistance;
|
||||
} else {
|
||||
resistance = prevResistance;
|
||||
}
|
||||
|
||||
strength -= resistance;
|
||||
// Apply a constant fall-off
|
||||
strength -= 0.22500001F;
|
||||
|
||||
stepX += normX;
|
||||
stepY += normY;
|
||||
stepZ += normZ;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called for every step made by a ray being cast by an explosion.
|
||||
*
|
||||
* @param strength The strength of the ray during this step
|
||||
* @param blockX The x-coordinate of the block the ray is inside of
|
||||
* @param blockY The y-coordinate of the block the ray is inside of
|
||||
* @param blockZ The z-coordinate of the block the ray is inside of
|
||||
* @return The resistance of the current block space to the ray
|
||||
*/
|
||||
private float traverseBlock(float strength, int blockX, int blockY, int blockZ, LongOpenHashSet touched) {
|
||||
cachedPos.c(blockX, blockY, blockZ);
|
||||
IBlockData iblockdata = this.world.getType(cachedPos);
|
||||
|
||||
// Early-exit if the y-coordinate is out of bounds.
|
||||
if (cachedPos.isInvalidYLocation()) {
|
||||
if (iblockdata.getMaterial() != Material.AIR) {
|
||||
float blastResistance = this.source != null ? this.source.a((Explosion)(Object)this, this.world, cachedPos, iblockdata) : iblockdata.getBlock().a((Entity) null);
|
||||
return (blastResistance + 0.3F) * 0.3F;
|
||||
}
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
|
||||
int chunkX = blockX >> 4;
|
||||
int chunkZ = blockZ >> 4;
|
||||
|
||||
// Avoid calling into the chunk manager as much as possible through managing chunks locally
|
||||
if (this.prevChunkX != chunkX || this.prevChunkZ != chunkZ) {
|
||||
this.prevChunk = this.world.getChunkAt(chunkX, chunkZ);
|
||||
|
||||
this.prevChunkX = chunkX;
|
||||
this.prevChunkZ = chunkZ;
|
||||
}
|
||||
|
||||
final Chunk chunk = this.prevChunk;
|
||||
|
||||
float totalResistance = 0.0F;
|
||||
Optional<Float> blastResistance = Optional.empty();
|
||||
|
||||
// If the chunk is missing or out of bounds, assume that it is air
|
||||
if (chunk != null) {
|
||||
// We operate directly on chunk sections to avoid interacting with BlockPos and to squeeze out as much
|
||||
// performance as possible here
|
||||
ChunkSection section = chunk.getSections()[blockY >> 4];
|
||||
|
||||
// If the section doesn't exist or it's empty, assume that the block is air
|
||||
if (section != null && !section.a()) {
|
||||
// Retrieve the block state from the chunk section directly to avoid associated overhead
|
||||
IBlockData blockState = section.getType(blockX & 15, blockY & 15, blockZ & 15);
|
||||
|
||||
// If the block state is air, it cannot have fluid or any kind of resistance, so just leave
|
||||
if (blockState.getBlock() != Blocks.AIR) {
|
||||
// Get the explosion resistance like vanilla
|
||||
blastResistance = Optional.of(this.source != null ? this.source.a((Explosion)(Object)this, this.world, cachedPos, iblockdata) : iblockdata.getBlock().a((Entity) null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate how much this block will resist an explosion's ray
|
||||
if (blastResistance.isPresent()) {
|
||||
totalResistance = (blastResistance.get() + 0.3F) * 0.3F;
|
||||
}
|
||||
|
||||
// Check if this ray is still strong enough to break blocks, and if so, add this position to the set
|
||||
// of positions to destroy
|
||||
float reducedStrength = strength - totalResistance;
|
||||
if (reducedStrength > 0.0F && (this.a || iblockdata.getMaterial() != Material.AIR)) {
|
||||
if ((this.source == null || this.source.a((Explosion)(Object)this, this.world, cachedPos, iblockdata, reducedStrength)) && cachedPos.getY() < 256 && cachedPos.getY() >= 0) {
|
||||
touched.add(cachedPos.asLong());
|
||||
}
|
||||
}
|
||||
|
||||
return totalResistance;
|
||||
}
|
||||
@Overwrite
|
||||
public void a(boolean flag) {
|
||||
this.world.a((EntityHuman) null, this.posX, this.posY, this.posZ, SoundEffects.bV, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.world.random.nextFloat() - this.world.random.nextFloat()) * 0.2F) * 0.7F);
|
||||
if (this.size >= 2.0F && this.b) {
|
||||
this.world.addParticle(EnumParticle.EXPLOSION_HUGE, this.posX, this.posY, this.posZ, 1.0D, 0.0D, 0.0D);
|
||||
} else {
|
||||
this.world.addParticle(EnumParticle.EXPLOSION_LARGE, this.posX, this.posY, this.posZ, 1.0D, 0.0D, 0.0D);
|
||||
}
|
||||
|
||||
Iterator<BlockPosition> iterator;
|
||||
BlockPosition blockposition;
|
||||
|
||||
if (this.b) {
|
||||
// CraftBukkit start
|
||||
org.bukkit.World bworld = this.world.getWorld();
|
||||
org.bukkit.entity.Entity explode = this.source == null ? null : this.source.getBukkitEntity();
|
||||
Location location = new Location(bworld, this.posX, this.posY, this.posZ);
|
||||
|
||||
List<org.bukkit.block.Block> blockList = Lists.newArrayList();
|
||||
for (int i1 = this.blocks.size() - 1; i1 >= 0; i1--) {
|
||||
BlockPosition cpos = (BlockPosition) this.blocks.get(i1);
|
||||
org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ());
|
||||
if (bblock.getType() != org.bukkit.Material.AIR) {
|
||||
blockList.add(bblock);
|
||||
}
|
||||
}
|
||||
|
||||
boolean cancelled;
|
||||
List<org.bukkit.block.Block> bukkitBlocks;
|
||||
float yield;
|
||||
|
||||
if (explode != null) {
|
||||
EntityExplodeEvent event = new EntityExplodeEvent(explode, location, blockList, 1.0F / this.size);
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
cancelled = event.isCancelled();
|
||||
bukkitBlocks = event.blockList();
|
||||
yield = event.getYield();
|
||||
} else {
|
||||
BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, 1.0F / this.size);
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
cancelled = event.isCancelled();
|
||||
bukkitBlocks = event.blockList();
|
||||
yield = event.getYield();
|
||||
}
|
||||
|
||||
this.blocks.clear();
|
||||
|
||||
((ArrayList<BlockPosition>)this.blocks).ensureCapacity(bukkitBlocks.size());
|
||||
for (org.bukkit.block.Block bblock : bukkitBlocks) {
|
||||
BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ());
|
||||
blocks.add(coords);
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
this.wasCanceled = true;
|
||||
return;
|
||||
}
|
||||
// CraftBukkit end
|
||||
iterator = this.blocks.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
blockposition = (BlockPosition) iterator.next();
|
||||
IBlockData iblockdata = this.world.getType(blockposition);
|
||||
Block block = iblockdata.getBlock();
|
||||
this.world.chunkPacketBlockController.updateNearbyBlocks(this.world, blockposition); // Paper - Anti-Xray
|
||||
|
||||
if (flag) {
|
||||
double d0 = (double) ((float) blockposition.getX() + this.world.random.nextFloat());
|
||||
double d1 = (double) ((float) blockposition.getY() + this.world.random.nextFloat());
|
||||
double d2 = (double) ((float) blockposition.getZ() + this.world.random.nextFloat());
|
||||
double d3 = d0 - this.posX;
|
||||
double d4 = d1 - this.posY;
|
||||
double d5 = d2 - this.posZ;
|
||||
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
|
||||
|
||||
d3 /= d6;
|
||||
d4 /= d6;
|
||||
d5 /= d6;
|
||||
double d7 = 0.5D / (d6 / (double) this.size + 0.1D);
|
||||
|
||||
d7 *= (double) (this.world.random.nextFloat() * this.world.random.nextFloat() + 0.3F);
|
||||
d3 *= d7;
|
||||
d4 *= d7;
|
||||
d5 *= d7;
|
||||
this.world.addParticle(EnumParticle.EXPLOSION_NORMAL, (d0 + this.posX) / 2.0D, (d1 + this.posY) / 2.0D, (d2 + this.posZ) / 2.0D, d3, d4, d5);
|
||||
this.world.addParticle(EnumParticle.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
if (iblockdata.getMaterial() != Material.AIR) {
|
||||
if (block.a((Explosion)(Object)this)) {
|
||||
// CraftBukkit - add yield
|
||||
block.dropNaturally(this.world, blockposition, this.world.getType(blockposition), yield, 0);
|
||||
}
|
||||
|
||||
this.world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 3);
|
||||
block.wasExploded(this.world, blockposition, (Explosion)(Object)this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.a) {
|
||||
iterator = this.blocks.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
blockposition = (BlockPosition) iterator.next();
|
||||
if (this.world.getType(blockposition).getMaterial() == Material.AIR && this.world.getType(blockposition.down()).b() && this.c.nextInt(3) == 0) {
|
||||
// CraftBukkit start - Ignition by explosion
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(this.world, blockposition.getX(), blockposition.getY(), blockposition.getZ(), (Explosion)(Object)this).isCancelled()) {
|
||||
this.world.setTypeUpdate(blockposition, Blocks.FIRE.getBlockData());
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Shadow protected abstract float getBlockDensity(Vec3D vec3d, AxisAlignedBB aabb);
|
||||
//private float getBlockDensity(Vec3D vec3d, AxisAlignedBB aabb) {
|
||||
//if (!this.world.paperConfig.optimizeExplosions) {
|
||||
// return this.world.a(vec3d, aabb);
|
||||
//}
|
||||
//CacheKey key = new CacheKey((Explosion)(Object)this, aabb);
|
||||
//return this.world.explosionDensityCache.computeIfAbsent(key, k1 -> this.world.a(vec3d, aabb));
|
||||
//}
|
||||
// Paper end
|
||||
// Dionysus end
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
|
||||
import net.minecraft.server.MathHelper;
|
||||
|
||||
@Mixin(value = MathHelper.class, remap = false)
|
||||
public abstract class MixinMathHelper {
|
||||
private static final int[] SINE_TABLE_INT = new int[16384 + 1];
|
||||
private static final float SINE_TABLE_MIDPOINT;
|
||||
@Overwrite
|
||||
public static float sin(float f) {
|
||||
return lookup((int) (f * 10430.38) & 0xFFFF);
|
||||
}
|
||||
@Overwrite
|
||||
public static float cos(float f) {
|
||||
return lookup((int) (f * 10430.38 + 16384.0) & 0xFFFF);
|
||||
}
|
||||
private static float lookup(int index) {
|
||||
if (index == 32768) {
|
||||
return SINE_TABLE_MIDPOINT;
|
||||
}
|
||||
int neg = (index & 0x8000) << 16;
|
||||
int mask = (index << 17) >> 31;
|
||||
int pos = (0x8001 & mask) + (index ^ mask);
|
||||
pos &= 0x7fff;
|
||||
return Float.intBitsToFloat(SINE_TABLE_INT[pos] ^ neg);
|
||||
}
|
||||
static {
|
||||
int i;
|
||||
|
||||
final float[] SINE_TABLE = new float[65536];
|
||||
for (i = 0; i < 65536; ++i) {
|
||||
SINE_TABLE[i] = (float) Math.sin((double) i * 3.141592653589793D * 2.0D / 65536.0D);
|
||||
}
|
||||
for (i = 0; i < SINE_TABLE_INT.length; i++) {
|
||||
SINE_TABLE_INT[i] = Float.floatToRawIntBits(SINE_TABLE[i]);
|
||||
}
|
||||
|
||||
SINE_TABLE_MIDPOINT = SINE_TABLE[SINE_TABLE.length / 2];
|
||||
for (i = 0; i < SINE_TABLE.length; i++) {
|
||||
float expected = SINE_TABLE[i];
|
||||
float value = lookup(i);
|
||||
|
||||
if (expected != value) {
|
||||
throw new IllegalArgumentException(String.format("LUT error at index %d (expected: %s, found: %s)", i, expected, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import com.destroystokyo.paper.exception.ServerInternalException;
|
||||
|
||||
import net.minecraft.server.IDataManager;
|
||||
import net.minecraft.server.MCUtil;
|
||||
import net.minecraft.server.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
import net.minecraft.server.PersistentBase;
|
||||
import net.minecraft.server.PersistentCollection;
|
||||
|
||||
@Mixin(value = PersistentCollection.class, remap = false)
|
||||
public abstract class MixinPersistentCollection {
|
||||
@Shadow(aliases = "b") @Final private IDataManager dataManager;
|
||||
|
||||
@Overwrite
|
||||
private void a(PersistentBase persistentbase) {
|
||||
if (this.dataManager == null) return;
|
||||
|
||||
File file = this.dataManager.getDataFile(persistentbase.id);
|
||||
if (file == null) return;
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.set("data", persistentbase.b(new NBTTagCompound()));
|
||||
|
||||
// Akarin start
|
||||
MCUtil.scheduleAsyncTask(() -> {
|
||||
try {
|
||||
FileOutputStream fileoutputstream = new FileOutputStream(file);
|
||||
|
||||
NBTCompressedStreamTools.a(nbttagcompound, fileoutputstream);
|
||||
fileoutputstream.close();
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
ServerInternalException.reportInternalException(exception); // Paper
|
||||
}
|
||||
});
|
||||
// Akarin end
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.Overwrite;
|
||||
import net.minecraft.server.TileEntityEnchantTable;
|
||||
|
||||
@Mixin(value = TileEntityEnchantTable.class, remap = false)
|
||||
public class MixinTileEntityEnchantTable {
|
||||
public abstract class MixinTileEntityEnchantTable {
|
||||
@Overwrite
|
||||
public void e() {} // No tickable
|
||||
}
|
||||
|
||||
@@ -0,0 +1,510 @@
|
||||
package io.akarin.server.mixin.optimization;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.server.BaseBlockPosition;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.BlockDiodeAbstract;
|
||||
import net.minecraft.server.BlockObserver;
|
||||
import net.minecraft.server.BlockPiston;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.BlockRedstoneComparator;
|
||||
import net.minecraft.server.BlockRedstoneTorch;
|
||||
import net.minecraft.server.BlockRedstoneWire;
|
||||
import net.minecraft.server.BlockRepeater;
|
||||
import net.minecraft.server.Blocks;
|
||||
import net.minecraft.server.EnumDirection;
|
||||
import net.minecraft.server.IBlockAccess;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.Material;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = BlockRedstoneWire.class, remap = false)
|
||||
public abstract class PandaRedstoneWire extends Block {
|
||||
|
||||
protected PandaRedstoneWire(Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/** Positions that need to be turned off **/
|
||||
private List<BlockPosition> turnOff = Lists.newArrayList();
|
||||
/** Positions that need to be checked to be turned on **/
|
||||
private List<BlockPosition> turnOn = Lists.newArrayList();
|
||||
/** Positions of wire that was updated already (Ordering determines update order and is therefore required!) **/
|
||||
private final Set<BlockPosition> updatedRedstoneWire = Sets.newLinkedHashSet();
|
||||
|
||||
/** Ordered arrays of the facings; Needed for the update order.
|
||||
* I went with a vertical-first order here, but vertical last would work to.
|
||||
* However it should be avoided to update the vertical axis between the horizontal ones as this would cause unneeded directional behavior. **/
|
||||
private static final EnumDirection[] facingsHorizontal = {EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH};
|
||||
private static final EnumDirection[] facingsVertical = {EnumDirection.DOWN, EnumDirection.UP};
|
||||
private static final EnumDirection[] facings = ArrayUtils.addAll(facingsVertical, facingsHorizontal);
|
||||
|
||||
/** Offsets for all surrounding blocks that need to receive updates **/
|
||||
private static final BaseBlockPosition[] surroundingBlocksOffset;
|
||||
static {
|
||||
Set<BaseBlockPosition> set = Sets.newLinkedHashSet();
|
||||
for (EnumDirection facing : facings) {
|
||||
set.add(facing.getDirectionPosition());
|
||||
}
|
||||
for (EnumDirection facing1 : facings) {
|
||||
BaseBlockPosition v1 = facing1.getDirectionPosition();
|
||||
for (EnumDirection facing2 : facings) {
|
||||
BaseBlockPosition v2 = facing2.getDirectionPosition();
|
||||
set.add(new BaseBlockPosition(v1.getX() + v2.getX(), v1.getY() + v2.getY(), v1.getZ() + v2.getZ()));
|
||||
}
|
||||
}
|
||||
set.remove(BaseBlockPosition.ZERO);
|
||||
surroundingBlocksOffset = set.toArray(new BaseBlockPosition[set.size()]);
|
||||
}
|
||||
|
||||
@Shadow(aliases = "g") private boolean canProvidePower;
|
||||
@Shadow public abstract int getPower(World world, BlockPosition pos, int strength);
|
||||
@Shadow(aliases = "b") public abstract boolean isPowerSourceAt(IBlockAccess worldIn, BlockPosition pos, EnumDirection side);
|
||||
|
||||
@Inject(method = "e", at = @At("HEAD"), cancellable = true)
|
||||
private void onUpdateSurroundingRedstone(World worldIn, BlockPosition pos, IBlockData state, CallbackInfoReturnable<IBlockData> cir) {
|
||||
this.updateSurroundingRedstone(worldIn, pos);
|
||||
cir.setReturnValue(state);
|
||||
}
|
||||
|
||||
@Inject(method = "a*", at = @At("HEAD"), cancellable = true)
|
||||
private void onCalculateCurrentChanges(World worldIn, BlockPosition pos1, BlockPosition pos2, IBlockData state, CallbackInfoReturnable<IBlockData> cir) {
|
||||
this.calculateCurrentChanges(worldIn, pos1);
|
||||
cir.setReturnValue(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates all surrounding wires and causes all needed updates
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param world World
|
||||
* @param pos Position that needs updating
|
||||
*/
|
||||
private void updateSurroundingRedstone(World world, BlockPosition pos) {
|
||||
// Recalculate the connected wires
|
||||
this.calculateCurrentChanges(world, pos);
|
||||
|
||||
// Set to collect all the updates, to only execute them once. Ordering required.
|
||||
Set<BlockPosition> blocksNeedingUpdate = Sets.newLinkedHashSet();
|
||||
|
||||
// Add the needed updates
|
||||
for (BlockPosition posi : this.updatedRedstoneWire) {
|
||||
this.addBlocksNeedingUpdate(world, posi, blocksNeedingUpdate);
|
||||
}
|
||||
// Add all other updates to keep known behaviors
|
||||
// They are added in a backwards order because it preserves a commonly used behavior with the update order
|
||||
Iterator<BlockPosition> it = Lists.newLinkedList(this.updatedRedstoneWire).descendingIterator();
|
||||
while (it.hasNext()) {
|
||||
this.addAllSurroundingBlocks(it.next(), blocksNeedingUpdate);
|
||||
}
|
||||
// Remove updates on the wires as they just were updated
|
||||
blocksNeedingUpdate.removeAll(this.updatedRedstoneWire);
|
||||
/*
|
||||
* Avoid unnecessary updates on the just updated wires A huge scale test
|
||||
* showed about 40% more ticks per second It's probably less in normal
|
||||
* usage but likely still worth it
|
||||
*/
|
||||
this.updatedRedstoneWire.clear();
|
||||
|
||||
// Execute updates
|
||||
for (BlockPosition posi : blocksNeedingUpdate) {
|
||||
world.applyPhysics(posi, (BlockRedstoneWire) (Object) this, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on or off all connected wires
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param position Position of the wire that received the update
|
||||
*/
|
||||
private void calculateCurrentChanges(World worldIn, BlockPosition position) {
|
||||
// Turn off all connected wires first if needed
|
||||
if (worldIn.getType(position).getBlock() == (BlockRedstoneWire) (Object) this) {
|
||||
turnOff.add(position);
|
||||
} else {
|
||||
// In case this wire was removed, check the surrounding wires
|
||||
this.checkSurroundingWires(worldIn, position);
|
||||
}
|
||||
|
||||
while (!turnOff.isEmpty()) {
|
||||
BlockPosition pos = turnOff.remove(0);
|
||||
if (pos == null) continue; // Akarin
|
||||
IBlockData state = worldIn.getType(pos);
|
||||
int oldPower = state.get(BlockRedstoneWire.POWER).intValue();
|
||||
this.canProvidePower = false;
|
||||
int blockPower = worldIn.z(pos); // OBFHELPER: isBlockIndirectlyGettingPowered
|
||||
this.canProvidePower = true;
|
||||
int wirePower = this.getSurroundingWirePower(worldIn, pos);
|
||||
|
||||
// Lower the strength as it moved a block
|
||||
wirePower--;
|
||||
int newPower = Math.max(blockPower, wirePower);
|
||||
|
||||
// Akarin start - BlockRedstoneEvent
|
||||
if (oldPower != newPower) {
|
||||
BlockRedstoneEvent event = new BlockRedstoneEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), oldPower, newPower);
|
||||
worldIn.getServer().getPluginManager().callEvent(event);
|
||||
newPower = event.getNewCurrent();
|
||||
}
|
||||
// Akarin end
|
||||
|
||||
// Power lowered?
|
||||
if (newPower < oldPower) {
|
||||
// If it's still powered by a direct source (but weaker) mark for turn on
|
||||
if (blockPower > 0 && !this.turnOn.contains(pos)) {
|
||||
this.turnOn.add(pos);
|
||||
}
|
||||
// Set all the way to off for now, because wires that were powered by this need to update first
|
||||
setWireState(worldIn, pos, state, 0);
|
||||
// Power rose?
|
||||
} else if (newPower > oldPower) {
|
||||
// Set new Power
|
||||
this.setWireState(worldIn, pos, state, newPower);
|
||||
}
|
||||
// Check if surrounding wires need to change based on the current/new state and add them to the lists
|
||||
this.checkSurroundingWires(worldIn, pos);
|
||||
}
|
||||
// Now all needed wires are turned off. Time to turn them on again if there is a power source.
|
||||
while (!this.turnOn.isEmpty()) {
|
||||
BlockPosition pos = this.turnOn.remove(0);
|
||||
if (pos == null) continue; // Akarin
|
||||
IBlockData state = worldIn.getType(pos);
|
||||
int oldPower = state.get(BlockRedstoneWire.POWER).intValue();
|
||||
this.canProvidePower = false;
|
||||
int blockPower = worldIn.z(pos); // OBFHELPER: isBlockIndirectlyGettingPowered
|
||||
this.canProvidePower = true;
|
||||
int wirePower = this.getSurroundingWirePower(worldIn, pos);
|
||||
// Lower the strength as it moved a block
|
||||
wirePower--;
|
||||
int newPower = Math.max(blockPower, wirePower);
|
||||
|
||||
// Akarin start - BlockRedstoneEvent
|
||||
BlockRedstoneEvent event = new BlockRedstoneEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), oldPower, newPower);
|
||||
worldIn.getServer().getPluginManager().callEvent(event);
|
||||
newPower = event.getNewCurrent();
|
||||
// Akarin end
|
||||
|
||||
if (newPower > oldPower) {
|
||||
setWireState(worldIn, pos, state, newPower);
|
||||
} else if (newPower < oldPower) {
|
||||
// Add warning
|
||||
}
|
||||
// Check if surrounding wires need to change based on the current/new state and add them to the lists
|
||||
this.checkSurroundingWires(worldIn, pos);
|
||||
}
|
||||
this.turnOff.clear();
|
||||
this.turnOn.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an wire needs to be marked for update depending on the power next to it
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position of the wire that might need to change
|
||||
* @param otherPower Power of the wire next to it
|
||||
*/
|
||||
private void addWireToList(World worldIn, BlockPosition pos, int otherPower) {
|
||||
IBlockData state = worldIn.getType(pos);
|
||||
if (state.getBlock() == (BlockRedstoneWire) (Object) this) {
|
||||
int power = state.get(BlockRedstoneWire.POWER).intValue();
|
||||
// Could get powered stronger by the neighbor?
|
||||
if (power < (otherPower - 1) && !this.turnOn.contains(pos)) {
|
||||
// Mark for turn on check.
|
||||
this.turnOn.add(pos);
|
||||
}
|
||||
// Should have powered the neighbor? Probably was powered by it and is in turn off phase.
|
||||
if (power > otherPower && !this.turnOff.contains(pos)) {
|
||||
// Mark for turn off check.
|
||||
this.turnOff.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the wires around need to get updated depending on this wires state.
|
||||
* Checks all wires below before the same layer before on top to keep
|
||||
* some more rotational symmetry around the y-axis.
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position of the wire
|
||||
*/
|
||||
private void checkSurroundingWires(World worldIn, BlockPosition pos) {
|
||||
IBlockData state = worldIn.getType(pos);
|
||||
int ownPower = 0;
|
||||
if (state.getBlock() == (BlockRedstoneWire) (Object) this) {
|
||||
ownPower = state.get(BlockRedstoneWire.POWER).intValue();
|
||||
}
|
||||
// Check wires on the same layer first as they appear closer to the wire
|
||||
for (EnumDirection facing : facingsHorizontal) {
|
||||
BlockPosition offsetPos = pos.shift(facing);
|
||||
if (facing.getAxis().isHorizontal()) {
|
||||
this.addWireToList(worldIn, offsetPos, ownPower);
|
||||
}
|
||||
}
|
||||
for (EnumDirection facingVertical : facingsVertical) {
|
||||
BlockPosition offsetPos = pos.shift(facingVertical);
|
||||
boolean solidBlock = worldIn.getType(offsetPos).k(); // OBFHELPER: isBlockNormalCube
|
||||
for (EnumDirection facingHorizontal : facingsHorizontal) {
|
||||
// wire can travel upwards if the block on top doesn't cut the wire (is non-solid)
|
||||
// it can travel down if the block below is solid and the block "diagonal" doesn't cut off the wire (is non-solid)
|
||||
if ((facingVertical == EnumDirection.UP && !solidBlock) || (facingVertical == EnumDirection.DOWN && solidBlock && !worldIn.getType(offsetPos.shift(facingHorizontal)).k())) { // OBFHELPER: isBlockNormalCube
|
||||
this.addWireToList(worldIn, offsetPos.shift(facingHorizontal), ownPower);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum power of the surrounding wires
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position of the asking wire
|
||||
* @return The maximum power of the wires that could power the wire at pos
|
||||
*/
|
||||
private int getSurroundingWirePower(World worldIn, BlockPosition pos) {
|
||||
int wirePower = 0;
|
||||
for (EnumDirection enumfacing : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
|
||||
BlockPosition offsetPos = pos.shift(enumfacing);
|
||||
// Wires on the same layer
|
||||
wirePower = this.getPower(worldIn, offsetPos, wirePower);
|
||||
|
||||
// Block below the wire need to be solid (Upwards diode of slabs/stairs/glowstone) and no block should cut the wire
|
||||
if(worldIn.getType(offsetPos).l() && !worldIn.getType(pos.up()).l()) { // OBFHELPER: isNormalCube
|
||||
wirePower = this.getPower(worldIn, offsetPos.up(), wirePower);
|
||||
// Only get from power below if no block is cutting the wire
|
||||
} else if (!worldIn.getType(offsetPos).l()) { // OBFHELPER: isNormalCube
|
||||
wirePower = this.getPower(worldIn, offsetPos.down(), wirePower);
|
||||
}
|
||||
}
|
||||
return wirePower;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all blocks that need to receive an update from a redstone change in this position.
|
||||
* This means only blocks that actually could change.
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position of the wire
|
||||
* @param set Set to add the update positions too
|
||||
*/
|
||||
private void addBlocksNeedingUpdate(World worldIn, BlockPosition pos, Set<BlockPosition> set) {
|
||||
List<EnumDirection> connectedSides = this.getSidesToPower(worldIn, pos);
|
||||
// Add the blocks next to the wire first (closest first order)
|
||||
for (EnumDirection facing : facings) {
|
||||
BlockPosition offsetPos = pos.shift(facing);
|
||||
// canConnectTo() is not the nicest solution here as it returns true for e.g. the front of a repeater
|
||||
// canBlockBePowereFromSide catches these cases
|
||||
if (!connectedSides.contains(facing.opposite()) && facing != EnumDirection.DOWN
|
||||
&& (!facing.getAxis().isHorizontal() || canConnectToBlock(worldIn.getType(offsetPos), facing))) continue;
|
||||
if (this.canBlockBePoweredFromSide(worldIn.getType(offsetPos), facing, true))
|
||||
set.add(offsetPos);
|
||||
}
|
||||
// Later add blocks around the surrounding blocks that get powered
|
||||
for (EnumDirection facing : facings) {
|
||||
BlockPosition offsetPos = pos.shift(facing);
|
||||
if (!connectedSides.contains(facing.opposite()) && facing != EnumDirection.DOWN || !worldIn.getType(offsetPos).l()) continue; // OBFHELPER: isNormalCube
|
||||
for (EnumDirection facing1 : facings) {
|
||||
if (this.canBlockBePoweredFromSide(worldIn.getType(offsetPos.shift(facing1)), facing1, false))
|
||||
set.add(offsetPos.shift(facing1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a block can get powered from a side.
|
||||
* This behavior would better be implemented per block type as follows:
|
||||
* - return false as default. (blocks that are not affected by redstone don't need to be updated, it doesn't really hurt if they are either)
|
||||
* - return true for all blocks that can get powered from all side and change based on it (doors, fence gates, trap doors, note blocks, lamps, dropper, hopper, TNT, rails, possibly more)
|
||||
* - implement own logic for pistons, repeaters, comparators and redstone torches
|
||||
* The current implementation was chosen to keep everything in one class.
|
||||
*
|
||||
* Why is this extra check needed?
|
||||
* 1. It makes sure that many old behaviors still work (QC + Pistons).
|
||||
* 2. It prevents updates from "jumping".
|
||||
* Or rather it prevents this wire to update a block that would get powered by the next one of the same line.
|
||||
* This is to prefer as it makes understanding the update order of the wire really easy. The signal "travels" from the power source.
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param state State of the block
|
||||
* @param side Side from which it gets powered
|
||||
* @param isWire True if it's powered by a wire directly, False if through a block
|
||||
* @return True if the block can change based on the power level it gets on the given side, false otherwise
|
||||
*/
|
||||
private boolean canBlockBePoweredFromSide(IBlockData state, EnumDirection side, boolean isWire) {
|
||||
if (state.getBlock() instanceof BlockPiston && state.get(BlockPiston.FACING) == side.opposite()) {
|
||||
return false;
|
||||
}
|
||||
if (state.getBlock() instanceof BlockDiodeAbstract && state.get(BlockDiodeAbstract.FACING) != side.opposite()) {
|
||||
if (isWire && state.getBlock() instanceof BlockRedstoneComparator
|
||||
&& state.get(BlockRedstoneComparator.FACING).k() != side.getAxis() && side.getAxis().isHorizontal()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (state.getBlock() instanceof BlockRedstoneTorch) {
|
||||
if (isWire || state.get(BlockRedstoneTorch.FACING) != side) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of all horizontal sides that can get powered by a wire.
|
||||
* The list is ordered the same as the facingsHorizontal.
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position of the wire
|
||||
* @return List of all facings that can get powered by this wire
|
||||
*/
|
||||
private List<EnumDirection> getSidesToPower(World worldIn, BlockPosition pos) {
|
||||
List<EnumDirection> retval = Lists.newArrayList();
|
||||
for (EnumDirection facing : facingsHorizontal) {
|
||||
if (isPowerSourceAt(worldIn, pos, facing))
|
||||
retval.add(facing);
|
||||
}
|
||||
if (retval.isEmpty()) return Lists.newArrayList(facingsHorizontal);
|
||||
boolean northsouth = retval.contains(EnumDirection.NORTH) || retval.contains(EnumDirection.SOUTH);
|
||||
boolean eastwest = retval.contains(EnumDirection.EAST) || retval.contains(EnumDirection.WEST);
|
||||
if (northsouth) {
|
||||
retval.remove(EnumDirection.EAST);
|
||||
retval.remove(EnumDirection.WEST);
|
||||
}
|
||||
if (eastwest) {
|
||||
retval.remove(EnumDirection.NORTH);
|
||||
retval.remove(EnumDirection.SOUTH);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all surrounding positions to a set.
|
||||
* This is the neighbor blocks, as well as their neighbors
|
||||
*
|
||||
* @param pos
|
||||
* @param set
|
||||
*/
|
||||
private void addAllSurroundingBlocks(BlockPosition pos, Set<BlockPosition> set) {
|
||||
for (BaseBlockPosition vect : surroundingBlocksOffset) {
|
||||
set.add(pos.a(vect)); // OBFHELPER: add
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the block state of a wire with a new power level and marks for updates
|
||||
*
|
||||
* @author panda
|
||||
*
|
||||
* @param worldIn World
|
||||
* @param pos Position at which the state needs to be set
|
||||
* @param state Old state
|
||||
* @param power Power it should get set to
|
||||
*/
|
||||
private void setWireState(World worldIn, BlockPosition pos, IBlockData state, int power) {
|
||||
state = state.set(BlockRedstoneWire.POWER, Integer.valueOf(power));
|
||||
worldIn.setTypeAndData(pos, state, 2);
|
||||
updatedRedstoneWire.add(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author panda
|
||||
* @reason Uses local surrounding block offset list for notifications.
|
||||
*
|
||||
* @param world The world
|
||||
* @param pos The position
|
||||
* @param state The block state
|
||||
*/
|
||||
@Override
|
||||
@Overwrite
|
||||
public void onPlace(World world, BlockPosition pos, IBlockData state) {
|
||||
this.updateSurroundingRedstone(world, pos);
|
||||
for (BaseBlockPosition vec : surroundingBlocksOffset) {
|
||||
world.applyPhysics(pos.a(vec), this, false); // OBFHELPER: add
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author panda
|
||||
* @reason Uses local surrounding block offset list for notifications.
|
||||
*
|
||||
* @param world The world
|
||||
* @param pos The position
|
||||
*/
|
||||
@Override
|
||||
@Overwrite
|
||||
public void remove(World world, BlockPosition pos, IBlockData state) {
|
||||
super.remove(world, pos, state);
|
||||
this.updateSurroundingRedstone(world, pos);
|
||||
for (BaseBlockPosition vec : surroundingBlocksOffset) {
|
||||
world.applyPhysics(pos.a(vec), this, false); // OBFHELPER: add
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author panda
|
||||
* @reason Changed to use getSidesToPower() to avoid duplicate implementation.
|
||||
*
|
||||
* @param blockState The block state
|
||||
* @param blockAccess The block access
|
||||
* @param pos The position
|
||||
* @param side The side
|
||||
*/
|
||||
@Override
|
||||
@Overwrite
|
||||
public int b(IBlockData blockState, IBlockAccess blockAccess, BlockPosition pos, EnumDirection side) { // OBFHELPER: getWeakPower
|
||||
if (!this.canProvidePower) {
|
||||
return 0;
|
||||
} else {
|
||||
if (side == EnumDirection.UP || this.getSidesToPower((World) blockAccess, pos).contains(side)) {
|
||||
return blockState.get(BlockRedstoneWire.POWER).intValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canConnectToBlock(IBlockData blockState, @Nullable EnumDirection side) {
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
if (block == Blocks.REDSTONE_WIRE) {
|
||||
return true;
|
||||
} else if (Blocks.UNPOWERED_REPEATER.D(blockState)) { // OBFHELPER: isSameDiode
|
||||
EnumDirection enumdirection1 = blockState.get(BlockRepeater.FACING);
|
||||
|
||||
return enumdirection1 == side || enumdirection1.opposite() == side;
|
||||
} else if (Blocks.dk == blockState.getBlock()) {
|
||||
return side == blockState.get(BlockObserver.FACING); // OBFHELPER: OBSERVER
|
||||
} else {
|
||||
return blockState.m() && side != null; // OBFHELPER: canProvidePower
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,11 +16,11 @@ import net.minecraft.server.WorldGenBigTree;
|
||||
* Fixes MC-128547(https://bugs.mojang.com/browse/MC-128547)
|
||||
*/
|
||||
@Mixin(value = WorldGenBigTree.class, remap = false)
|
||||
public class WeakBigTree {
|
||||
@Shadow private World l;
|
||||
public abstract class WeakBigTree {
|
||||
@Shadow(aliases = "l") private World worldReference;
|
||||
|
||||
@Inject(method = "generate", at = @At("RETURN"))
|
||||
private void clearWorldRef(World world, Random random, BlockPosition pos, CallbackInfoReturnable<?> info) {
|
||||
l = null; // Akarin - remove references to world objects to avoid memory leaks
|
||||
world = null; // Akarin - remove references to world objects to avoid memory leaks
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,56 +40,56 @@ import net.minecraft.server.ItemStack;
|
||||
* Fixes MC-128547(https://bugs.mojang.com/browse/MC-128547)
|
||||
*/
|
||||
@Mixin(value = EnchantmentManager.class, remap = false)
|
||||
public class WeakEnchantmentManager {
|
||||
@Shadow @Final private static EnchantmentManager.EnchantmentModifierProtection a;
|
||||
@Shadow @Final private static EnchantmentManager.EnchantmentModifierThorns c;
|
||||
@Shadow @Final private static EnchantmentManager.EnchantmentModifierArthropods d;
|
||||
public abstract class WeakEnchantmentManager {
|
||||
@Shadow(aliases = "a") @Final private static EnchantmentManager.EnchantmentModifierProtection protection;
|
||||
@Shadow(aliases = "c") @Final private static EnchantmentManager.EnchantmentModifierThorns thorns;
|
||||
@Shadow(aliases = "d") @Final private static EnchantmentManager.EnchantmentModifierArthropods arthropods;
|
||||
|
||||
@Shadow private static void a(EnchantmentManager.EnchantmentModifier modifier, Iterable<ItemStack> iterable) {}
|
||||
@Shadow private static void a(EnchantmentManager.EnchantmentModifier modifier, ItemStack itemstack) {}
|
||||
|
||||
@Overwrite
|
||||
public static int a(Iterable<ItemStack> iterable, DamageSource damageSource) {
|
||||
EnchantmentManager.a.a = 0; // PAIL: damageModifier
|
||||
EnchantmentManager.a.b = damageSource;
|
||||
a(EnchantmentManager.a, iterable);
|
||||
a.b = null; // Akarin - Remove reference to Damagesource
|
||||
return EnchantmentManager.a.a;
|
||||
protection.a = 0; // OBFHELPER: damageModifier
|
||||
protection.b = damageSource;
|
||||
a(protection, iterable); // OBFHELPER: applyEnchantmentModifierArray
|
||||
protection.b = null; // Akarin - Remove reference to Damagesource
|
||||
return protection.a;
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public static void a(EntityLiving user, Entity attacker) { // PAIL: applyThornEnchantments
|
||||
EnchantmentManager.c.b = attacker;
|
||||
EnchantmentManager.c.a = user;
|
||||
public static void a(EntityLiving user, Entity attacker) { // OBFHELPER: applyThornEnchantments
|
||||
thorns.b = attacker;
|
||||
thorns.a = user;
|
||||
if (user != null) {
|
||||
a(EnchantmentManager.c, user.aQ()); // PAIL: applyEnchantmentModifierArray, getEquipmentAndArmor
|
||||
a(thorns, user.aQ()); // OBFHELPER: applyEnchantmentModifierArray - getEquipmentAndArmor
|
||||
}
|
||||
|
||||
if (attacker instanceof EntityHuman) {
|
||||
a(EnchantmentManager.c, user.getItemInMainHand()); // PAIL: applyEnchantmentModifier
|
||||
a(thorns, user.getItemInMainHand()); // OBFHELPER: applyEnchantmentModifier
|
||||
}
|
||||
|
||||
// Akarin Start - remove references to entity objects to avoid memory leaks
|
||||
c.b = null;
|
||||
c.a = null;
|
||||
// SAkarin end
|
||||
thorns.b = null;
|
||||
thorns.a = null;
|
||||
// Akarin end
|
||||
}
|
||||
|
||||
@Overwrite
|
||||
public static void b(EntityLiving user, Entity target) { // PAIL: applyArthropodEnchantments
|
||||
EnchantmentManager.d.a = user;
|
||||
EnchantmentManager.d.b = target;
|
||||
public static void b(EntityLiving user, Entity target) { // OBFHELPER: applyArthropodEnchantments
|
||||
arthropods.a = user;
|
||||
arthropods.b = target;
|
||||
if (user != null) {
|
||||
a(EnchantmentManager.d, user.aQ()); // PAIL: applyEnchantmentModifierArray, getEquipmentAndArmor
|
||||
a(arthropods, user.aQ()); // OBFHELPER: applyEnchantmentModifierArray - getEquipmentAndArmor
|
||||
}
|
||||
|
||||
if (user instanceof EntityHuman) {
|
||||
a(EnchantmentManager.d, user.getItemInMainHand()); // PAIL: applyEnchantmentModifier
|
||||
a(arthropods, user.getItemInMainHand()); // OBFHELPER: applyEnchantmentModifier
|
||||
}
|
||||
|
||||
// Akarin Start - remove references to entity objects to avoid memory leaks
|
||||
d.a = null;
|
||||
d.b = null;
|
||||
arthropods.a = null;
|
||||
arthropods.b = null;
|
||||
// Akarin end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = Entity.class, remap = false, priority = 1001)
|
||||
public abstract class MixinEntity {
|
||||
private static final String ENTITY_RIDABLE_COOLDOWN_FIELD = "Lnet/minecraft/entity/Entity;j:I"; // PUTFIELD: rideCooldown
|
||||
private static final String ENTITY_PORTAL_COUNTER_FIELD = "Lnet/minecraft/entity/Entity;al:I"; // PUTFIELD: portalCounter
|
||||
@Shadow protected int j;
|
||||
@Shadow protected int al;
|
||||
@Shadow public World world;
|
||||
|
||||
// OBFHELPER: onEntityUpdate
|
||||
@Redirect(method = "Y()V", at = @At(value = "FIELD", target = ENTITY_RIDABLE_COOLDOWN_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupEntityCooldown(Entity self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.world).getRealTimeTicks();
|
||||
this.j = Math.max(0, this.j - ticks); // OBFHELPER: rideCooldown
|
||||
}
|
||||
|
||||
@Redirect(method = "Y()V", at = @At(value = "FIELD", target = ENTITY_PORTAL_COUNTER_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupPortalCounter(Entity self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.world).getRealTimeTicks();
|
||||
this.al += ticks; // OBFHELPER: portalCounter
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityAgeable;
|
||||
|
||||
@Mixin(value = EntityAgeable.class, remap = false)
|
||||
public abstract class MixinEntityAgeable {
|
||||
private static final String ENTITY_AGEABLE_SET_GROWING_AGE_METHOD = "Lnet/minecraft/entity/EntityAgeable;setAgeRaw(I)V";
|
||||
|
||||
// OBFHELPER: onLivingUpdate
|
||||
@Redirect(method = "n()V", at = @At(value = "INVOKE", target = ENTITY_AGEABLE_SET_GROWING_AGE_METHOD, ordinal = 0))
|
||||
public void fixupGrowingUp(EntityAgeable self, int age) {
|
||||
// Subtract the one the original update method added
|
||||
int diff = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks() - 1;
|
||||
self.setAgeRaw(Math.min(0, age + diff));
|
||||
}
|
||||
|
||||
@Redirect(method = "n()V", at = @At(value = "INVOKE", target = ENTITY_AGEABLE_SET_GROWING_AGE_METHOD, ordinal = 1))
|
||||
public void fixupBreedingCooldown(EntityAgeable self, int age) {
|
||||
// Subtract the one the original update method added
|
||||
int diff = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks() - 1;
|
||||
self.setAgeRaw(Math.max(0, age - diff));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityExperienceOrb;
|
||||
|
||||
@Mixin(value = EntityExperienceOrb.class, remap = false)
|
||||
public abstract class MixinEntityExperienceOrb {
|
||||
private static final String ENTITY_XP_DELAY_PICKUP_FIELD = "Lnet/minecraft/entity/item/EntityExperienceOrb;c:I"; // PUTFIELD: delayBeforeCanPickup
|
||||
private static final String ENTITY_XP_AGE_FIELD = "Lnet/minecraft/entity/item/EntityExperienceOrb;b:I"; // PUTFIELD: xpOrbAge
|
||||
@Shadow public int c; // OBFHELPER: delayBeforeCanPickup
|
||||
@Shadow public int b; // OBFHELPER: xpOrbAge
|
||||
|
||||
// OBFHELPER: onUpdate
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_XP_DELAY_PICKUP_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupPickupDelay(EntityExperienceOrb self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.c = Math.max(0, this.c - ticks); // OBFHELPER: delayBeforeCanPickup
|
||||
}
|
||||
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_XP_AGE_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupAge(EntityExperienceOrb self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.b += ticks; // OBFHELPER: xpOrbAge
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
|
||||
@Mixin(value = EntityHuman.class, remap = false)
|
||||
public abstract class MixinEntityHuman {
|
||||
private static final String ENTITY_PLAYER_XP_COOLDOWN_FIELD = "Lnet/minecraft/entity/player/EntityHuman;bD:I"; // PUTFIELD: xpCooldown
|
||||
private static final String ENTITY_PLAYER_SLEEP_TIMER_FIELD = "Lnet/minecraft/entity/player/EntityHuman;sleepTicks:I";
|
||||
@Shadow public int bD;
|
||||
@Shadow private int sleepTicks;
|
||||
|
||||
// OBFHELPER: onUpdate
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_PLAYER_XP_COOLDOWN_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupXpCooldown(EntityHuman self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.bD = Math.max(0, this.bD - ticks); // OBFHELPER: xpCooldown
|
||||
}
|
||||
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_PLAYER_SLEEP_TIMER_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupSleepTimer(EntityHuman self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.sleepTicks += ticks;
|
||||
}
|
||||
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_PLAYER_SLEEP_TIMER_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 2))
|
||||
public void fixupWakeTimer(EntityHuman self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.sleepTicks += ticks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityInsentient;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = EntityInsentient.class, remap = false)
|
||||
public abstract class MixinEntityInsentient extends EntityLiving {
|
||||
private static final String ENTITY_LIVING_AGE_FIELD = "Lnet/minecraft/entity/EntityInsentient;ticksFarFromPlayer:I";
|
||||
|
||||
public MixinEntityInsentient(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Redirect(method = "doTick()V", at = @At(value = "FIELD", target = ENTITY_LIVING_AGE_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupEntityDespawnAge(EntityInsentient self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.ticksFarFromPlayer += ticks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityItem;
|
||||
|
||||
@Mixin(value = EntityItem.class, remap = false)
|
||||
public abstract class MixinEntityItem {
|
||||
private static final String ENTITY_ITEM_DELAY_PICKUP_FIELD = "Lnet/minecraft/entity/item/EntityItem;pickupDelay:I";
|
||||
private static final String ENTITY_ITEM_AGE_FIELD = "Lnet/minecraft/entity/item/EntityItem;age:I";
|
||||
@Shadow public int age;
|
||||
@Shadow private int pickupDelay;
|
||||
|
||||
// OBFHELPER: onUpdate
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_ITEM_DELAY_PICKUP_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupPickupDelay(EntityItem self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.pickupDelay = Math.max(0, this.pickupDelay - ticks);
|
||||
}
|
||||
|
||||
@Redirect(method = "B_()V", at = @At(value = "FIELD", target = ENTITY_ITEM_AGE_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupAge(EntityItem self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.age += ticks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = EntityPlayer.class, remap = false)
|
||||
public abstract class MixinEntityPlayer extends Entity {
|
||||
private static final String ENTITY_PLAYER_MP_PORTAL_COOLDOWN_FIELD = "Lnet/minecraft/entity/player/EntityPlayer;portalCooldown:I";
|
||||
|
||||
public MixinEntityPlayer(World worldIn) {
|
||||
super(worldIn);
|
||||
}
|
||||
|
||||
// OBFHELPER: decrementTimeUntilPortal
|
||||
@Redirect(method = "I()V", at = @At(value = "FIELD", target = ENTITY_PLAYER_MP_PORTAL_COOLDOWN_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupPortalCooldown(EntityPlayer self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
this.portalCooldown = Math.max(0, this.portalCooldown - ticks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.EntityZombieVillager;
|
||||
|
||||
@Mixin(value = EntityZombieVillager.class, remap = false)
|
||||
public abstract class MixinEntityZombieVillager {
|
||||
private static final String ENTITY_ZOMBIE_GET_CONVERSION_BOOST_METHOD = "Lnet/minecraft/entity/monster/EntityZombieVillager;du()I"; // INVOKE: getConversionProgress
|
||||
|
||||
@Shadow(aliases = "du") protected abstract int getConversionProgress();
|
||||
|
||||
// OBFHELPER: onUpdate
|
||||
@Redirect(method = "B_()V", at = @At(value = "INVOKE", target = ENTITY_ZOMBIE_GET_CONVERSION_BOOST_METHOD, ordinal = 0))
|
||||
public int fixupConversionTimeBoost(EntityZombieVillager self) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) self.getWorld()).getRealTimeTicks();
|
||||
return this.getConversionProgress() * ticks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
@Mixin(value = MinecraftServer.class, remap = false, priority = 1001)
|
||||
public abstract class MixinMinecraftServer implements IMixinRealTimeTicking {
|
||||
private static long lastTickNanos = System.nanoTime();
|
||||
private static long realTimeTicks = 1;
|
||||
|
||||
@Inject(method = "C()V", at = @At("HEAD")) // OBFHELPER: fullTick
|
||||
public void onTickUpdateRealTimeTicks(CallbackInfo ci) {
|
||||
long currentNanos = System.nanoTime();
|
||||
realTimeTicks = (currentNanos - lastTickNanos) / 50000000;
|
||||
if (realTimeTicks < 1) {
|
||||
realTimeTicks = 1;
|
||||
}
|
||||
lastTickNanos = currentNanos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getRealTimeTicks() {
|
||||
return realTimeTicks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.PlayerConnection;
|
||||
|
||||
@Mixin(value = PlayerConnection.class, remap = false)
|
||||
public abstract class MixinPlayerConnection {
|
||||
private static final String NET_HANDLER_PLAY_CHAT_SPAM_FIELD = "Lnet/minecraft/network/PlayerConnection;chatThrottle:I";
|
||||
private static final String NET_HANDLER_PLAY_DROP_SPAM_FIELD = "Lnet/minecraft/network/PlayerConnection;itemDropThreshold:I";
|
||||
@Shadow private volatile int chatThrottle;
|
||||
@Shadow(aliases = "j") private int itemDropThreshold;
|
||||
@Shadow @Final private MinecraftServer minecraftServer;
|
||||
|
||||
// OBFHELPER: update
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = NET_HANDLER_PLAY_CHAT_SPAM_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupChatSpamCheck(PlayerConnection self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.minecraftServer).getRealTimeTicks();
|
||||
this.chatThrottle = Math.max(0, this.chatThrottle - ticks);
|
||||
}
|
||||
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = NET_HANDLER_PLAY_DROP_SPAM_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupDropSpamCheck(PlayerConnection self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.minecraftServer).getRealTimeTicks();
|
||||
this.itemDropThreshold = Math.max(0, this.itemDropThreshold - ticks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.PlayerInteractManager;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = PlayerInteractManager.class, remap = false)
|
||||
public abstract class MixinPlayerInteractManager {
|
||||
private static final String PLAYER_INTERACTION_BLOCK_DAMAGE_FIELD = "Lnet/minecraft/server/management/PlayerInteractManager;currentTick:I";
|
||||
@Shadow public World world;
|
||||
@Shadow private int currentTick;
|
||||
|
||||
// OBFHELPER: updateBlockRemoving
|
||||
@Redirect(method = "a()V", at = @At(value = "FIELD", target = PLAYER_INTERACTION_BLOCK_DAMAGE_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupDiggingTime(PlayerInteractManager self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.world.getMinecraftServer()).getRealTimeTicks();
|
||||
this.currentTick += ticks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.TileEntity;
|
||||
import net.minecraft.server.TileEntityBrewingStand;
|
||||
|
||||
@Mixin(value = TileEntityBrewingStand.class, remap = false)
|
||||
public abstract class MixinTileEntityBrewingStand extends TileEntity {
|
||||
private static final String BREWING_STAND_BREW_TIME_FIELD = "Lnet/minecraft/tileentity/TileEntityBrewingStand;brewTime:I";
|
||||
@Shadow private int brewTime;
|
||||
|
||||
// OBFHELPER: update
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = BREWING_STAND_BREW_TIME_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupBrewTime(TileEntityBrewingStand self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.getWorld()).getRealTimeTicks();
|
||||
this.brewTime = Math.max(0, this.brewTime - ticks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.TileEntity;
|
||||
import net.minecraft.server.TileEntityFurnace;
|
||||
|
||||
@Mixin(value = TileEntityFurnace.class, remap = false)
|
||||
public abstract class MixinTileEntityFurnace extends TileEntity {
|
||||
private static final String FURNACE_BURN_TIME_FIELD = "Lnet/minecraft/tileentity/TileEntityFurnace;burnTime:I";
|
||||
private static final String FURNACE_COOK_TIME_FIELD = "Lnet/minecraft/tileentity/TileEntityFurnace;cookTime:I";
|
||||
@Shadow private int burnTime;
|
||||
@Shadow private int cookTime;
|
||||
@Shadow private int cookTimeTotal;
|
||||
|
||||
// OBFHELPER: update
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = FURNACE_BURN_TIME_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupBurnTime(TileEntityFurnace self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.getWorld()).getRealTimeTicks();
|
||||
this.burnTime = Math.max(0, this.burnTime - ticks);
|
||||
}
|
||||
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = FURNACE_COOK_TIME_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 0))
|
||||
public void fixupCookTime(TileEntityFurnace self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.getWorld()).getRealTimeTicks();
|
||||
this.cookTime = Math.min(this.cookTimeTotal, this.cookTime + ticks);
|
||||
}
|
||||
|
||||
@Redirect(method = "e()V", at = @At(value = "FIELD", target = FURNACE_COOK_TIME_FIELD, opcode = Opcodes.PUTFIELD, ordinal = 3))
|
||||
public void fixupCookTimeCooldown(TileEntityFurnace self, int modifier) {
|
||||
int ticks = (int) ((IMixinRealTimeTicking) this.getWorld()).getRealTimeTicks();
|
||||
this.cookTime = MathHelper.clamp(this.cookTime - (2 * ticks), 0, this.cookTimeTotal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
@Mixin(value = World.class, remap = false, priority = 1001)
|
||||
public abstract class MixinWorld implements IMixinRealTimeTicking {
|
||||
@Shadow @Nullable public abstract MinecraftServer getMinecraftServer();
|
||||
|
||||
@Override
|
||||
public long getRealTimeTicks() {
|
||||
if (this.getMinecraftServer() != null) {
|
||||
return ((IMixinRealTimeTicking) this.getMinecraftServer()).getRealTimeTicks();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of Sponge, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the 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.
|
||||
*/
|
||||
package io.akarin.server.mixin.realtime;
|
||||
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import io.akarin.api.internal.mixin.IMixinRealTimeTicking;
|
||||
import net.minecraft.server.IDataManager;
|
||||
import net.minecraft.server.MethodProfiler;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldData;
|
||||
import net.minecraft.server.WorldProvider;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@Mixin(value = WorldServer.class, remap = false, priority = 1001)
|
||||
public abstract class MixinWorldServer extends World implements IMixinRealTimeTicking {
|
||||
|
||||
protected MixinWorldServer(IDataManager idatamanager, WorldData worlddata, WorldProvider worldprovider, MethodProfiler methodprofiler, boolean flag, ChunkGenerator gen, Environment env) {
|
||||
super(idatamanager, worlddata, worldprovider, methodprofiler, flag, gen, env);
|
||||
}
|
||||
|
||||
@Inject(method = "doTick()V", at = @At("HEAD"))
|
||||
public void fixTimeOfDay(CallbackInfo ci) {
|
||||
if (this.getGameRules().getBoolean("doDaylightCycle")) {
|
||||
// Subtract the one the original tick method is going to add
|
||||
long diff = this.getRealTimeTicks() - 1;
|
||||
// Don't set if we're not changing it as other mods might be listening for changes
|
||||
if (diff > 0) {
|
||||
this.worldData.setDayTime(this.worldData.getDayTime() + diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1561
sources/src/main/java/net/minecraft/server/Chunk.java
Normal file
1561
sources/src/main/java/net/minecraft/server/Chunk.java
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user