11
11
import meteordevelopment .meteorclient .settings .*;
12
12
import meteordevelopment .meteorclient .systems .modules .Categories ;
13
13
import meteordevelopment .meteorclient .systems .modules .Module ;
14
+ import meteordevelopment .meteorclient .utils .entity .DamageUtils ;
14
15
import meteordevelopment .meteorclient .utils .entity .EntityUtils ;
15
16
import meteordevelopment .meteorclient .utils .entity .SortPriority ;
16
17
import meteordevelopment .meteorclient .utils .entity .TargetUtils ;
20
21
import meteordevelopment .orbit .EventHandler ;
21
22
import net .minecraft .block .Blocks ;
22
23
import net .minecraft .entity .player .PlayerEntity ;
23
- import net .minecraft .fluid .FlowableFluid ;
24
24
import net .minecraft .item .Items ;
25
25
import net .minecraft .util .Hand ;
26
26
import net .minecraft .util .hit .BlockHitResult ;
27
27
import net .minecraft .util .math .BlockPos ;
28
28
import net .minecraft .util .math .Direction ;
29
29
import net .minecraft .util .math .Vec3d ;
30
+ import org .jetbrains .annotations .Nullable ;
30
31
31
32
public class AnchorAura extends Module {
32
33
private final SettingGroup sgGeneral = settings .getDefaultGroup ();
@@ -225,6 +226,7 @@ public class AnchorAura extends Module {
225
226
private int placeDelayLeft ;
226
227
private int breakDelayLeft ;
227
228
private PlayerEntity target ;
229
+ private final BlockPos .Mutable mutable = new BlockPos .Mutable ();
228
230
229
231
public AnchorAura () {
230
232
super (Categories .Combat , "anchor-aura" , "Automatically places and breaks Respawn Anchors to harm entities." );
@@ -264,7 +266,8 @@ private void onTick(TickEvent.Post event) {
264
266
breakDelayLeft = 0 ;
265
267
266
268
if (rotationMode .get () == RotationMode .Both || rotationMode .get () == RotationMode .Break ) {
267
- Rotations .rotate (Rotations .getYaw (breakPos ), Rotations .getPitch (breakPos ), 50 , () -> breakAnchor (breakPos , anchor , glowStone ));
269
+ BlockPos immutableBreakPos = breakPos .toImmutable ();
270
+ Rotations .rotate (Rotations .getYaw (breakPos ), Rotations .getPitch (breakPos ), 50 , () -> breakAnchor (immutableBreakPos , anchor , glowStone ));
268
271
} else breakAnchor (breakPos , anchor , glowStone );
269
272
}
270
273
}
@@ -274,7 +277,7 @@ private void onTick(TickEvent.Post event) {
274
277
275
278
if (placePos != null ) {
276
279
placeDelayLeft = 0 ;
277
- BlockUtils .place (placePos , anchor , (rotationMode .get () == RotationMode .Place || rotationMode .get () == RotationMode .Both ), 50 );
280
+ BlockUtils .place (placePos . toImmutable () , anchor , (rotationMode .get () == RotationMode .Place || rotationMode .get () == RotationMode .Both ), 50 );
278
281
}
279
282
}
280
283
@@ -301,48 +304,50 @@ private void onRender(Render3DEvent event) {
301
304
}
302
305
}
303
306
307
+ @ Nullable
304
308
private BlockPos findPlacePos (BlockPos targetPlacePos ) {
305
309
switch (placePositions .get ()) {
306
- case All :
307
- if (isValidPlace (targetPlacePos . down ())) return targetPlacePos . down () ;
308
- else if (isValidPlace (targetPlacePos . up ( 2 ))) return targetPlacePos . up ( 2 ) ;
309
- else if (isValidPlace (targetPlacePos . add ( 1 , 0 , 0 ))) return targetPlacePos . add ( 1 , 0 , 0 ) ;
310
- else if (isValidPlace (targetPlacePos . add ( -1 , 0 , 0 ))) return targetPlacePos . add (- 1 , 0 , 0 ) ;
311
- else if (isValidPlace (targetPlacePos . add ( 0 , 0 , 1 ))) return targetPlacePos . add ( 0 , 0 , 1 ) ;
312
- else if (isValidPlace (targetPlacePos . add ( 0 , 0 , -1 ))) return targetPlacePos . add ( 0 , 0 , - 1 ) ;
313
- else if (isValidPlace (targetPlacePos . add ( 1 , 1 , 0 ))) return targetPlacePos . add ( 1 , 1 , 0 ) ;
314
- else if (isValidPlace (targetPlacePos . add ( -1 , -1 , 0 ))) return targetPlacePos . add (- 1 , - 1 , 0 ) ;
315
- else if (isValidPlace (targetPlacePos . add ( 0 , 1 , 1 ))) return targetPlacePos . add ( 0 , 1 , 1 ) ;
316
- else if (isValidPlace (targetPlacePos . add ( 0 , 0 , -1 ))) return targetPlacePos . add ( 0 , 0 , - 1 ) ;
317
- break ;
318
- case Above :
319
- if (isValidPlace (targetPlacePos . up ( 2 ))) return targetPlacePos . up ( 2 ) ;
320
- break ;
321
- case AboveAndBelow :
322
- if (isValidPlace (targetPlacePos . down ())) return targetPlacePos . down () ;
323
- else if (isValidPlace (targetPlacePos . up ( 2 ))) return targetPlacePos . up ( 2 ) ;
324
- break ;
325
- case Around :
326
- if (isValidPlace (targetPlacePos . north ())) return targetPlacePos . north () ;
327
- else if (isValidPlace (targetPlacePos . east ())) return targetPlacePos . east () ;
328
- else if (isValidPlace (targetPlacePos . west ())) return targetPlacePos . west () ;
329
- else if (isValidPlace (targetPlacePos . south ())) return targetPlacePos . south () ;
330
- break ;
310
+ case All -> {
311
+ if (isValidPlace (targetPlacePos , 0 , - 1 , 0 )) return mutable ;
312
+ else if (isValidPlace (targetPlacePos , 0 , 2 , 0 )) return mutable ;
313
+ else if (isValidPlace (targetPlacePos , 1 , 0 , 0 )) return mutable ;
314
+ else if (isValidPlace (targetPlacePos , -1 , 0 , 0 )) return mutable ;
315
+ else if (isValidPlace (targetPlacePos , 0 , 0 , 1 )) return mutable ;
316
+ else if (isValidPlace (targetPlacePos , 0 , 0 , -1 )) return mutable ;
317
+ else if (isValidPlace (targetPlacePos , 1 , 1 , 0 )) return mutable ;
318
+ else if (isValidPlace (targetPlacePos , -1 , -1 , 0 )) return mutable ;
319
+ else if (isValidPlace (targetPlacePos , 0 , 1 , 1 )) return mutable ;
320
+ else if (isValidPlace (targetPlacePos , 0 , 0 , -1 )) return mutable ;
321
+ }
322
+ case Above -> {
323
+ if (isValidPlace (targetPlacePos , 0 , 2 , 0 )) return mutable ;
324
+ }
325
+ case AboveAndBelow -> {
326
+ if (isValidPlace (targetPlacePos , 0 , - 1 , 0 )) return mutable ;
327
+ else if (isValidPlace (targetPlacePos , 0 , 2 , 0 )) return mutable ;
328
+ }
329
+ case Around -> {
330
+ if (isValidPlace (targetPlacePos , 0 , 0 , - 1 )) return mutable ;
331
+ else if (isValidPlace (targetPlacePos , 1 , 0 , 0 )) return mutable ;
332
+ else if (isValidPlace (targetPlacePos , - 1 , 0 , 0 )) return mutable ;
333
+ else if (isValidPlace (targetPlacePos , 0 , 0 , 1 )) return mutable ;
334
+ }
331
335
}
332
336
return null ;
333
337
}
334
338
339
+ @ Nullable
335
340
private BlockPos findBreakPos (BlockPos targetPos ) {
336
- if (isValidBreak (targetPos . down ())) return targetPos . down () ;
337
- else if (isValidBreak (targetPos . up ( 2 ))) return targetPos . up ( 2 ) ;
338
- else if (isValidBreak (targetPos . add ( 1 , 0 , 0 ))) return targetPos . add ( 1 , 0 , 0 ) ;
339
- else if (isValidBreak (targetPos . add ( -1 , 0 , 0 ))) return targetPos . add (- 1 , 0 , 0 ) ;
340
- else if (isValidBreak (targetPos . add ( 0 , 0 , 1 ))) return targetPos . add ( 0 , 0 , 1 ) ;
341
- else if (isValidBreak (targetPos . add ( 0 , 0 , -1 ))) return targetPos . add ( 0 , 0 , - 1 ) ;
342
- else if (isValidBreak (targetPos . add ( 1 , 1 , 0 ))) return targetPos . add ( 1 , 1 , 0 ) ;
343
- else if (isValidBreak (targetPos . add ( -1 , -1 , 0 ))) return targetPos . add (- 1 , - 1 , 0 ) ;
344
- else if (isValidBreak (targetPos . add ( 0 , 1 , 1 ))) return targetPos . add ( 0 , 1 , 1 ) ;
345
- else if (isValidBreak (targetPos . add ( 0 , 0 , -1 ))) return targetPos . add ( 0 , 0 , - 1 ) ;
341
+ if (isValidBreak (targetPos , 0 , - 1 , 0 )) return mutable ;
342
+ else if (isValidBreak (targetPos , 0 , 2 , 0 )) return mutable ;
343
+ else if (isValidBreak (targetPos , 1 , 0 , 0 )) return mutable ;
344
+ else if (isValidBreak (targetPos , -1 , 0 , 0 )) return mutable ;
345
+ else if (isValidBreak (targetPos , 0 , 0 , 1 )) return mutable ;
346
+ else if (isValidBreak (targetPos , 0 , 0 , -1 )) return mutable ;
347
+ else if (isValidBreak (targetPos , 1 , 1 , 0 )) return mutable ;
348
+ else if (isValidBreak (targetPos , -1 , -1 , 0 )) return mutable ;
349
+ else if (isValidBreak (targetPos , 0 , 1 , 1 )) return mutable ;
350
+ else if (isValidBreak (targetPos , 0 , 0 , -1 )) return mutable ;
346
351
return null ;
347
352
}
348
353
@@ -354,12 +359,14 @@ private boolean getDamageBreak(BlockPos pos) {
354
359
return breakMode .get () == Safety .Suicide || DamageUtils .anchorDamage (mc .player , pos .toCenterPos ()) <= maxDamage .get ();
355
360
}
356
361
357
- private boolean isValidPlace (BlockPos pos ) {
358
- return Math .sqrt (mc .player .getBlockPos ().getSquaredDistance (pos )) <= placeRange .get () && getDamagePlace (pos ) && BlockUtils .canPlace (pos , true );
362
+ private boolean isValidPlace (BlockPos origin , int xOffset , int yOffset , int zOffset ) {
363
+ BlockUtils .mutateAround (mutable , origin , xOffset , yOffset , zOffset );
364
+ return Math .sqrt (mc .player .getBlockPos ().getSquaredDistance (mutable )) <= placeRange .get () && getDamagePlace (mutable ) && BlockUtils .canPlace (mutable );
359
365
}
360
366
361
- private boolean isValidBreak (BlockPos pos ) {
362
- return mc .world .getBlockState (pos ).getBlock () == Blocks .RESPAWN_ANCHOR && Math .sqrt (mc .player .getBlockPos ().getSquaredDistance (pos )) <= breakRange .get () && getDamageBreak (pos );
367
+ private boolean isValidBreak (BlockPos origin , int xOffset , int yOffset , int zOffset ) {
368
+ BlockUtils .mutateAround (mutable , origin , xOffset , yOffset , zOffset );
369
+ return mc .world .getBlockState (mutable ).getBlock () == Blocks .RESPAWN_ANCHOR && Math .sqrt (mc .player .getBlockPos ().getSquaredDistance (mutable )) <= breakRange .get () && getDamageBreak (mutable );
363
370
}
364
371
365
372
private void breakAnchor (BlockPos pos , FindItemResult anchor , FindItemResult glowStone ) {
0 commit comments