2424import meteordevelopment .orbit .EventHandler ;
2525import net .minecraft .block .Block ;
2626import net .minecraft .block .BlockState ;
27- import net .minecraft .network .packet .c2s .play .HandSwingC2SPacket ;
2827import net .minecraft .network .packet .c2s .play .PlayerActionC2SPacket ;
2928import net .minecraft .network .packet .c2s .play .UpdateSelectedSlotC2SPacket ;
30- import net .minecraft .util .Hand ;
3129import net .minecraft .util .math .BlockPos ;
3230import net .minecraft .util .math .Direction ;
3331import net .minecraft .util .shape .VoxelShape ;
@@ -71,6 +69,13 @@ public class PacketMine extends Module {
7169 .build ()
7270 );
7371
72+ private final Setting <Boolean > obscureBreakingProgress = sgGeneral .add (new BoolSetting .Builder ()
73+ .name ("obscure-breaking-progress" )
74+ .description ("Spams abort breaking packets to obscure the block mining progress from other players. Does not hide it perfectly." )
75+ .defaultValue (false )
76+ .build ()
77+ );
78+
7479 // Render
7580
7681 private final Setting <Boolean > render = sgRender .add (new BoolSetting .Builder ()
@@ -133,6 +138,7 @@ public void onActivate() {
133138 public void onDeactivate () {
134139 for (MyBlock block : blocks ) blockPool .free (block );
135140 blocks .clear ();
141+
136142 if (shouldUpdateSlot ) {
137143 mc .player .networkHandler .sendPacket (new UpdateSelectedSlotC2SPacket (mc .player .getInventory ().getSelectedSlot ()));
138144 shouldUpdateSlot = false ;
@@ -142,7 +148,6 @@ public void onDeactivate() {
142148 @ EventHandler
143149 private void onStartBreakingBlock (StartBreakingBlockEvent event ) {
144150 if (!BlockUtils .canBreak (event .blockPos )) return ;
145-
146151 event .cancel ();
147152
148153 swapped = false ;
@@ -167,31 +172,30 @@ private void onTick(TickEvent.Pre event) {
167172 if (shouldUpdateSlot ) {
168173 mc .player .networkHandler .sendPacket (new UpdateSelectedSlotC2SPacket (mc .player .getInventory ().getSelectedSlot ()));
169174 shouldUpdateSlot = false ;
175+ swapped = false ;
170176 }
171177
172- if (!blocks .isEmpty ()) blocks .getFirst ().mine ();
173-
174- if (!swapped && autoSwitch .get () && (!mc .player .isUsingItem () || !notOnUse .get ())) {
175- for (MyBlock block : blocks ) {
176- if (block .isReady ()) {
177- FindItemResult slot = InvUtils .findFastestTool (block .blockState );
178- if (!slot .found () || mc .player .getInventory ().getSelectedSlot () == slot .slot ()) continue ;
179- mc .player .networkHandler .sendPacket (new UpdateSelectedSlotC2SPacket (slot .slot ()));
180- swapped = true ;
181- shouldUpdateSlot = true ;
182- break ;
183- }
178+ if (!blocks .isEmpty ()) {
179+ MyBlock block = blocks .getFirst ();
180+ block .mine ();
181+
182+ if (block .isReady () && !swapped && autoSwitch .get () && (!mc .player .isUsingItem () || !notOnUse .get ())) {
183+ FindItemResult slot = InvUtils .findFastestTool (block .blockState );
184+ if (!slot .found () || mc .player .getInventory ().getSelectedSlot () == slot .slot ()) return ;
185+ mc .player .networkHandler .sendPacket (new UpdateSelectedSlotC2SPacket (slot .slot ()));
186+ swapped = true ;
187+ shouldUpdateSlot = true ;
184188 }
185189 }
186190 }
187191
188192 @ EventHandler
189193 private void onRender (Render3DEvent event ) {
190- if (render .get ()) {
191- for ( MyBlock block : blocks ) {
192- if ( Modules . get (). get ( BreakIndicators . class ). isActive () && Modules . get (). get ( BreakIndicators . class ). packetMine . get () && block . mining ) {
193- continue ;
194- } else block .render (event );
194+ if (! render .get ()) return ;
195+
196+ for ( MyBlock block : blocks ) {
197+ if (! Modules . get (). get ( BreakIndicators . class ). isActive () || ! Modules . get (). get ( BreakIndicators . class ). packetMine . get () || ! block . mining ) {
198+ block .render (event );
195199 }
196200 }
197201 }
@@ -203,9 +207,8 @@ public class MyBlock {
203207
204208 public Direction direction ;
205209
206- public int timer ;
210+ public int timer , startTime ;
207211 public boolean mining ;
208- public double progress ;
209212
210213 public MyBlock set (StartBreakingBlockEvent event ) {
211214 this .blockPos = event .blockPos ;
@@ -214,43 +217,32 @@ public MyBlock set(StartBreakingBlockEvent event) {
214217 this .block = blockState .getBlock ();
215218 this .timer = delay .get ();
216219 this .mining = false ;
217- this .progress = 0 ;
218220
219221 return this ;
220222 }
221223
222224 public boolean shouldRemove () {
223- boolean remove = mc .world .getBlockState (blockPos ).getBlock () != block || Utils .distance (mc .player .getX () - 0.5 , mc .player .getY () + mc .player .getEyeHeight (mc .player .getPose ()), mc .player .getZ () - 0.5 , blockPos .getX () + direction .getOffsetX (), blockPos .getY () + direction .getOffsetY (), blockPos .getZ () + direction .getOffsetZ ()) > mc .player .getBlockInteractionRange ();
224-
225- if (remove ) {
226- mc .getNetworkHandler ().sendPacket (new PlayerActionC2SPacket (PlayerActionC2SPacket .Action .ABORT_DESTROY_BLOCK , blockPos , direction ));
227- mc .getNetworkHandler ().sendPacket (new HandSwingC2SPacket (Hand .MAIN_HAND ));
228- }
225+ boolean broken = mc .world .getBlockState (blockPos ).getBlock () != block ;
226+ boolean timeout = progress () > 2 && (mc .player .age - startTime > 50 );
227+ boolean distance = Utils .distance (mc .player .getEyePos ().x , mc .player .getEyePos ().y , mc .player .getEyePos ().z , blockPos .getX () + direction .getOffsetX (), blockPos .getY () + direction .getOffsetY (), blockPos .getZ () + direction .getOffsetZ ()) > mc .player .getBlockInteractionRange ();
229228
230- return remove ;
229+ return broken || timeout || distance ;
231230 }
232231
233232 public boolean isReady () {
234- return progress >= 1 ;
233+ return progress () >= 1 ;
234+ }
235+
236+ public double progress () {
237+ if (!mining ) return 0 ;
238+
239+ FindItemResult fir = InvUtils .findFastestTool (blockState );
240+ return BlockUtils .getBreakDelta (fir .found () ? fir .slot () : mc .player .getInventory ().getSelectedSlot (), blockState ) * ((mc .player .age - startTime ) + 1 );
235241 }
236242
237243 public void mine () {
238244 if (rotate .get ()) Rotations .rotate (Rotations .getYaw (blockPos ), Rotations .getPitch (blockPos ), 50 , this ::sendMinePackets );
239245 else sendMinePackets ();
240-
241- double bestScore = -1 ;
242- int bestSlot = -1 ;
243-
244- for (int i = 0 ; i < 9 ; i ++) {
245- double score = mc .player .getInventory ().getStack (i ).getMiningSpeedMultiplier (blockState );
246-
247- if (score > bestScore ) {
248- bestScore = score ;
249- bestSlot = i ;
250- }
251- }
252-
253- progress += BlockUtils .getBreakDelta (bestSlot != -1 ? bestSlot : mc .player .getInventory ().getSelectedSlot (), blockState );
254246 }
255247
256248 private void sendMinePackets () {
@@ -260,11 +252,14 @@ private void sendMinePackets() {
260252 mc .interactionManager .sendSequencedPacket (mc .world , (sequence ) -> new PlayerActionC2SPacket (PlayerActionC2SPacket .Action .STOP_DESTROY_BLOCK , blockPos , direction , sequence ));
261253
262254 mining = true ;
255+ startTime = mc .player .age ;
263256 }
264257 }
265258 else {
266259 timer --;
267260 }
261+
262+ if (mining && obscureBreakingProgress .get ()) mc .getNetworkHandler ().sendPacket (new PlayerActionC2SPacket (PlayerActionC2SPacket .Action .ABORT_DESTROY_BLOCK , blockPos , direction ));
268263 }
269264
270265 public void render (Render3DEvent event ) {
0 commit comments