11package com .github .epsilon .modules .impl .render ;
22
33import com .github .epsilon .events .bus .EventHandler ;
4+ import com .github .epsilon .events .impl .PlayerTickEvent ;
45import com .github .epsilon .events .impl .Render3DEvent ;
56import com .github .epsilon .managers .Managers ;
67import com .github .epsilon .modules .Category ;
910import com .github .epsilon .settings .impl .BoolSetting ;
1011import com .github .epsilon .settings .impl .ColorSetting ;
1112import com .github .epsilon .settings .impl .DoubleSetting ;
13+ import com .github .epsilon .utils .timer .TimerUtils ;
1214import com .google .common .base .Supplier ;
1315import com .google .common .base .Suppliers ;
16+ import com .google .common .collect .Lists ;
1417import net .minecraft .core .BlockPos ;
15- import net .minecraft .world .level .ChunkPos ;
16- import net .minecraft .world .level .block .Block ;
17- import net .minecraft .world .level .block .Blocks ;
18- import net .minecraft .world .level .block .ChestBlock ;
19- import net .minecraft .world .level .block .entity .BlockEntity ;
18+ import net .minecraft .util .Mth ;
19+ import net .minecraft .util .Util ;
20+ import net .minecraft .world .level .Level ;
21+ import net .minecraft .world .level .block .*;
2022import net .minecraft .world .level .block .state .BlockState ;
2123import net .minecraft .world .level .block .state .properties .ChestType ;
22- import net .minecraft .world .level .chunk .LevelChunk ;
2324import net .minecraft .world .phys .AABB ;
2425
2526import java .awt .*;
2627import java .util .ArrayList ;
2728import java .util .HashSet ;
2829import java .util .List ;
2930import java .util .Set ;
31+ import java .util .concurrent .CompletableFuture ;
32+ import java .util .concurrent .ExecutorService ;
33+ import java .util .concurrent .Executors ;
3034
3135public class ESP extends Module {
3236
@@ -48,96 +52,126 @@ private ESP() {
4852 return list ;
4953 });
5054
51- private final BoolSetting blocks = boolSetting ("Blocks" , true );
52- private final BlockListSetting blockList = blockListSetting ("Block List" ,
53- defaultBlockList . get (), blocks :: getValue );
55+ private final BoolSetting blocksValue = boolSetting ("Blocks" , true );
56+ private final BlockListSetting blockList = blockListSetting ("Block List" , defaultBlockList . get (), blocksValue :: getValue );
57+ private final BoolSetting illegals = boolSetting ( "Illegals" , true );
5458 private final DoubleSetting range = doubleSetting ("Range" , 64.0 , 1.0 , 128.0 , 1.0 );
55- private final ColorSetting color = colorSetting ("Color" , new Color (160 , 210 , 255 , 30 ));
59+ private final ColorSetting sideColor = colorSetting ("Side Color" , new Color (160 , 210 , 255 , 30 ));
60+ private final ColorSetting lineColor = colorSetting ("Line Color" , new Color (160 , 210 , 255 , 180 ));
5661 private final BoolSetting blur = boolSetting ("Blur" , true );
5762 private final DoubleSetting blurStrength = doubleSetting ("Blur Strength" , 5.0 , 0.0 , 16.0 , 0.5 , blur ::getValue );
5863
59- @ EventHandler
60- private void onRender3D (Render3DEvent event ) {
61- if (blocks .getValue ()) {
62- double maxRange = range .getValue ();
63- int renderDistance = mc .options .renderDistance ().get ();
64+ private final ExecutorService searchThread = Executors .newSingleThreadExecutor ();
65+ private final TimerUtils searchTimer = new TimerUtils ();
66+ private boolean canContinue ;
6467
65- BlockPos playerPos = mc .player .blockPosition ();
66- ChunkPos playerChunk = mc .player .chunkPosition ();
67- Set <Block > selectedBlocks = blockList .asSet ();
68- Set <BlockPos > renderedBlocks = new HashSet <>();
68+ public static List <AABB > boxes = new ArrayList <>();
6969
70- if (selectedBlocks .isEmpty ()) {
71- return ;
72- }
70+ @ Override
71+ protected void onEnable () {
72+ boxes .clear ();
73+ canContinue = true ;
74+ }
7375
74- for (int x = -renderDistance ; x <= renderDistance ; x ++) {
75- for (int z = -renderDistance ; z <= renderDistance ; z ++) {
76- int chunkX = playerChunk .x () + x ;
77- int chunkZ = playerChunk .z () + z ;
78- if (!mc .level .hasChunk (chunkX , chunkZ )) {
79- continue ;
80- }
76+ @ EventHandler
77+ private void onPlayerTick (PlayerTickEvent .Pre event ) {
78+ if (searchTimer .every (1000 ) && canContinue ) {
79+ CompletableFuture .supplyAsync (this ::scan , searchThread ).thenAcceptAsync (newAABBList -> {
80+ boxes = newAABBList ;
81+ canContinue = true ;
82+ }, Util .backgroundExecutor ());
83+ canContinue = false ;
84+ }
85+ }
8186
82- LevelChunk chunk = mc .level .getChunkSource ().getChunkNow (chunkX , chunkZ );
83- if (chunk == null ) {
84- continue ;
85- }
87+ @ EventHandler
88+ private void onRender3D (Render3DEvent event ) {
89+ if (!boxes .isEmpty ()) {
90+ for (AABB aabb : Lists .newArrayList (boxes )) {
91+ if (blur .getValue ()) Managers .RENDER .addBlurredBox (aabb , blurStrength .getValue ());
92+ Managers .RENDER .addFilledBox (aabb , sideColor .getValue ());
93+ Managers .RENDER .addOutlineBox (aabb , lineColor .getValue ());
94+ }
95+ }
96+ }
8697
87- for (BlockEntity entity : chunk .getBlockEntities ().values ()) {
88- BlockPos blockPos = entity .getBlockPos ();
89- BlockState state = mc .level .getBlockState (blockPos );
90- if (!selectedBlocks .contains (state .getBlock ())) {
91- continue ;
98+ private List <AABB > scan () {
99+ List <AABB > boxes = new ArrayList <>();
100+ Set <BlockPos > processed = new HashSet <>();
101+
102+ int startX = Mth .floor (mc .player .getX () - range .getValue ());
103+ int endX = Mth .ceil (mc .player .getX () + range .getValue ());
104+ int startY = mc .level .getMinY () + 1 ;
105+ int endY = mc .level .getMaxY ();
106+ int startZ = Mth .floor (mc .player .getZ () - range .getValue ());
107+ int endZ = Mth .ceil (mc .player .getZ () + range .getValue ());
108+
109+ for (int x = startX ; x <= endX ; x ++) {
110+ for (int y = startY ; y <= endY ; y ++) {
111+ for (int z = startZ ; z <= endZ ; z ++) {
112+ BlockPos blockPos = new BlockPos (x , y , z );
113+ if (!processed .contains (blockPos )) {
114+ BlockState blockState = mc .level .getBlockState (blockPos );
115+ if (shouldAdd (blockState .getBlock (), blockPos )) {
116+ boxes .add (getConnectedShapeAABB (blockPos , blockState , processed ));
92117 }
93- renderBlock (blockPos , state , selectedBlocks , renderedBlocks , playerPos , maxRange );
94118 }
95119 }
96120 }
121+ }
122+ return boxes ;
123+ }
97124
98- int blockRange = (int ) Math .ceil (maxRange );
99- int minY = mc .level .getMinY ();
100- int maxY = mc .level .getMaxY ();
101- BlockPos min = new BlockPos (playerPos .getX () - blockRange , Math .max (minY , playerPos .getY () - blockRange ), playerPos .getZ () - blockRange );
102- BlockPos max = new BlockPos (playerPos .getX () + blockRange , Math .min (maxY , playerPos .getY () + blockRange ), playerPos .getZ () + blockRange );
103- for (BlockPos pos : BlockPos .betweenClosed (min , max )) {
104- if (!mc .level .isLoaded (pos ) || renderedBlocks .contains (pos )) {
105- continue ;
106- }
107- BlockState state = mc .level .getBlockState (pos );
108- if (selectedBlocks .contains (state .getBlock ())) {
109- renderBlock (pos .immutable (), state , selectedBlocks , renderedBlocks , playerPos , maxRange );
110- }
125+ private boolean shouldAdd (Block block , BlockPos pos ) {
126+ if (block instanceof AirBlock ) return false ;
127+ if (blockList .getValue ().contains (block )) return true ;
128+ if (illegals .getValue ()) return isIllegal (block , pos );
129+ return false ;
130+ }
131+
132+ private boolean isIllegal (Block block , BlockPos pos ) {
133+ if (block instanceof CommandBlock || block instanceof BarrierBlock ) return true ;
134+
135+ if (block == Blocks .BEDROCK ) {
136+ if (!Level .NETHER .equals (mc .level .dimension ())) {
137+ return pos .getY () > 4 ;
138+ } else {
139+ return pos .getY () > 127 || (pos .getY () < 123 && pos .getY () > 4 );
111140 }
112141 }
142+ return false ;
113143 }
114144
115- private void renderBlock (BlockPos blockPos , BlockState state , Set <Block > selectedBlocks , Set <BlockPos > renderedBlocks , BlockPos playerPos , double maxRange ) {
116- if (blockPos .distSqr (playerPos ) > maxRange * maxRange || !renderedBlocks .add (blockPos )) {
117- return ;
118- }
145+ private AABB getConnectedShapeAABB (BlockPos blockPos , BlockState state , Set <BlockPos > processed ) {
146+ processed .add (blockPos );
147+ AABB box = getShapeAABB (blockPos , state );
119148
120- AABB box = getAABB (blockPos );
121149 if (state .getBlock () instanceof ChestBlock && state .getValue (ChestBlock .TYPE ) != ChestType .SINGLE ) {
122150 BlockPos connectedPos = ChestBlock .getConnectedBlockPos (blockPos , state );
123- if (mc .level .isLoaded (connectedPos )) {
124- BlockState connectedState = mc .level .getBlockState (connectedPos );
125- if (selectedBlocks .contains (connectedState .getBlock ())
126- && connectedState .getBlock () == state .getBlock ()
127- && connectedState .getValue (ChestBlock .TYPE ) == state .getValue (ChestBlock .TYPE ).getOpposite ()
128- && connectedState .getValue (ChestBlock .FACING ) == state .getValue (ChestBlock .FACING )) {
129- box = box .minmax (getAABB (connectedPos ));
130- renderedBlocks .add (connectedPos );
131- }
151+ BlockState connectedState = mc .level .getBlockState (connectedPos );
152+ if (isConnectedChestPart (blockPos , state , connectedState , connectedPos )) {
153+ processed .add (connectedPos );
154+ box = box .minmax (getShapeAABB (connectedPos , connectedState ));
132155 }
133156 }
134157
135- if (blur .getValue ()) Managers .RENDER .addBlurredBox (box , blurStrength .getValue ());
136- Managers .RENDER .addFilledBox (box , color .getValue ());
158+ return box ;
159+ }
160+
161+ private boolean isConnectedChestPart (BlockPos blockPos , BlockState state , BlockState connectedState , BlockPos connectedPos ) {
162+ if (!(state .getBlock () instanceof ChestBlock chestBlock )) return false ;
163+ if (!chestBlock .chestCanConnectTo (connectedState )) return false ;
164+ if (!connectedState .hasProperty (ChestBlock .TYPE ) || !connectedState .hasProperty (ChestBlock .FACING ))
165+ return false ;
166+ if (connectedState .getValue (ChestBlock .TYPE ) == ChestType .SINGLE ) return false ;
167+ if (connectedState .getValue (ChestBlock .FACING ) != state .getValue (ChestBlock .FACING )) return false ;
168+ if (!ChestBlock .getConnectedBlockPos (connectedPos , connectedState ).equals (blockPos )) return false ;
169+
170+ return shouldAdd (connectedState .getBlock (), connectedPos );
137171 }
138172
139- private AABB getAABB (BlockPos blockPos ) {
140- return mc . level . getBlockState ( blockPos ) .getShape (mc .level , blockPos ).bounds ().move (blockPos );
173+ private AABB getShapeAABB (BlockPos blockPos , BlockState state ) {
174+ return state .getShape (mc .level , blockPos ).bounds ().move (blockPos );
141175 }
142176
143177}
0 commit comments