88package net .wurstclient .hacks ;
99
1010import java .awt .Color ;
11- import java .util .Arrays ;
11+ import java .util .ArrayList ;
12+ import java .util .HashSet ;
1213import java .util .List ;
14+ import java .util .Set ;
1315import java .util .function .BiPredicate ;
16+ import java .util .stream .Stream ;
1417
1518import net .minecraft .block .Block ;
1619import net .minecraft .block .BlockState ;
@@ -47,9 +50,35 @@ public final class RedstoneEspHack extends Hack implements UpdateListener,
4750 false );
4851 private final ChunkAreaSetting area = new ChunkAreaSetting ("Area" ,
4952 "The area around the player to search in.\n "
50- + "Higher values require a faster computer." );
53+ + "Higher values require a faster computer." ,
54+ ChunkAreaSetting .ChunkArea .A33 );
5155 private final Color defaultColor = Color .RED ;
52- // Per-block groups (default enabled)
56+ // Grouped categories
57+ private final MultiBlockEspGroup buttonsGroup = new MultiBlockEspGroup (
58+ blocks (Blocks .OAK_BUTTON , Blocks .SPRUCE_BUTTON , Blocks .BIRCH_BUTTON ,
59+ Blocks .JUNGLE_BUTTON , Blocks .ACACIA_BUTTON , Blocks .DARK_OAK_BUTTON ,
60+ Blocks .MANGROVE_BUTTON , Blocks .BAMBOO_BUTTON , Blocks .CHERRY_BUTTON ,
61+ Blocks .CRIMSON_BUTTON , Blocks .WARPED_BUTTON , Blocks .STONE_BUTTON ,
62+ Blocks .POLISHED_BLACKSTONE_BUTTON ),
63+ new ColorSetting ("Buttons color" ,
64+ "All button types will be highlighted in this color." ,
65+ defaultColor ),
66+ new CheckboxSetting ("Include buttons" , true ));
67+ private final MultiBlockEspGroup platesGroup = new MultiBlockEspGroup (
68+ blocks (Blocks .OAK_PRESSURE_PLATE , Blocks .SPRUCE_PRESSURE_PLATE ,
69+ Blocks .BIRCH_PRESSURE_PLATE , Blocks .JUNGLE_PRESSURE_PLATE ,
70+ Blocks .ACACIA_PRESSURE_PLATE , Blocks .DARK_OAK_PRESSURE_PLATE ,
71+ Blocks .MANGROVE_PRESSURE_PLATE , Blocks .BAMBOO_PRESSURE_PLATE ,
72+ Blocks .CHERRY_PRESSURE_PLATE , Blocks .CRIMSON_PRESSURE_PLATE ,
73+ Blocks .WARPED_PRESSURE_PLATE , Blocks .STONE_PRESSURE_PLATE ,
74+ Blocks .POLISHED_BLACKSTONE_PRESSURE_PLATE ,
75+ Blocks .LIGHT_WEIGHTED_PRESSURE_PLATE ,
76+ Blocks .HEAVY_WEIGHTED_PRESSURE_PLATE ),
77+ new ColorSetting ("Pressure plates color" ,
78+ "All pressure plate types will be highlighted in this color." ,
79+ defaultColor ),
80+ new CheckboxSetting ("Include pressure plates" , true ));
81+ // Single components (wrapped)
5382 private final PortalEspBlockGroup redstoneTorch =
5483 new PortalEspBlockGroup (Blocks .REDSTONE_TORCH ,
5584 new ColorSetting ("Redstone torch color" ,
@@ -66,98 +95,6 @@ public final class RedstoneEspHack extends Hack implements UpdateListener,
6695 new ColorSetting ("Lever color" ,
6796 "Levers will be highlighted in this color." , defaultColor ),
6897 new CheckboxSetting ("Include levers" , true ));
69- // Buttons
70- private final PortalEspBlockGroup [] buttons = new PortalEspBlockGroup []{
71- new PortalEspBlockGroup (
72- Blocks .OAK_BUTTON ,
73- new ColorSetting ("Oak button color" , "" , defaultColor ),
74- new CheckboxSetting ("Include oak buttons" , true )),
75- new PortalEspBlockGroup (Blocks .SPRUCE_BUTTON ,
76- new ColorSetting ("Spruce button color" , "" , defaultColor ),
77- new CheckboxSetting ("Include spruce buttons" , true )),
78- new PortalEspBlockGroup (Blocks .BIRCH_BUTTON ,
79- new ColorSetting ("Birch button color" , "" , defaultColor ),
80- new CheckboxSetting ("Include birch buttons" , true )),
81- new PortalEspBlockGroup (Blocks .JUNGLE_BUTTON ,
82- new ColorSetting ("Jungle button color" , "" , defaultColor ),
83- new CheckboxSetting ("Include jungle buttons" , true )),
84- new PortalEspBlockGroup (Blocks .ACACIA_BUTTON ,
85- new ColorSetting ("Acacia button color" , "" , defaultColor ),
86- new CheckboxSetting ("Include acacia buttons" , true )),
87- new PortalEspBlockGroup (Blocks .DARK_OAK_BUTTON ,
88- new ColorSetting ("Dark oak button color" , "" , defaultColor ),
89- new CheckboxSetting ("Include dark oak buttons" , true )),
90- new PortalEspBlockGroup (Blocks .MANGROVE_BUTTON ,
91- new ColorSetting ("Mangrove button color" , "" , defaultColor ),
92- new CheckboxSetting ("Include mangrove buttons" , true )),
93- new PortalEspBlockGroup (Blocks .BAMBOO_BUTTON ,
94- new ColorSetting ("Bamboo button color" , "" , defaultColor ),
95- new CheckboxSetting ("Include bamboo buttons" , true )),
96- new PortalEspBlockGroup (Blocks .CHERRY_BUTTON ,
97- new ColorSetting ("Cherry button color" , "" , defaultColor ),
98- new CheckboxSetting ("Include cherry buttons" , true )),
99- new PortalEspBlockGroup (Blocks .CRIMSON_BUTTON ,
100- new ColorSetting ("Crimson button color" , "" , defaultColor ),
101- new CheckboxSetting ("Include crimson buttons" , true )),
102- new PortalEspBlockGroup (Blocks .WARPED_BUTTON ,
103- new ColorSetting ("Warped button color" , "" , defaultColor ),
104- new CheckboxSetting ("Include warped buttons" , true )),
105- new PortalEspBlockGroup (Blocks .STONE_BUTTON ,
106- new ColorSetting ("Stone button color" , "" , defaultColor ),
107- new CheckboxSetting ("Include stone buttons" , true )),
108- new PortalEspBlockGroup (Blocks .POLISHED_BLACKSTONE_BUTTON ,
109- new ColorSetting ("Polished blackstone button color" , "" ,
110- defaultColor ),
111- new CheckboxSetting ("Include polished blackstone buttons" , true ))};
112- // Plates
113- private final PortalEspBlockGroup [] plates = new PortalEspBlockGroup []{
114- new PortalEspBlockGroup (Blocks .OAK_PRESSURE_PLATE ,
115- new ColorSetting ("Oak pressure plate color" , "" , defaultColor ),
116- new CheckboxSetting ("Include oak plates" , true )),
117- new PortalEspBlockGroup (Blocks .SPRUCE_PRESSURE_PLATE ,
118- new ColorSetting ("Spruce pressure plate color" , "" , defaultColor ),
119- new CheckboxSetting ("Include spruce plates" , true )),
120- new PortalEspBlockGroup (Blocks .BIRCH_PRESSURE_PLATE ,
121- new ColorSetting ("Birch pressure plate color" , "" , defaultColor ),
122- new CheckboxSetting ("Include birch plates" , true )),
123- new PortalEspBlockGroup (Blocks .JUNGLE_PRESSURE_PLATE ,
124- new ColorSetting ("Jungle pressure plate color" , "" , defaultColor ),
125- new CheckboxSetting ("Include jungle plates" , true )),
126- new PortalEspBlockGroup (Blocks .ACACIA_PRESSURE_PLATE ,
127- new ColorSetting ("Acacia pressure plate color" , "" , defaultColor ),
128- new CheckboxSetting ("Include acacia plates" , true )),
129- new PortalEspBlockGroup (Blocks .DARK_OAK_PRESSURE_PLATE ,
130- new ColorSetting ("Dark oak pressure plate color" , "" , defaultColor ),
131- new CheckboxSetting ("Include dark oak plates" , true )),
132- new PortalEspBlockGroup (Blocks .MANGROVE_PRESSURE_PLATE ,
133- new ColorSetting ("Mangrove pressure plate color" , "" , defaultColor ),
134- new CheckboxSetting ("Include mangrove plates" , true )),
135- new PortalEspBlockGroup (Blocks .BAMBOO_PRESSURE_PLATE ,
136- new ColorSetting ("Bamboo pressure plate color" , "" , defaultColor ),
137- new CheckboxSetting ("Include bamboo plates" , true )),
138- new PortalEspBlockGroup (Blocks .CHERRY_PRESSURE_PLATE ,
139- new ColorSetting ("Cherry pressure plate color" , "" , defaultColor ),
140- new CheckboxSetting ("Include cherry plates" , true )),
141- new PortalEspBlockGroup (Blocks .CRIMSON_PRESSURE_PLATE ,
142- new ColorSetting ("Crimson pressure plate color" , "" , defaultColor ),
143- new CheckboxSetting ("Include crimson plates" , true )),
144- new PortalEspBlockGroup (Blocks .WARPED_PRESSURE_PLATE ,
145- new ColorSetting ("Warped pressure plate color" , "" , defaultColor ),
146- new CheckboxSetting ("Include warped plates" , true )),
147- new PortalEspBlockGroup (Blocks .STONE_PRESSURE_PLATE ,
148- new ColorSetting ("Stone pressure plate color" , "" , defaultColor ),
149- new CheckboxSetting ("Include stone plates" , true )),
150- new PortalEspBlockGroup (Blocks .POLISHED_BLACKSTONE_PRESSURE_PLATE ,
151- new ColorSetting ("Polished blackstone pressure plate color" , "" ,
152- defaultColor ),
153- new CheckboxSetting ("Include polished blackstone plates" , true )),
154- new PortalEspBlockGroup (Blocks .LIGHT_WEIGHTED_PRESSURE_PLATE ,
155- new ColorSetting ("Light weighted plate color" , "" , defaultColor ),
156- new CheckboxSetting ("Include light weighted plates" , true )),
157- new PortalEspBlockGroup (Blocks .HEAVY_WEIGHTED_PRESSURE_PLATE ,
158- new ColorSetting ("Heavy weighted plate color" , "" , defaultColor ),
159- new CheckboxSetting ("Include heavy weighted plates" , true ))};
160- // Remaining components
16198 private final PortalEspBlockGroup tripwireHook =
16299 new PortalEspBlockGroup (Blocks .TRIPWIRE_HOOK ,
163100 new ColorSetting ("Tripwire hook color" , "" , defaultColor ),
@@ -237,21 +174,20 @@ Blocks.BELL, new ColorSetting("Bell color", "", defaultColor),
237174 new PortalEspBlockGroup (Blocks .ACTIVATOR_RAIL ,
238175 new ColorSetting ("Activator rail color" , "" , defaultColor ),
239176 new CheckboxSetting ("Include activator rails" , true ));
240- private final List <PortalEspBlockGroup > allGroups =
241- Arrays .asList (redstoneTorch , redstoneBlock , lever ,
242- // buttons
243- buttons [0 ], buttons [1 ], buttons [2 ], buttons [3 ], buttons [4 ],
244- buttons [5 ], buttons [6 ], buttons [7 ], buttons [8 ], buttons [9 ],
245- buttons [10 ], buttons [11 ],
246- // plates
247- plates [0 ], plates [1 ], plates [2 ], plates [3 ], plates [4 ], plates [5 ],
248- plates [6 ], plates [7 ], plates [8 ], plates [9 ], plates [10 ], plates [11 ],
249- plates [12 ], plates [13 ], plates [14 ],
250- // rest
251- tripwireHook , target , dust , repeater , comparator , observer ,
252- daylight , sculk , cSculk , piston , stickyPiston , dispenser , dropper ,
253- hopper , trappedChest , noteBlock , jukebox , bell , lectern ,
254- poweredRail , detectorRail , activatorRail );
177+
178+ private final java .util .List <RenderGroup > renderGroups =
179+ java .util .Arrays .asList (
180+ // grouped first
181+ buttonsGroup , platesGroup ,
182+ // singles via adapters
183+ wrap (redstoneTorch ), wrap (redstoneBlock ), wrap (lever ),
184+ wrap (tripwireHook ), wrap (target ), wrap (dust ), wrap (repeater ),
185+ wrap (comparator ), wrap (observer ), wrap (daylight ), wrap (sculk ),
186+ wrap (cSculk ), wrap (piston ), wrap (stickyPiston ), wrap (dispenser ),
187+ wrap (dropper ), wrap (hopper ), wrap (trappedChest ), wrap (noteBlock ),
188+ wrap (jukebox ), wrap (bell ), wrap (lectern ), wrap (poweredRail ),
189+ wrap (detectorRail ), wrap (activatorRail ));
190+
255191 private final BiPredicate <BlockPos , BlockState > query =
256192 (pos , state ) -> isEnabledTarget (state .getBlock ());
257193 private final ChunkSearcherCoordinator coordinator =
@@ -265,16 +201,21 @@ public RedstoneEspHack()
265201 super ("RedstoneESP" );
266202 setCategory (Category .RENDER );
267203 addSetting (style );
268- allGroups .stream ().flatMap (PortalEspBlockGroup ::getSettings )
204+ renderGroups .stream ().flatMap (RenderGroup ::getSettings )
269205 .forEach (this ::addSetting );
270206 addSetting (area );
271207 addSetting (stickyArea );
272208 }
273209
210+ private static Set <Block > blocks (Block ... bs )
211+ {
212+ return new HashSet <>(java .util .Arrays .asList (bs ));
213+ }
214+
274215 private boolean isEnabledTarget (Block b )
275216 {
276- for (PortalEspBlockGroup g : allGroups )
277- if (g .getBlock () == b && g .isEnabled ( ))
217+ for (RenderGroup g : renderGroups )
218+ if (g .isEnabled () && g .matches ( b ))
278219 return true ;
279220 return false ;
280221 }
@@ -301,7 +242,7 @@ protected void onDisable()
301242 EVENTS .remove (net .wurstclient .events .PacketInputListener .class ,
302243 coordinator );
303244 coordinator .reset ();
304- allGroups .forEach (PortalEspBlockGroup ::clear );
245+ renderGroups .forEach (RenderGroup ::clear );
305246 }
306247
307248 @ Override
@@ -348,7 +289,7 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
348289
349290 private void renderBoxes (MatrixStack matrixStack )
350291 {
351- for (PortalEspBlockGroup group : allGroups )
292+ for (RenderGroup group : renderGroups )
352293 {
353294 if (!group .isEnabled ())
354295 continue ;
@@ -363,7 +304,7 @@ private void renderBoxes(MatrixStack matrixStack)
363304
364305 private void renderTracers (MatrixStack matrixStack , float partialTicks )
365306 {
366- for (PortalEspBlockGroup group : allGroups )
307+ for (RenderGroup group : renderGroups )
367308 {
368309 if (!group .isEnabled ())
369310 continue ;
@@ -377,18 +318,152 @@ private void renderTracers(MatrixStack matrixStack, float partialTicks)
377318
378319 private void updateGroupBoxes ()
379320 {
380- allGroups .forEach (PortalEspBlockGroup ::clear );
321+ renderGroups .forEach (RenderGroup ::clear );
381322 coordinator .getMatches ().forEach (this ::addToGroupBoxes );
382323 groupsUpToDate = true ;
383324 }
384325
385326 private void addToGroupBoxes (Result result )
386327 {
387- for (PortalEspBlockGroup group : allGroups )
388- if (result .state ().getBlock () == group .getBlock ())
328+ Block b = result .state ().getBlock ();
329+ for (RenderGroup group : renderGroups )
330+ if (group .matches (b ))
389331 {
390332 group .add (result .pos ());
391333 break ;
392334 }
393335 }
336+
337+ // Common interface for rendering groups
338+ private static interface RenderGroup
339+ {
340+ boolean isEnabled ();
341+
342+ boolean matches (Block b );
343+
344+ void add (BlockPos pos );
345+
346+ void clear ();
347+
348+ List <Box > getBoxes ();
349+
350+ int getColorI (int alpha );
351+
352+ Stream <net .wurstclient .settings .Setting > getSettings ();
353+ }
354+
355+ // Adapter for single-block groups
356+ private static RenderGroup wrap (PortalEspBlockGroup g )
357+ {
358+ return new RenderGroup ()
359+ {
360+ @ Override
361+ public boolean isEnabled ()
362+ {
363+ return g .isEnabled ();
364+ }
365+
366+ @ Override
367+ public boolean matches (Block b )
368+ {
369+ return g .getBlock () == b ;
370+ }
371+
372+ @ Override
373+ public void add (BlockPos pos )
374+ {
375+ g .add (pos );
376+ }
377+
378+ @ Override
379+ public void clear ()
380+ {
381+ g .clear ();
382+ }
383+
384+ @ Override
385+ public List <Box > getBoxes ()
386+ {
387+ return g .getBoxes ();
388+ }
389+
390+ @ Override
391+ public int getColorI (int alpha )
392+ {
393+ return g .getColorI (alpha );
394+ }
395+
396+ @ Override
397+ public Stream <net .wurstclient .settings .Setting > getSettings ()
398+ {
399+ return g .getSettings ();
400+ }
401+ };
402+ }
403+
404+ // Group that matches any of multiple blocks
405+ private static final class MultiBlockEspGroup implements RenderGroup
406+ {
407+ private final ArrayList <Box > boxes = new ArrayList <>();
408+ private final Set <Block > blocks ;
409+ private final ColorSetting color ;
410+ private final CheckboxSetting enabled ;
411+
412+ private MultiBlockEspGroup (Set <Block > blocks , ColorSetting color ,
413+ CheckboxSetting enabled )
414+ {
415+ this .blocks = new HashSet <>(blocks );
416+ this .color = java .util .Objects .requireNonNull (color );
417+ this .enabled = enabled ;
418+ }
419+
420+ @ Override
421+ public boolean isEnabled ()
422+ {
423+ return enabled == null || enabled .isChecked ();
424+ }
425+
426+ @ Override
427+ public boolean matches (Block b )
428+ {
429+ return blocks .contains (b );
430+ }
431+
432+ @ Override
433+ public void add (BlockPos pos )
434+ {
435+ if (!isEnabled ())
436+ return ;
437+ if (!net .wurstclient .util .BlockUtils .canBeClicked (pos ))
438+ return ;
439+ Box box = net .wurstclient .util .BlockUtils .getBoundingBox (pos );
440+ if (box .getAverageSideLength () == 0 )
441+ return ;
442+ boxes .add (box );
443+ }
444+
445+ @ Override
446+ public void clear ()
447+ {
448+ boxes .clear ();
449+ }
450+
451+ @ Override
452+ public List <Box > getBoxes ()
453+ {
454+ return java .util .Collections .unmodifiableList (boxes );
455+ }
456+
457+ @ Override
458+ public int getColorI (int alpha )
459+ {
460+ return color .getColorI (alpha );
461+ }
462+
463+ @ Override
464+ public Stream <net .wurstclient .settings .Setting > getSettings ()
465+ {
466+ return Stream .of (enabled , color ).filter (java .util .Objects ::nonNull );
467+ }
468+ }
394469}
0 commit comments