forked from umerov1999/instagrabber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestingnew.java
1154 lines (930 loc) · 40.6 KB
/
testingnew.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client/).
* Copyright (c) 2021 Meteor Development.
*/
package meteordevelopment.meteorclient.systems.modules.combat;
import com.google.common.util.concurrent.AtomicDouble;
import it.unimi.dsi.fastutil.ints.*;
import meteordevelopment.meteorclient.events.entity.EntityAddedEvent;
import Xmeteordevelopment.meteorclient.events.entity.EntityRemovedEvent;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteoxarclient.events.render.Render2DEvent;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.mixininterface.IBox;
import meteordevelopment.meteorclient.mixininterface.IRaycastContext;
import meteordevelopment.meteorclient.mixininterface.IVec3d;
import meteordevelopment.meteorclient.renderer.ShapeMode;
import meteordevelopment.meteorclient.renderer.text.TextRenderer;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.friends.Friends;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
import meteordevelopment.meteorclient.utils.entity.Target;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerManager;
import meteordevelopment.meteorclient.utils.misc.Keybind;
import meteordevelopment.meteorclient.utils.misc.Vec3;
import meteordevelopment.meteorclient.utils.player.*;
import meteordevelopment.meteorclient.utils.render.NametagUtils;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.meteorclient.utils.world.BlockIterator;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import meteordevelopment.orbit.EventPriority;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.network.packet.c2s.play.*;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.*;
import net.minecraft.world.RaycastContext;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public class CrystalAura extends Module {
public enum YawStepMode {
Break,
All,
}
public enum AutoSwitchMode {
Normal,
Silent,
None
}
public enum SupportMode {
Disabled,
Accurate,
Fast
}
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final SettingGroup sgPlace = settings.createGroup("Place");
private final SettingGroup sgFacePlace = settings.createGroup("Face Place");
private final SettingGroup sgBreak = settings.createGroup("Break");
private final SettingGroup sgPause = settings.createGroup("Pause");
private final SettingGroup sgRender = settings.createGroup("Render");
// General
private final Setting<Double> targetRange = sgGeneral.add(new DoubleSetting.Builder()
.name("target-range")
.description("Range in which to target players.")
.defaultValue(10)
.min(0)
.sliderMax(16)
.build()
);
private final Setting<Boolean> predictMovement = sgGeneral.add(new BoolSetting.Builder()
.name("predict-movement")
.description("Predicts target movement.")
.defaultValue(false)
.build()
);
private final Setting<Boolean> ignoreTerrain = sgGeneral.add(new BoolSetting.Builder()
.name("ignore-terrain")
.description("Completely ignores terrain if it can be blown up by end crystals.")
.defaultValue(true)
.build()
);
private final Setting<Double> minDamage = sgGeneral.add(new DoubleSetting.Builder()
.name("min-damage")
.description("Minimum damage the crystal needs to deal to your target.")
.defaultValue(6)
.min(0)
.build()
);
private final Setting<Double> maxDamage = sgGeneral.add(new DoubleSetting.Builder()
.name("max-damage")
.description("Maximum damage crystals can deal to yourself.")
.defaultValue(6)
.min(0)
.max(36)
.sliderMax(36)
.build()
);
private final Setting<AutoSwitchMode> autoSwitch = sgGeneral.add(new EnumSetting.Builder<AutoSwitchMode>()
.name("auto-switch")
.description("Switches to crystals in your hotbar once a target is found.")
.defaultValue(AutoSwitchMode.Normal)
.build()
);
private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
.name("rotate")
.description("Rotates server-side towards the crystals being hit/placed.")
.defaultValue(true)
.build()
);
private final Setting<YawStepMode> yawStepMode = sgGeneral.add(new EnumSetting.Builder<YawStepMode>()
.name("yaw-steps-mode")
.description("When to run the yaw steps check.")
.defaultValue(YawStepMode.Break)
.visible(rotate::get)
.build()
);
private final Setting<Double> yawSteps = sgGeneral.add(new DoubleSetting.Builder()
.name("yaw-steps")
.description("Maximum number of degrees its allowed to rotate in one tick.")
.defaultValue(180)
.min(1)
.max(180)
.sliderMin(1)
.sliderMax(180)
.visible(rotate::get)
.build()
);
private final Setting<Boolean> antiSuicide = sgGeneral.add(new BoolSetting.Builder()
.name("anti-suicide")
.description("Will not place and break crystals if they will kill you.")
.defaultValue(true)
.build()
);
// Place
private final Setting<Boolean> doPlace = sgPlace.add(new BoolSetting.Builder()
.name("place")
.description("If the CA should place crystals.")
.defaultValue(true)
.build()
);
private final Setting<Integer> placeDelay = sgPlace.add(new IntSetting.Builder()
.name("place-delay")
.description("The delay in ticks to wait to place a crystal after it's exploded.")
.defaultValue(0)
.min(0)
.sliderMin(0)
.sliderMax(20)
.build()
);
private final Setting<Double> placeRange = sgPlace.add(new DoubleSetting.Builder()
.name("place-range")
.description("Range in which to place crystals.")
.defaultValue(4.5)
.min(0)
.sliderMax(6)
.build()
);
private final Setting<Double> placeWallsRange = sgPlace.add(new DoubleSetting.Builder()
.name("place-walls-range")
.description("Range in which to place crystals when behind blocks.")
.defaultValue(4.5)
.min(0)
.sliderMax(6)
.build()
);
private final Setting<Boolean> placement112 = sgPlace.add(new BoolSetting.Builder()
.name("1.12-placement")
.description("Uses 1.12 crystal placement.")
.defaultValue(false)
.build()
);
private final Setting<SupportMode> support = sgPlace.add(new EnumSetting.Builder<SupportMode>()
.name("support")
.description("Places a support block in air if no other position have been found.")
.defaultValue(SupportMode.Disabled)
.build()
);
private final Setting<Integer> supportDelay = sgPlace.add(new IntSetting.Builder()
.name("support-delay")
.description("Delay in ticks after placing support block.")
.defaultValue(1)
.min(0)
.visible(() -> support.get() != SupportMode.Disabled)
.build()
);
// Face place
private final Setting<Boolean> facePlace = sgFacePlace.add(new BoolSetting.Builder()
.name("face-place")
.description("Will face-place when target is below a certain health or armor durability threshold.")
.defaultValue(true)
.build()
);
private final Setting<Double> facePlaceHealth = sgFacePlace.add(new DoubleSetting.Builder()
.name("face-place-health")
.description("The health the target has to be at to start face placing.")
.defaultValue(8)
.min(1)
.sliderMin(1)
.sliderMax(36)
.visible(facePlace::get)
.build()
);
private final Setting<Double> facePlaceDurability = sgFacePlace.add(new DoubleSetting.Builder()
.name("face-place-durability")
.description("The durability threshold percentage to be able to face-place.")
.defaultValue(2)
.min(1)
.sliderMin(1)
.sliderMax(100)
.visible(facePlace::get)
.build()
);
private final Setting<Boolean> facePlaceArmor = sgFacePlace.add(new BoolSetting.Builder()
.name("face-place-missing-armor")
.description("Automatically starts face placing when a target misses a piece of armor.")
.defaultValue(false)
.visible(facePlace::get)
.build()
);
private final Setting<Keybind> forceFacePlace = sgFacePlace.add(new KeybindSetting.Builder()
.name("force-face-place")
.description("Starts face place when this button is pressed.")
.defaultValue(Keybind.none())
.build()
);
// Break
private final Setting<Boolean> doBreak = sgBreak.add(new BoolSetting.Builder()
.name("break")
.description("If the CA should break crystals.")
.defaultValue(true)
.build()
);
private final Setting<Integer> breakDelay = sgBreak.add(new IntSetting.Builder()
.name("break-delay")
.description("The delay in ticks to wait to break a crystal after it's placed.")
.defaultValue(0)
.min(0)
.sliderMin(0)
.sliderMax(20)
.build()
);
private final Setting<Boolean> smartDelay = sgBreak.add(new BoolSetting.Builder()
.name("smart-delay")
.description("Only breaks crystals when the target can receive damage.")
.defaultValue(false)
.build()
);
private final Setting<Integer> switchDelay = sgBreak.add(new IntSetting.Builder()
.name("switch-delay")
.description("The delay in ticks to wait to break a crystal after switching hotbar slot.")
.defaultValue(0)
.min(0)
.sliderMax(10)
.build()
);
private final Setting<Double> breakRange = sgBreak.add(new DoubleSetting.Builder()
.name("break-range")
.description("Range in which to break crystals.")
.defaultValue(4.5)
.min(0)
.sliderMax(6)
.build()
);
private final Setting<Double> breakWallsRange = sgBreak.add(new DoubleSetting.Builder()
.name("break-walls-range")
.description("Range in which to break crystals when behind blocks.")
.defaultValue(4.5)
.min(0)
.sliderMax(6)
.build()
);
private final Setting<Boolean> onlyBreakOwn = sgBreak.add(new BoolSetting.Builder()
.name("only-own")
.description("Only breaks own crystals.")
.defaultValue(false)
.build()
);
private final Setting<Integer> breakAttempts = sgBreak.add(new IntSetting.Builder()
.name("break-attempts")
.description("How many times to hit a crystal before stopping to target it.")
.defaultValue(2)
.sliderMin(1)
.sliderMax(5)
.build()
);
private final Setting<Integer> ticksExisted = sgBreak.add(new IntSetting.Builder()
.name("ticks-existed")
.description("Amount of ticks a crystal needs to have lived for it to be attacked by CrystalAura.")
.defaultValue(0)
.min(0)
.build()
);
private final Setting<Integer> attackFrequency = sgBreak.add(new IntSetting.Builder()
.name("attack-frequency")
.description("Maximum hits to do per second.")
.defaultValue(25)
.min(1)
.sliderMax(30)
.build()
);
private final Setting<Boolean> fastBreak = sgBreak.add(new BoolSetting.Builder()
.name("fast-break")
.description("Ignores break delay and tries to break the crystal as soon as it's spawned in the world.")
.defaultValue(true)
.build()
);
private final Setting<Boolean> antiWeakness = sgBreak.add(new BoolSetting.Builder()
.name("anti-weakness")
.description("Switches to tools with high enough damage to explode the crystal with weakness effect.")
.defaultValue(true)
.build()
);
// Pause
private final Setting<Boolean> eatPause = sgPause.add(new BoolSetting.Builder()
.name("pause-on-eat")
.description("Pauses Crystal Aura when eating.")
.defaultValue(true)
.build()
);
private final Setting<Boolean> drinkPause = sgPause.add(new BoolSetting.Builder()
.name("pause-on-drink")
.description("Pauses Crystal Aura when drinking.")
.defaultValue(true)
.build()
);
private final Setting<Boolean> minePause = sgPause.add(new BoolSetting.Builder()
.name("pause-on-mine")
.description("Pauses Crystal Aura when mining.")
.defaultValue(false)
.build()
);
// Render
private final Setting<Boolean> renderSwing = sgRender.add(new BoolSetting.Builder()
.name("swing")
.description("Renders hand swinging client side.")
.defaultValue(true)
.build()
);
private final Setting<Boolean> render = sgRender.add(new BoolSetting.Builder()
.name("render")
.description("Renders a block overlay over the block the crystals are being placed on.")
.defaultValue(true)
.build()
);
private final Setting<Boolean> renderBreak = sgRender.add(new BoolSetting.Builder()
.name("break")
.description("Renders a block overlay over the block the crystals are broken on.")
.defaultValue(false)
.build()
);
private final Setting<ShapeMode> shapeMode = sgRender.add(new EnumSetting.Builder<ShapeMode>()
.name("shape-mode")
.description("How the shapes are rendered.")
.defaultValue(ShapeMode.Both)
.build()
);
private final Setting<SettingColor> sideColor = sgRender.add(new ColorSetting.Builder()
.name("side-color")
.description("The side color of the block overlay.")
.defaultValue(new SettingColor(255, 255, 255, 45))
.build()
);
private final Setting<SettingColor> lineColor = sgRender.add(new ColorSetting.Builder()
.name("line-color")
.description("The line color of the block overlay.")
.defaultValue(new SettingColor(255, 255, 255, 255))
.build()
);
private final Setting<Boolean> renderDamageText = sgRender.add(new BoolSetting.Builder()
.name("damage")
.description("Renders crystal damage text in the block overlay.")
.defaultValue(true)
.build()
);
private final Setting<Double> damageTextScale = sgRender.add(new DoubleSetting.Builder()
.name("damage-scale")
.description("How big the damage text should be.")
.defaultValue(1.25)
.min(1)
.sliderMax(4)
.visible(renderDamageText::get)
.build()
);
private final Setting<Integer> renderTime = sgRender.add(new IntSetting.Builder()
.name("render-time")
.description("How long to render for.")
.defaultValue(10)
.min(0)
.sliderMax(20)
.build()
);
private final Setting<Integer> renderBreakTime = sgRender.add(new IntSetting.Builder()
.name("break-time")
.description("How long to render breaking for.")
.defaultValue(13)
.min(0)
.sliderMax(20)
.visible(renderBreak::get)
.build()
);
// Fields
private int breakTimer, placeTimer, switchTimer, ticksPassed;
private final List<PlayerEntity> targets = new ArrayList<>();
private final Vec3d vec3d = new Vec3d(0, 0, 0);
private final Vec3d playerEyePos = new Vec3d(0, 0, 0);
private final Vec3 vec3 = new Vec3();
private final BlockPos.Mutable blockPos = new BlockPos.Mutable();
private final Box box = new Box(0, 0, 0, 0, 0, 0);
private final Vec3d vec3dRayTraceEnd = new Vec3d(0, 0, 0);
private RaycastContext raycastContext;
private final IntSet placedCrystals = new IntOpenHashSet();
private boolean placing;
private int placingTimer;
private final BlockPos.Mutable placingCrystalBlockPos = new BlockPos.Mutable();
private final IntSet removed = new IntOpenHashSet();
private final Int2IntMap attemptedBreaks = new Int2IntOpenHashMap();
private final Int2IntMap waitingToExplode = new Int2IntOpenHashMap();
private int attacks;
private double serverYaw;
private PlayerEntity bestTarget;
private double bestTargetDamage;
private int bestTargetTimer;
private boolean didRotateThisTick;
private boolean isLastRotationPos;
private final Vec3d lastRotationPos = new Vec3d(0, 0 ,0);
private double lastYaw, lastPitch;
private int lastRotationTimer;
private int renderTimer, breakRenderTimer;
private final BlockPos.Mutable renderPos = new BlockPos.Mutable();
private final BlockPos.Mutable breakRenderPos = new BlockPos.Mutable();
private double renderDamage;
public CrystalAura() {
super(Categories.Combat, "crystal-aura", "Automatically places and attacks crystals.");
}
@Override
public void onActivate() {
breakTimer = 0;
placeTimer = 0;
ticksPassed = 0;
raycastContext = new RaycastContext(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
placing = false;
placingTimer = 0;
attacks = 0;
serverYaw = mc.player.getYaw();
bestTargetDamage = 0;
bestTargetTimer = 0;
lastRotationTimer = getLastRotationStopDelay();
renderTimer = 0;
breakRenderTimer = 0;
}
@Override
public void onDeactivate() {
targets.clear();
placedCrystals.clear();
attemptedBreaks.clear();
waitingToExplode.clear();
removed.clear();
bestTarget = null;
}
private int getLastRotationStopDelay() {
return Math.max(10, placeDelay.get() / 2 + breakDelay.get() / 2 + 10);
}
@EventHandler(priority = EventPriority.HIGH)
private void onPreTick(TickEvent.Pre event) {
// Update last rotation
didRotateThisTick = false;
lastRotationTimer++;
// Decrement placing timer
if (placing) {
if (placingTimer > 0) placingTimer--;
else placing = false;
}
if (ticksPassed < 20) ticksPassed++;
else {
ticksPassed = 0;
attacks = 0;
}
// Decrement best target timer
if (bestTargetTimer > 0) bestTargetTimer--;
bestTargetDamage = 0;
// Decrement break, place and switch timers
if (breakTimer > 0) breakTimer--;
if (placeTimer > 0) placeTimer--;
if (switchTimer > 0) switchTimer--;
// Decrement render timers
if (renderTimer > 0) renderTimer--;
if (breakRenderTimer > 0) breakRenderTimer--;
// Update waiting to explode crystals and mark them as existing if reached threshold
for (IntIterator it = waitingToExplode.keySet().iterator(); it.hasNext();) {
int id = it.nextInt();
int ticks = waitingToExplode.get(id);
if (ticks > 3) {
it.remove();
removed.remove(id);
}
else {
waitingToExplode.put(id, ticks + 1);
}
}
// Check pause settings
if (PlayerUtils.shouldPause(minePause.get(), eatPause.get(), drinkPause.get())) return;
// Set player eye pos
((IVec3d) playerEyePos).set(mc.player.getPos().x, mc.player.getPos().y + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getPos().z);
// Find targets, break and place
findTargets();
if (targets.size() > 0) {
if (!didRotateThisTick) doBreak();
if (!didRotateThisTick) doPlace();
}
}
@EventHandler(priority = EventPriority.LOWEST - 666)
private void onPreTickLast(TickEvent.Pre event) {
// Rotate to last rotation
if (rotate.get() && lastRotationTimer < getLastRotationStopDelay() && !didRotateThisTick) {
Rotations.rotate(isLastRotationPos ? Rotations.getYaw(lastRotationPos) : lastYaw, isLastRotationPos ? Rotations.getPitch(lastRotationPos) : lastPitch, -100, null);
}
}
@EventHandler
private void onEntityAdded(EntityAddedEvent event) {
if (!(event.entity instanceof EndCrystalEntity)) return;
if (placing && event.entity.getBlockPos().equals(placingCrystalBlockPos)) {
placing = false;
placingTimer = 0;
placedCrystals.add(event.entity.getId());
}
if (fastBreak.get() && !didRotateThisTick && attacks < attackFrequency.get()) {
double damage = getBreakDamage(event.entity, true);
if (damage > minDamage.get()) doBreak(event.entity);
}
}
@EventHandler
private void onEntityRemoved(EntityRemovedEvent event) {
if (event.entity instanceof EndCrystalEntity) {
placedCrystals.remove(event.entity.getId());
removed.remove(event.entity.getId());
waitingToExplode.remove(event.entity.getId());
}
}
private void setRotation(boolean isPos, Vec3d pos, double yaw, double pitch) {
didRotateThisTick = true;
isLastRotationPos = isPos;
if (isPos) ((IVec3d) lastRotationPos).set(pos.x, pos.y, pos.z);
else {
lastYaw = yaw;
lastPitch = pitch;
}
lastRotationTimer = 0;
}
// Break
private void doBreak() {
if (!doBreak.get() || breakTimer > 0 || switchTimer > 0 || attacks >= attackFrequency.get()) return;
double bestDamage = 0;
Entity crystal = null;
// Find best crystal to break
for (Entity entity : mc.world.getEntities()) {
double damage = getBreakDamage(entity, true);
if (damage > bestDamage) {
bestDamage = damage;
crystal = entity;
}
}
// Break the crystal
if (crystal != null) doBreak(crystal);
}
private double getBreakDamage(Entity entity, boolean checkCrystalAge) {
if (!(entity instanceof EndCrystalEntity)) return 0;
// Check only break own
if (onlyBreakOwn.get() && !placedCrystals.contains(entity.getId())) return 0;
// Check if it should already be removed
if (removed.contains(entity.getId())) return 0;
// Check attempted breaks
if (attemptedBreaks.get(entity.getId()) > breakAttempts.get()) return 0;
// Check crystal age
if (checkCrystalAge && entity.age < ticksExisted.get()) return 0;
// Check range
if (isOutOfRange(entity.getPos(), entity.getBlockPos(), false)) return 0;
// Check damage to self and anti suicide
blockPos.set(entity.getBlockPos()).move(0, -1, 0);
double selfDamage = DamageUtils.crystalDamage(mc.player, entity.getPos(), predictMovement.get(), blockPos, ignoreTerrain.get());
if (selfDamage > maxDamage.get() || (antiSuicide.get() && selfDamage >= EntityUtils.getTotalHealth(mc.player))) return 0;
// Check damage to targets and face place
double damage = getDamageToTargets(entity.getPos(), blockPos, true, false);
boolean facePlaced = (facePlace.get() && shouldFacePlace(entity.getBlockPos()) || forceFacePlace.get().isPressed());
if (!facePlaced && damage < minDamage.get()) return 0;
return damage;
}
private void doBreak(Entity crystal) {
// Anti weakness
if (antiWeakness.get()) {
StatusEffectInstance weakness = mc.player.getStatusEffect(StatusEffects.WEAKNESS);
StatusEffectInstance strength = mc.player.getStatusEffect(StatusEffects.STRENGTH);
// Check for strength
if (weakness != null && (strength == null || strength.getAmplifier() <= weakness.getAmplifier())) {
// Check if the item in your hand is already valid
if (!isValidWeaknessItem(mc.player.getMainHandStack())) {
// Find valid item to break with
if (!InvUtils.swap(InvUtils.findInHotbar(this::isValidWeaknessItem).getSlot(), false)) return;
switchTimer = 1;
return;
}
}
}
// Rotate and attack
boolean attacked = true;
if (rotate.get()) {
double yaw = Rotations.getYaw(crystal);
double pitch = Rotations.getPitch(crystal, Target.Feet);
if (doYawSteps(yaw, pitch)) {
setRotation(true, crystal.getPos(), 0, 0);
Rotations.rotate(yaw, pitch, 50, () -> attackCrystal(crystal));
breakTimer = breakDelay.get();
}
else {
attacked = false;
}
}
else {
attackCrystal(crystal);
breakTimer = breakDelay.get();
}
if (attacked) {
// Update state
removed.add(crystal.getId());
attemptedBreaks.put(crystal.getId(), attemptedBreaks.get(crystal.getId()) + 1);
waitingToExplode.put(crystal.getId(), 0);
// Break render
breakRenderPos.set(crystal.getBlockPos().down());
breakRenderTimer = renderBreakTime.get();
}
}
private boolean isValidWeaknessItem(ItemStack itemStack) {
if (!(itemStack.getItem() instanceof ToolItem) || itemStack.getItem() instanceof HoeItem) return false;
ToolMaterial material = ((ToolItem) itemStack.getItem()).getMaterial();
return material == ToolMaterials.DIAMOND || material == ToolMaterials.NETHERITE;
}
private void attackCrystal(Entity entity) {
// Attack
mc.player.networkHandler.sendPacket(PlayerInteractEntityC2SPacket.attack(entity, mc.player.isSneaking()));
Hand hand = InvUtils.findInHotbar(Items.END_CRYSTAL).getHand();
if (hand == null) hand = Hand.MAIN_HAND;
if (renderSwing.get()) mc.player.swingHand(hand);
else mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(hand));
attacks++;
}
@EventHandler
private void onPacketSend(PacketEvent.Send event) {
if (event.packet instanceof UpdateSelectedSlotC2SPacket) {
switchTimer = switchDelay.get();
}
}
// Place
private void doPlace() {
if (!doPlace.get() || placeTimer > 0) return;
// Return if there are no crystals in hotbar or offhand
if (!InvUtils.findInHotbar(Items.END_CRYSTAL).found()) return;
// Return if there are no crystals in either hand and auto switch mode is none
if (autoSwitch.get() == AutoSwitchMode.None && mc.player.getOffHandStack().getItem() != Items.END_CRYSTAL && mc.player.getMainHandStack().getItem() != Items.END_CRYSTAL) return;
// Check for multiplace
for (Entity entity : mc.world.getEntities()) {
if (getBreakDamage(entity, false) > 0) return;
}
// Setup variables
AtomicDouble bestDamage = new AtomicDouble(0);
AtomicReference<BlockPos.Mutable> bestBlockPos = new AtomicReference<>(new BlockPos.Mutable());
AtomicBoolean isSupport = new AtomicBoolean(support.get() != SupportMode.Disabled);
// Find best position to place the crystal on
BlockIterator.register((int) Math.ceil(placeRange.get()), (int) Math.ceil(placeRange.get()), (bp, blockState) -> {
// Check if its bedrock or obsidian and return if isSupport is false
boolean hasBlock = blockState.isOf(Blocks.BEDROCK) || blockState.isOf(Blocks.OBSIDIAN);
if (!hasBlock && (!isSupport.get() || !blockState.getMaterial().isReplaceable())) return;
// Check if there is air on top
blockPos.set(bp.getX(), bp.getY() + 1, bp.getZ());
if (!mc.world.getBlockState(blockPos).isAir()) return;
if (placement112.get()) {
blockPos.move(0, 1, 0);
if (!mc.world.getBlockState(blockPos).isAir()) return;
}
// Check range
((IVec3d) vec3d).set(bp.getX() + 0.5, bp.getY() + 1, bp.getZ() + 0.5);
blockPos.set(bp).move(0, 1, 0);
if (isOutOfRange(vec3d, blockPos, true)) return;
// Check damage to self and anti suicide
double selfDamage = DamageUtils.crystalDamage(mc.player, vec3d, predictMovement.get(), bp, ignoreTerrain.get());
if (selfDamage > maxDamage.get() || (antiSuicide.get() && selfDamage >= EntityUtils.getTotalHealth(mc.player))) return;
// Check damage to targets and face place
double damage = getDamageToTargets(vec3d, bp, false, !hasBlock && support.get() == SupportMode.Fast);
boolean facePlaced = (facePlace.get() && shouldFacePlace(blockPos)) || (forceFacePlace.get().isPressed());
if (!facePlaced && damage < minDamage.get()) return;
// Check if it can be placed
double x = bp.getX();
double y = bp.getY() + 1;
double z = bp.getZ();
((IBox) box).set(x, y, z, x + 1, y + (placement112.get() ? 1 : 2), z + 1);
if (intersectsWithEntities(box)) return;
// Compare damage
if (damage > bestDamage.get() || (isSupport.get() && hasBlock)) {
bestDamage.set(damage);
bestBlockPos.get().set(bp);
}
if (hasBlock) isSupport.set(false);
});
// Place the crystal
BlockIterator.after(() -> {
if (bestDamage.get() == 0) return;
BlockHitResult result = getPlaceInfo(bestBlockPos.get());
((IVec3d) vec3d).set(
result.getBlockPos().getX() + 0.5 + result.getSide().getVector().getX() * 1.0 / 2.0,
result.getBlockPos().getY() + 0.5 + result.getSide().getVector().getY() * 1.0 / 2.0,
result.getBlockPos().getZ() + 0.5 + result.getSide().getVector().getZ() * 1.0 / 2.0
);
if (rotate.get()) {
double yaw = Rotations.getYaw(vec3d);
double pitch = Rotations.getPitch(vec3d);
if (yawStepMode.get() == YawStepMode.Break || doYawSteps(yaw, pitch)) {
setRotation(true, vec3d, 0, 0);
Rotations.rotate(yaw, pitch, 50, () -> placeCrystal(result, bestDamage.get(), isSupport.get() ? bestBlockPos.get() : null));
placeTimer += placeDelay.get();
}
}
else {
placeCrystal(result, bestDamage.get(), isSupport.get() ? bestBlockPos.get() : null);
placeTimer += placeDelay.get();
}
});
}
private BlockHitResult getPlaceInfo(BlockPos blockPos) {
((IVec3d) vec3d).set(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
for (Direction side : Direction.values()) {
((IVec3d) vec3dRayTraceEnd).set(
blockPos.getX() + 0.5 + side.getVector().getX() * 0.5,
blockPos.getY() + 0.5 + side.getVector().getY() * 0.5,
blockPos.getZ() + 0.5 + side.getVector().getZ() * 0.5
);
((IRaycastContext) raycastContext).set(vec3d, vec3dRayTraceEnd, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
BlockHitResult result = mc.world.raycast(raycastContext);
if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(blockPos)) {
return result;
}
}
Direction side = blockPos.getY() > vec3d.y ? Direction.DOWN : Direction.UP;
return new BlockHitResult(vec3d, side, blockPos, false);
}
private void placeCrystal(BlockHitResult result, double damage, BlockPos supportBlock) {
// Switch
Item targetItem = supportBlock == null ? Items.END_CRYSTAL : Items.OBSIDIAN;
FindItemResult item = InvUtils.findInHotbar(targetItem);
if (!item.found()) return;
int prevSlot = mc.player.getInventory().selectedSlot;
if (autoSwitch.get() != AutoSwitchMode.None && !item.isOffhand()) InvUtils.swap(item.getSlot(), false);
Hand hand = item.getHand();
if (hand == null) return;
// Place
if (supportBlock == null) {
// Place crystal
mc.player.networkHandler.sendPacket(new PlayerInteractBlockC2SPacket(hand, result));
if (renderSwing.get()) mc.player.swingHand(hand);
else mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(hand));
placing = true;
placingTimer = 4;
placingCrystalBlockPos.set(result.getBlockPos()).move(0, 1, 0);
renderTimer = renderTime.get();
renderPos.set(result.getBlockPos());
renderDamage = damage;
}
else {
// Place support block
BlockUtils.place(supportBlock, item, false, 0, renderSwing.get(), true, false);
placeTimer += supportDelay.get();
if (supportDelay.get() == 0) placeCrystal(result, damage, null);
}
// Switch back
if (autoSwitch.get() == AutoSwitchMode.Silent) InvUtils.swap(prevSlot, false);
}
// Yaw steps
@EventHandler
private void onPacketSent(PacketEvent.Sent event) {
if (event.packet instanceof PlayerMoveC2SPacket) {
serverYaw = ((PlayerMoveC2SPacket) event.packet).getYaw((float) serverYaw);
}
}
public boolean doYawSteps(double targetYaw, double targetPitch) {
targetYaw = MathHelper.wrapDegrees(targetYaw) + 180;
double serverYaw = MathHelper.wrapDegrees(this.serverYaw) + 180;
if (distanceBetweenAngles(serverYaw, targetYaw) <= yawSteps.get()) return true;
double delta = Math.abs(targetYaw - serverYaw);
double yaw = this.serverYaw;
if (serverYaw < targetYaw) {
if (delta < 180) yaw += yawSteps.get();
else yaw -= yawSteps.get();
}
else {
if (delta < 180) yaw -= yawSteps.get();
else yaw += yawSteps.get();
}
setRotation(false, null, yaw, targetPitch);
Rotations.rotate(yaw, targetPitch, -100, null); // Priority -100 so it sends the packet as the last one, im pretty sure it doesn't matte but idc
return false;
}
private static double distanceBetweenAngles(double alpha, double beta) {
double phi = Math.abs(beta - alpha) % 360;