forked from cev-api/Wurst7-CevAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrialSpawnerEspHack.java
More file actions
1461 lines (1343 loc) · 45.9 KB
/
Copy pathTrialSpawnerEspHack.java
File metadata and controls
1461 lines (1343 loc) · 45.9 KB
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
/*
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Optional;
import java.util.UUID;
import java.util.Timer;
import java.util.TimerTask;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.Font.DisplayMode;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.VaultBlock;
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawner;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerConfig;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerState;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerStateData;
import net.minecraft.world.level.block.entity.vault.VaultBlockEntity;
import net.minecraft.world.level.block.entity.vault.VaultState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.wurstclient.Category;
import net.wurstclient.events.CameraTransformViewBobbingListener;
import net.wurstclient.events.CameraTransformViewBobbingListener.CameraTransformViewBobbingEvent;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.mixin.TrialSpawnerDataAccessor;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.ItemUtils;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RenderUtils.ColoredBox;
import net.wurstclient.util.RenderUtils.ColoredPoint;
import net.wurstclient.nicewurst.NiceWurstModule;
import net.wurstclient.util.chunk.ChunkUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
public final class TrialSpawnerEspHack extends Hack
implements UpdateListener, CameraTransformViewBobbingListener,
RenderListener, net.wurstclient.events.RightClickListener
{
private final SliderSetting maxDistance =
new SliderSetting("Max distance", 160, 0, 256, 1, ValueDisplay.INTEGER);
private final CheckboxSetting drawTracers =
new CheckboxSetting("Show tracer", false);
private final CheckboxSetting tracerFlash = new CheckboxSetting(
"Tracer flash", "Make tracers pulse with a smooth fade.", false);
private final CheckboxSetting fillShapes =
new CheckboxSetting("Fill boxes", true);
private final CheckboxSetting showOverlay =
new CheckboxSetting("Text overlay", true);
private final SliderSetting overlayScale = new SliderSetting(
"Overlay scale", 0.5, 0.5, 2.0, 0.05, ValueDisplay.DECIMAL);
private final CheckboxSetting showMobType =
new CheckboxSetting("Show mob type", true);
private final CheckboxSetting showStatus =
new CheckboxSetting("Show status", true);
// removed wave info setting (simplified status display)
private final CheckboxSetting showNextSpawn =
new CheckboxSetting("Show next wave", true);
private final CheckboxSetting showCooldown =
new CheckboxSetting("Show cooldown", true);
private final CheckboxSetting markOnApproach =
new CheckboxSetting("Mark on approach", false);
private final SliderSetting approachRange =
new SliderSetting("Approach range", 4, 1, 16, 1, ValueDisplay.INTEGER);
// spawn tracers removed
private final ColorSetting vaultBoxColor =
new ColorSetting("Vault box color", new Color(0xFF7CF2C9));
private final ColorSetting ominousVaultBoxColor =
new ColorSetting("Ominous vault color", new Color(0xFF9B59B6));
private final CheckboxSetting showDistance =
new CheckboxSetting("Show distance", true);
private final CheckboxSetting showTrialType =
new CheckboxSetting("Show trial type", true);
private final CheckboxSetting showActivationRadius =
new CheckboxSetting("Show activation radius", true);
private final CheckboxSetting showVaultLink =
new CheckboxSetting("Show vault link", false);
private final CheckboxSetting onlyVaults =
new CheckboxSetting("Only vaults", false);
private final SliderSetting vaultLinkRange = new SliderSetting(
"Vault link range", 48, 8, 96, 1, ValueDisplay.INTEGER);
private final CheckboxSetting alertOminousKey = new CheckboxSetting(
"Ominous key alert",
"Alerts in chat when an ominous trial key item appears near a trial spawner.",
false);
private final CheckboxSetting alertOminousKeySound = new CheckboxSetting(
"Ominous key sound",
"Plays a sound when an ominous trial key item is detected near a trial spawner.",
false);
private final SliderSetting ominousKeySoundVolume =
new SliderSetting("Ominous key sound volume", 100, 0, 200, 1,
ValueDisplay.INTEGER.withSuffix("%"));
private final CheckboxSetting showCountInHackList =
new CheckboxSetting("HackList count", false);
private final ColorSetting colorIdle =
new ColorSetting("Idle color", new Color(0xFFAAAAAA));
private final ColorSetting colorCharging =
new ColorSetting("Charging color", new Color(0xFFF4C542));
private final ColorSetting colorActive =
new ColorSetting("Active color", new Color(0xFFE5534B));
private final ColorSetting colorCompleted =
new ColorSetting("Completed color", new Color(0xFF51C271));
private final ColorSetting radiusColor =
new ColorSetting("Radius color", new Color(0xFF66B3FF));
private final ColorSetting vaultLinkColor =
new ColorSetting("Vault link color", new Color(0xFF7CF2C9));
private final ArrayList<TrialSpawnerInfo> spawners = new ArrayList<>();
private final ArrayList<VaultInfo> vaults = new ArrayList<>();
private final HashSet<String> openedVaultKeys = new HashSet<>();
private final HashSet<UUID> alertedOminousKeys = new HashSet<>();
private boolean openedVaultsLoaded = false;
private final java.util.Set<String> approachScheduledKeys =
new java.util.HashSet<>();
private final Timer approachTimer = new Timer(true);
private static final Gson GSON =
new GsonBuilder().setPrettyPrinting().create();
// predicted cooldown end ticks for spawners when we observe the transition
private final Map<BlockPos, Long> predictedCooldownEnds = new HashMap<>();
// previous known states to detect transitions
private final Map<BlockPos, TrialSpawnerState> prevStates = new HashMap<>();
private int foundCount;
private final CheckboxSetting estimateCooldownOnTransition =
new CheckboxSetting("Estimate cooldown when observed", true);
public TrialSpawnerEspHack()
{
super("TrialSpawnerESP");
setCategory(Category.RENDER);
addSetting(maxDistance);
addSetting(drawTracers);
addSetting(tracerFlash);
addSetting(fillShapes);
addSetting(showOverlay);
addSetting(overlayScale);
addSetting(showMobType);
addSetting(showStatus);
addSetting(showNextSpawn);
addSetting(showCooldown);
addSetting(markOnApproach);
addSetting(approachRange);
// spawn tracers removed
addSetting(estimateCooldownOnTransition);
addSetting(showDistance);
addSetting(showTrialType);
addSetting(showActivationRadius);
addSetting(showVaultLink);
addSetting(onlyVaults);
addSetting(vaultLinkRange);
addSetting(alertOminousKey);
addSetting(alertOminousKeySound);
addSetting(ominousKeySoundVolume);
addSetting(vaultBoxColor);
addSetting(ominousVaultBoxColor);
addSetting(showCountInHackList);
addSetting(colorIdle);
addSetting(colorCharging);
addSetting(colorActive);
addSetting(colorCompleted);
addSetting(radiusColor);
addSetting(vaultLinkColor);
}
@Override
protected void onEnable()
{
EVENTS.add(UpdateListener.class, this);
EVENTS.add(CameraTransformViewBobbingListener.class, this);
EVENTS.add(RenderListener.class, this);
EVENTS.add(net.wurstclient.events.RightClickListener.class, this);
}
@Override
protected void onDisable()
{
EVENTS.remove(UpdateListener.class, this);
EVENTS.remove(CameraTransformViewBobbingListener.class, this);
EVENTS.remove(RenderListener.class, this);
EVENTS.remove(net.wurstclient.events.RightClickListener.class, this);
spawners.clear();
vaults.clear();
foundCount = 0;
// reset opened vaults load state so they are reloaded on next world
openedVaultsLoaded = false;
openedVaultKeys.clear();
alertedOminousKeys.clear();
}
@Override
public void onUpdate()
{
spawners.clear();
if(MC.level == null || MC.player == null)
{
vaults.clear();
foundCount = 0;
return;
}
// load opened vaults for current server once
if(!openedVaultsLoaded)
{
loadOpenedVaults();
openedVaultsLoaded = true;
}
vaults.clear();
ChunkUtils.getLoadedBlockEntities()
.filter(be -> be instanceof VaultBlockEntity)
.map(be -> (VaultBlockEntity)be).forEach(be -> {
BlockPos vpos = be.getBlockPos().immutable();
vaults.add(new VaultInfo(vpos));
// detect ominous vaults that have been opened / ejected
if(MC.level != null)
{
BlockState state = MC.level.getBlockState(vpos);
if(state.is(Blocks.VAULT)
&& state.hasProperty(VaultBlock.OMINOUS)
&& state.getValue(VaultBlock.OMINOUS))
{
if(state.hasProperty(VaultBlock.STATE))
{
VaultState vs = state.getValue(VaultBlock.STATE);
// treat any non-INACTIVE /
// ejecting/unlocking/active as opened
if(vs == VaultState.EJECTING)
{
String dim = "unknown";
try
{
if(MC != null && MC.level != null)
dim = MC.level.dimension().identifier()
.toString();
}catch(Throwable ignored)
{}
String key = dim + "|" + vpos.getX() + ","
+ vpos.getY() + "," + vpos.getZ();
if(openedVaultKeys.add(key))
saveOpenedVaults();
}
}
}
}
});
boolean limit = maxDistance.getValue() > 0;
double maxDistanceSq = maxDistance.getValue() * maxDistance.getValue();
// schedule approach-based checks for ominous vaults
if(markOnApproach.isChecked())
{
double range = approachRange.getValue();
double rangeSq = range * range;
for(VaultInfo v : vaults)
{
BlockPos vpos = v.pos();
String dim = "unknown";
try
{
if(MC != null && MC.level != null)
dim = MC.level.dimension().identifier().toString();
}catch(Throwable ignored)
{}
String key = dim + "|" + vpos.getX() + "," + vpos.getY() + ","
+ vpos.getZ();
if(openedVaultKeys.contains(key)
|| approachScheduledKeys.contains(key))
continue;
if(MC.player.distanceToSqr(vpos.getX() + 0.5, vpos.getY() + 0.5,
vpos.getZ() + 0.5) <= rangeSq)
{
BlockState state = MC.level.getBlockState(vpos);
VaultState prev = state.hasProperty(VaultBlock.STATE)
? state.getValue(VaultBlock.STATE) : null;
// make final copies for inner class
final VaultState prevFinal = prev;
final String keyFinal = key;
final BlockPos vposFinal = vpos;
approachScheduledKeys.add(keyFinal);
approachTimer.schedule(new TimerTask()
{
@Override
public void run()
{
MC.execute(() -> {
try
{
if(MC.level == null)
return;
BlockState after =
MC.level.getBlockState(vposFinal);
VaultState afterState =
after.hasProperty(VaultBlock.STATE)
? after.getValue(VaultBlock.STATE)
: null;
boolean prevIdle = prevFinal == null
|| prevFinal == VaultState.INACTIVE;
if(prevIdle && ((afterState == null
&& prevFinal == null)
|| (afterState == prevFinal)))
{
// unchanged and was idle -> assume
// already opened/locked
if(openedVaultKeys.add(keyFinal))
saveOpenedVaults();
}
}catch(Throwable ignored)
{}finally
{
approachScheduledKeys.remove(keyFinal);
}
});
}
}, 1500L);
}
}
}
// When only-vaults is enabled, skip scanning spawners entirely
if(!onlyVaults.isChecked())
ChunkUtils.getLoadedBlockEntities()
.filter(be -> be instanceof TrialSpawnerBlockEntity)
.map(be -> (TrialSpawnerBlockEntity)be).forEach(spawner -> {
BlockPos pos = spawner.getBlockPos();
double distSq = MC.player.distanceToSqr(pos.getX() + 0.5,
pos.getY() + 0.5, pos.getZ() + 0.5);
if(limit && distSq > maxDistanceSq)
return;
BlockPos immutablePos = pos.immutable();
VaultInfo link = showVaultLink.isChecked()
? findLinkedVault(immutablePos) : null;
String decorMob = detectMobFromDecor(immutablePos);
spawners.add(new TrialSpawnerInfo(spawner, immutablePos,
distSq, link, decorMob));
});
foundCount = onlyVaults.isChecked() ? vaults.size() : spawners.size();
if(alertOminousKey.isChecked())
alertIfOminousKeyNearby();
// detect transitions and predict cooldown end when configured
if(MC.level != null && estimateCooldownOnTransition.isChecked())
{
long worldTime = MC.level.getGameTime();
for(TrialSpawnerInfo info : spawners)
{
var be = info.blockEntity();
if(be == null || be.isRemoved() || be.getLevel() != MC.level)
continue;
TrialSpawner logic = be.getTrialSpawner();
if(logic == null)
continue;
TrialSpawnerState state = logic.getState() == null
? TrialSpawnerState.INACTIVE : logic.getState();
TrialSpawnerStateData data = logic.getStateData();
long cooldownEnd = 0;
if(data != null)
{
TrialSpawnerDataAccessor acc =
(TrialSpawnerDataAccessor)data;
cooldownEnd = acc.getCooldownEnd();
}
BlockPos pos = info.pos();
TrialSpawnerState prev = prevStates.get(pos);
// if we observed it go from ACTIVE to non-ACTIVE and there's no
// server cooldown
if(prev == TrialSpawnerState.ACTIVE
&& state != TrialSpawnerState.ACTIVE
&& cooldownEnd <= worldTime)
{
long predicted =
worldTime + logic.getTargetCooldownLength();
predictedCooldownEnds.put(pos, predicted);
}
// if server set a cooldown, prefer that and remove any
// prediction
if(cooldownEnd > worldTime)
predictedCooldownEnds.remove(pos);
// update previous state
prevStates.put(pos, state);
}
// cleanup expired predictions
predictedCooldownEnds.entrySet()
.removeIf(e -> e.getValue() <= MC.level.getGameTime());
}
}
@Override
public void onCameraTransformViewBobbing(
CameraTransformViewBobbingEvent event)
{
if(drawTracers.isChecked() || showOverlay.isChecked())
event.cancel();
}
@Override
public void onRightClick(
net.wurstclient.events.RightClickListener.RightClickEvent event)
{
if(MC == null || MC.level == null || MC.player == null)
return;
var hit = MC.hitResult;
if(!(hit instanceof net.minecraft.world.phys.BlockHitResult bhr))
return;
BlockPos pos = bhr.getBlockPos();
BlockState state = MC.level.getBlockState(pos);
if(!state.is(Blocks.VAULT))
return;
// remember initial state and schedule a check after 1.5s
VaultState before = state.hasProperty(VaultBlock.STATE)
? state.getValue(VaultBlock.STATE) : null;
String dim = "unknown";
try
{
if(MC.level != null)
dim = MC.level.dimension().identifier().toString();
}catch(Throwable ignored)
{}
// make final copies for inner class
final VaultState beforeFinal = before;
final String dimFinal = dim;
final BlockPos posFinal = pos;
TimerTask task = new TimerTask()
{
@Override
public void run()
{
MC.execute(() -> {
try
{
if(MC.level == null)
return;
BlockState after = MC.level.getBlockState(posFinal);
VaultState afterState =
after.hasProperty(VaultBlock.STATE)
? after.getValue(VaultBlock.STATE) : null;
// Only mark as opened if the vault was idle/inactive
// when we checked and the state stayed unchanged. If it
// was ACTIVE (mouth opened) or transitioned to
// ACTIVE/EJECTING, do not mark.
boolean beforeIdle = beforeFinal == null
|| beforeFinal == VaultState.INACTIVE;
if(beforeIdle
&& ((afterState == null && beforeFinal == null)
|| (afterState == beforeFinal)))
{
String key = dimFinal + "|" + posFinal.getX() + ","
+ posFinal.getY() + "," + posFinal.getZ();
if(openedVaultKeys.add(key))
saveOpenedVaults();
}
}catch(Throwable ignored)
{}
});
}
};
new Timer(true).schedule(task, 1500);
}
@Override
public void onRender(PoseStack matrices, float partialTicks)
{
if(MC.level == null)
return;
ArrayList<ColoredBox> outlineBoxes = new ArrayList<>();
ArrayList<ColoredBox> filledBoxes =
fillShapes.isChecked() ? new ArrayList<>() : null;
ArrayList<ColoredPoint> tracerTargets =
drawTracers.isChecked() ? new ArrayList<>() : null;
ArrayList<OverlayEntry> overlays = new ArrayList<>();
// Render vault ESP boxes and simple status labels while hack is enabled
if(!vaults.isEmpty())
{
for(VaultInfo v : vaults)
{
BlockPos vpos = v.pos();
BlockState vstate = MC.level.getBlockState(vpos);
int vcolor = vaultBoxColor.getColorI();
boolean ominous = vstate.hasProperty(VaultBlock.OMINOUS)
&& vstate.getValue(VaultBlock.OMINOUS);
if(ominous)
vcolor = ominousVaultBoxColor.getColorI();
// if we know this ominous vault was opened before, mark it
// differently
String dim = "unknown";
try
{
if(MC != null && MC.level != null)
dim = MC.level.dimension().identifier().toString();
}catch(Throwable ignored)
{}
String key = dim + "|" + vpos.getX() + "," + vpos.getY() + ","
+ vpos.getZ();
if(ominous && openedVaultKeys.contains(key))
{
// darken color to indicate opened
vcolor = mixWithWhite(vcolor, 0.6F);
}
AABB vbox = new AABB(vpos);
outlineBoxes.add(new ColoredBox(vbox, vcolor));
if(filledBoxes != null)
filledBoxes
.add(new ColoredBox(vbox, withAlpha(vcolor, 0.18F)));
// show simple status label above the vault
String status = describeVaultState(vstate);
ArrayList<OverlayLine> lines = new ArrayList<>();
lines.add(new OverlayLine("Vault", vcolor));
lines.add(new OverlayLine(status, 0xFFFFFFFF));
if(ominous && openedVaultKeys.contains(key))
lines.add(new OverlayLine("Opened", 0xFFDD4444));
Vec3 original = Vec3.atCenterOf(vpos).add(0, 1.0, 0);
Vec3 resolved = resolveLabelPosition(original);
overlays.add(new OverlayEntry(original, resolved, lines,
overlayScale.getValueF()));
}
}
if(!onlyVaults.isChecked())
for(TrialSpawnerInfo info : spawners)
{
TrialSpawnerBlockEntity be = info.blockEntity();
if(be == null || be.isRemoved() || be.getLevel() != MC.level)
continue;
TrialSpawner logic = be.getTrialSpawner();
if(logic == null)
continue;
TrialSpawnerState state = logic.getState() == null
? TrialSpawnerState.INACTIVE : logic.getState();
TrialStatus status = TrialStatus.fromState(state);
int color = getColorForStatus(status);
AABB box = new AABB(info.pos());
outlineBoxes.add(new ColoredBox(box, color));
if(filledBoxes != null)
filledBoxes
.add(new ColoredBox(box, withAlpha(color, 0.18F)));
if(tracerTargets != null)
{
int tracerColor = color;
if(tracerFlash.isChecked())
tracerColor = RenderUtils.flashColor(tracerColor);
tracerTargets.add(new ColoredPoint(
Vec3.atCenterOf(info.pos()), tracerColor));
}
if(showActivationRadius.isChecked())
drawActivationRadius(matrices, info, logic, color);
if(showVaultLink.isChecked() && info.vault() != null)
drawVaultLink(matrices, info, color, overlays);
// spawn tracers removed
if(showOverlay.isChecked())
drawOverlay(matrices, info, logic, state, color, overlays);
}
if(filledBoxes != null && !filledBoxes.isEmpty())
RenderUtils.drawSolidBoxes(matrices, filledBoxes, false);
if(!outlineBoxes.isEmpty())
RenderUtils.drawOutlinedBoxes(matrices, outlineBoxes, false);
if(tracerTargets != null && !tracerTargets.isEmpty())
RenderUtils.drawTracers(matrices, partialTicks, tracerTargets,
false);
// draw overlays after all ESP geometry so labels are not overwritten
java.util.HashSet<BlockPos> drawn = new java.util.HashSet<>();
for(OverlayEntry e : overlays)
{
if(!NiceWurstModule.shouldRenderTarget(e.original()))
continue;
BlockPos key = BlockPos.containing(e.original());
if(drawn.contains(key))
continue;
drawn.add(key);
drawLabel(matrices, e.resolved(), e.lines(), e.scale());
}
}
private void drawActivationRadius(PoseStack matrices, TrialSpawnerInfo info,
TrialSpawner logic, int stateColor)
{
int radius = logic.getRequiredPlayerRange();
if(radius <= 0)
return;
Vec3 center = Vec3.atCenterOf(info.pos()).add(0, 0.05, 0);
double radiusSq = radius * radius;
Vec3 playerPos = MC.player == null ? null
: new Vec3(MC.player.getX(), MC.player.getY(), MC.player.getZ());
boolean inside =
playerPos != null && playerPos.distanceToSqr(center) <= radiusSq;
int color = withAlpha(
inside ? mixWithWhite(stateColor, 0.35F) : radiusColor.getColorI(),
inside ? 0.65F : 0.35F);
int segments = Math.max(32, radius * 12);
RenderUtils.drawCircle(matrices, center, radius, segments, color,
false);
}
private void drawVaultLink(PoseStack matrices, TrialSpawnerInfo info,
int stateColor, ArrayList<OverlayEntry> overlays)
{
if(MC.level == null || info.vault() == null)
return;
BlockPos vaultPos = info.vault().pos();
Vec3 start = Vec3.atCenterOf(info.pos());
Vec3 end = Vec3.atCenterOf(vaultPos).add(0, 0.25, 0);
int color = vaultLinkColor.getColorI();
RenderUtils.drawLine(matrices, start, end, color, false);
BlockState state = MC.level.getBlockState(vaultPos);
if(!state.is(Blocks.VAULT))
return;
String status = describeVaultState(state);
List<OverlayLine> lines = List.of(new OverlayLine("Vault", stateColor),
new OverlayLine(status, color));
Vec3 original = end.add(0, 0.6, 0);
Vec3 resolved = resolveLabelPosition(original);
overlays.add(new OverlayEntry(original, resolved, lines,
overlayScale.getValueF()));
}
private void drawOverlay(PoseStack matrices, TrialSpawnerInfo info,
TrialSpawner logic, TrialSpawnerState state, int headerColor,
ArrayList<OverlayEntry> overlays)
{
if(MC.level == null)
return;
TrialSpawnerStateData data = logic.getStateData();
if(data == null)
return;
TrialSpawnerDataAccessor accessor = (TrialSpawnerDataAccessor)data;
long worldTime = MC.level.getGameTime();
long cooldownTicks = accessor.getCooldownEnd() - worldTime;
double cooldownSeconds = Math.max(0, cooldownTicks / 20.0);
boolean cooldownEstimated = false;
// if server did not set a cooldown, check predicted values we observed
if(cooldownTicks <= 0 && estimateCooldownOnTransition.isChecked())
{
Long predicted = predictedCooldownEnds.get(info.pos());
if(predicted != null && predicted > worldTime)
{
cooldownSeconds = Math.max(0, (predicted - worldTime) / 20.0);
cooldownEstimated = true;
}
}
long nextSpawnTicks = accessor.getNextMobSpawnsAt() - worldTime;
double nextSpawnSeconds = Math.max(0, nextSpawnTicks / 20.0);
// Avoid vanilla spam when the spawner has no detected players.
int additionalPlayers = 0;
TrialSpawnerConfig config = logic.activeConfig();
int totalMobs =
Math.max(1, config.calculateTargetTotalMobs(additionalPlayers));
int simultaneous = Math.max(1,
config.calculateTargetSimultaneousMobs(additionalPlayers));
int trackedSpawned =
Mth.clamp(accessor.getTotalSpawnedMobs(), 0, totalMobs);
Set<UUID> aliveSet = accessor.getSpawnedMobsAlive();
int aliveFromData =
aliveSet == null ? 0 : Math.min(aliveSet.size(), totalMobs);
int totalWaves =
Math.max(1, (int)Math.ceil(totalMobs / (double)simultaneous));
String decorMob = info.decorMob() == null ? "" : info.decorMob();
String spawnId = readMobId(data.getUpdateTag(state));
String resolvedMob = resolveMobName(spawnId);
String mobName = !decorMob.isEmpty() ? decorMob
: (resolvedMob == null ? "" : resolvedMob);
if(mobName.isEmpty())
mobName = "Unknown";
EntityType<?> mobType = resolveEntityType(spawnId, decorMob);
int aliveFromWorld =
countWorldMobs(info.pos(), logic, mobType, mobName);
int alive = Math.max(aliveFromWorld, aliveFromData);
if(trackedSpawned <= 0 && alive > 0)
trackedSpawned = alive;
int mobsProgress =
Mth.clamp(Math.max(trackedSpawned, alive), 0, totalMobs);
int currentWave = Mth.clamp(
(int)Math.ceil(Math.max(1, mobsProgress) / (double)simultaneous),
mobsProgress > 0 ? 1 : 0, totalWaves);
String trialType = describeTrialType(mobName, spawnId);
TrialStatus status = TrialStatus.fromState(state);
String statusLine = describeStatus(status);
ArrayList<OverlayLine> lines = new ArrayList<>();
String title =
logic.isOminous() ? "Ominous Trial Spawner" : "Trial Spawner";
lines.add(new OverlayLine(title, headerColor));
if(showMobType.isChecked())
lines.add(new OverlayLine("Mob: " + mobName, 0xFFFFFFFF));
if(showStatus.isChecked())
lines.add(new OverlayLine("Status: " + statusLine, 0xFFFFFFFF));
if(alive > 0)
lines.add(new OverlayLine("Active mobs: " + alive, 0xFFFFFFFF));
// removed wave info display (keeps overlay simple)
if(showNextSpawn.isChecked() && state == TrialSpawnerState.ACTIVE)
{
String next = "Next: " + simultaneous + "x " + mobName + " in "
+ formatSeconds(nextSpawnSeconds);
lines.add(new OverlayLine(next, 0xFFFFFFFF));
}
if(showCooldown.isChecked() && cooldownSeconds > 0)
{
String prefix =
cooldownEstimated ? "Cooldown (est): " : "Cooldown: ";
lines.add(new OverlayLine(prefix + formatSeconds(cooldownSeconds),
0xFFFFFFFF));
}
// raw timer debug removed
if(showTrialType.isChecked())
lines.add(new OverlayLine("Trial: " + trialType, 0xFFFFFFFF));
if(showDistance.isChecked())
{
double meters = Math.sqrt(info.distanceSq());
lines.add(new OverlayLine("Distance: " + Math.round(meters) + "m",
0xFFFFFFFF));
}
if(showVaultLink.isChecked() && info.vault() != null)
{
String vaultInfo =
describeVaultState(MC.level.getBlockState(info.vault().pos()));
lines.add(new OverlayLine("Vault: " + vaultInfo, 0xFFFFFFFF));
}
Vec3 original = Vec3.atCenterOf(info.pos()).add(0, 1.6, 0);
Vec3 resolved = resolveLabelPosition(original);
overlays.add(new OverlayEntry(original, resolved, lines,
overlayScale.getValueF()));
}
private void drawLabel(PoseStack matrices, Vec3 position,
List<OverlayLine> lines, float scale)
{
if(lines.isEmpty() || MC.font == null)
return;
matrices.pushPose();
Vec3 cam = RenderUtils.getCameraPos();
Vec3 dir = position.subtract(cam);
double dist = dir.length();
double lx = position.x;
double ly = position.y;
double lz = position.z;
if(dist > 1.0)
{
double anchor = Math.min(dist, 12.0);
Vec3 anchored = cam.add(dir.scale(anchor / dist));
lx = anchored.x;
ly = anchored.y;
lz = anchored.z;
}
matrices.translate(lx - cam.x, ly - cam.y, lz - cam.z);
var camEntity = MC.getCameraEntity();
if(camEntity != null)
{
matrices.mulPose(Axis.YP.rotationDegrees(-camEntity.getYRot()));
matrices.mulPose(Axis.XP.rotationDegrees(camEntity.getXRot()));
}
matrices.mulPose(Axis.YP.rotationDegrees(180));
float s = 0.025F * RenderUtils.getCappedWorldLabelScale(scale, dist);
matrices.scale(s, -s, s);
Font tr = MC.font;
int bg = (int)(MC.options.getBackgroundOpacity(0.25F) * 255) << 24;
int lineHeight = tr.lineHeight + 2;
int maxWidth = 0;
for(OverlayLine line : lines)
maxWidth = Math.max(maxWidth, tr.width(line.text()));
int x = -maxWidth / 2;
DisplayMode layerType =
NiceWurstModule.enforceTextLayer(DisplayMode.SEE_THROUGH);
for(int i = 0; i < lines.size(); i++)
{
OverlayLine line = lines.get(i);
int y = i * lineHeight;
net.wurstclient.util.RenderUtils.drawTextInBatch(tr, line.text(), x,
y, line.color(), false, matrices.last().pose(), null, layerType,
bg, 0xF000F0);
}
matrices.popPose();
}
private Vec3 resolveLabelPosition(Vec3 target)
{
Vec3 cam = RenderUtils.getCameraPos();
double distance = cam.distanceTo(target);
double anchor = 12;
if(distance <= anchor)
return target;
Vec3 dir = target.subtract(cam);
double len = dir.length();
if(len < 1e-4)
return target;
return cam.add(dir.scale(anchor / len));
}
private VaultInfo findLinkedVault(BlockPos spawnerPos)
{
if(vaults.isEmpty())
return null;
double maxRangeSq =
vaultLinkRange.getValue() * vaultLinkRange.getValue();
VaultInfo closest = null;
double best = maxRangeSq;
for(VaultInfo info : vaults)
{
double distSq = info.pos().distSqr(spawnerPos);
if(distSq <= best)
{
closest = info;
best = distSq;
}
}
return closest;
}
private void loadOpenedVaults()
{
String server = null;
try
{
if(MC != null && MC.getCurrentServer() != null)
server = MC.getCurrentServer().ip;
}catch(Throwable ignored)
{}
String name = sanitizeServer(server);
File dir = new File("config/wurst/opened_vaults");
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, name + ".json");
if(!file.isFile())
return;
try(FileReader r = new FileReader(file))
{
JsonObject root = GSON.fromJson(r, JsonObject.class);
JsonArray arr = root.getAsJsonArray("openedPositions");
if(arr == null)
return;
for(var el : arr)
{
try
{
JsonObject o = el.getAsJsonObject();
int x = o.get("x").getAsInt();
int y = o.get("y").getAsInt();
int z = o.get("z").getAsInt();
String dim = null;
if(o.has("dimension"))
dim = o.get("dimension").getAsString();
if(dim == null)
{
try
{
if(MC != null && MC.level != null)
dim = MC.level.dimension().identifier()
.toString();
}catch(Throwable ignored)
{}
if(dim == null)
dim = "unknown";
}
String key = dim + "|" + x + "," + y + "," + z;
openedVaultKeys.add(key);
}catch(Throwable ignored)
{}
}
}catch(Throwable ignored)
{}
}
private void saveOpenedVaults()
{
String server = null;
try
{
if(MC != null && MC.getCurrentServer() != null)
server = MC.getCurrentServer().ip;
}catch(Throwable ignored)
{}
String name = sanitizeServer(server);
File dir = new File("config/wurst/opened_vaults");
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, name + ".json");
JsonObject root = new JsonObject();
JsonArray arr = new JsonArray();
for(String key : openedVaultKeys)
{
try
{
String dim = "unknown";
String coords = key;
int sep = key.indexOf('|');
if(sep >= 0)
{
dim = key.substring(0, sep);
coords = key.substring(sep + 1);
}
String[] parts = coords.split(",");
if(parts.length >= 3)
{
int x = Integer.parseInt(parts[0]);
int y = Integer.parseInt(parts[1]);
int z = Integer.parseInt(parts[2]);
JsonObject o = new JsonObject();
o.addProperty("dimension", dim);
o.addProperty("x", x);
o.addProperty("y", y);
o.addProperty("z", z);
arr.add(o);
}
}catch(Throwable ignored)
{}
}
root.add("openedPositions", arr);
try(FileWriter w = new FileWriter(file))
{
w.write(GSON.toJson(root));
}catch(Throwable ignored)
{}
}
private String sanitizeServer(String serverIp)
{
if(serverIp == null || serverIp.isBlank())
return "singleplayer";
return serverIp.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9._-]",
"_");
}
private String detectMobFromDecor(BlockPos spawnerPos)
{