@@ -20,45 +20,52 @@ public class DeObfuscator {
2020
2121 private final ServerPlayerEntity player ;
2222 private final HashSet <Vec3i > revealed = new HashSet <>();
23+ private final BlockPos .Mutable mutable = new BlockPos .Mutable ();
24+
25+ private Thread thread = null ;
2326
2427 public DeObfuscator (ServerPlayerEntity player ) {
2528 this .player = player ;
2629 }
2730
2831 public void tick () {
29- Vec3d origin = this .player .getCameraPosVec (1F );
32+ if (thread == null || !thread .isAlive ()) {
33+ thread = new Thread (() -> {
34+ Vec3d origin = this .player .getCameraPosVec (1F );
3035
31- for (Vec3i pos : this .revealed ) {
32- if (!pos .isWithinDistance (origin , SEARCH_RADIUS )) {
33- this .sendBlockUpdate (new BlockPos (pos ), this .player .networkHandler ::sendPacket );
34- }
35- }
36+ for (Vec3i pos : this .revealed ) {
37+ if (!pos .isWithinDistance (origin , SEARCH_RADIUS )) {
38+ this .sendBlockUpdate (new BlockPos (pos ), this .player .networkHandler ::sendPacket );
39+ }
40+ }
3641
37- this .revealed .removeIf (pos -> !pos .isWithinDistance (origin , SEARCH_RADIUS ));
38- BlockPos .Mutable mutable = new BlockPos .Mutable ();
39-
40- int i = 0 ;
41- for (byte x = -SEARCH_RADIUS ; x <= SEARCH_RADIUS ; ++x ) {
42- for (byte y = -SEARCH_RADIUS ; y <= SEARCH_RADIUS ; ++y ) {
43- for (byte z = -SEARCH_RADIUS ; z <= SEARCH_RADIUS ; ++z ) {
44- if (x * x + y * y + z * z <= SEARCH_RADIUS * SEARCH_RADIUS ) {
45- ++i ;
46- mutable .set (origin .x , origin .y , origin .z );
47- mutable .move (x , y , z );
48-
49- if (Config .HIDDEN .containsKey (this .player .world .getBlockState (mutable ).getBlock ())) {
50- Vec3i pos = mutable .toImmutable ();
51-
52- if (!this .revealed .contains (pos )) {
53- if (this .traceForBlock (this .player , pos )) {
54- this .revealed .add (pos );
55- this .sendBlockUpdate (new BlockPos (pos ), this .player .networkHandler .connection ::send );
42+ this .revealed .removeIf (pos -> !pos .isWithinDistance (origin , SEARCH_RADIUS ));
43+
44+ for (byte x = -SEARCH_RADIUS ; x <= SEARCH_RADIUS ; ++x ) {
45+ for (byte y = -SEARCH_RADIUS ; y <= SEARCH_RADIUS ; ++y ) {
46+ for (byte z = -SEARCH_RADIUS ; z <= SEARCH_RADIUS ; ++z ) {
47+ if (x * x + y * y + z * z <= SEARCH_RADIUS * SEARCH_RADIUS ) {
48+ mutable .set (origin .x , origin .y , origin .z );
49+ mutable .move (x , y , z );
50+
51+ if (Config .HIDDEN .containsKey (this .player .world .getBlockState (mutable ).getBlock ())) {
52+ Vec3i pos = mutable .toImmutable ();
53+
54+ if (!this .revealed .contains (pos )) {
55+ if (this .traceForBlock (this .player , pos )) {
56+ this .revealed .add (pos );
57+ this .sendBlockUpdate (new BlockPos (pos ), this .player .networkHandler .connection ::send );
58+ }
59+ }
5660 }
5761 }
5862 }
5963 }
6064 }
61- }
65+ });
66+
67+ thread .setDaemon (true );
68+ thread .start ();
6269 }
6370 }
6471
0 commit comments