Skip to content

Commit fa3e5e7

Browse files
authored
Update BlockUtils.java
1 parent 3c64084 commit fa3e5e7

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/main/java/meteordevelopment/meteorclient/utils/world/BlockUtils.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import net.minecraft.world.LightType;
3939
import net.minecraft.world.World;
4040

41+
import java.util.function.Supplier;
42+
4143
import static meteordevelopment.meteorclient.MeteorClient.mc;
4244

4345
@SuppressWarnings("ConstantConditions")
@@ -234,6 +236,13 @@ private static void onTickPost(TickEvent.Post event) {
234236
* Needs to be used in {@link TickEvent.Pre}
235237
*/
236238
public static boolean breakBlock(BlockPos blockPos, boolean swing) {
239+
return breakBlock(blockPos, swing ? SwingMode.Normal : SwingMode.SendPacket, () -> getDirection(blockPos));
240+
}
241+
242+
/**
243+
* Needs to be used in {@link TickEvent.Pre}
244+
*/
245+
public static boolean breakBlock(BlockPos blockPos, SwingMode swing, Supplier<Direction> getDirection) {
237246
if (!canBreak(blockPos, mc.world.getBlockState(blockPos))) return false;
238247

239248
// Creating new instance of block pos because minecraft assigns the parameter to a field, and we don't want it to change when it has been stored in a field somewhere
@@ -245,19 +254,29 @@ public static boolean breakBlock(BlockPos blockPos, boolean swing) {
245254
return true;
246255
}
247256

257+
Direction direction = getDirection.get();
248258
if (mc.interactionManager.isBreakingBlock())
249-
mc.interactionManager.updateBlockBreakingProgress(pos, getDirection(blockPos));
250-
else mc.interactionManager.attackBlock(pos, getDirection(blockPos));
259+
mc.interactionManager.updateBlockBreakingProgress(pos, direction);
260+
else mc.interactionManager.attackBlock(pos, direction);
251261

252-
if (swing) mc.player.swingHand(Hand.MAIN_HAND);
253-
else mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
262+
switch (swing) {
263+
case None -> {}
264+
case SendPacket -> mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));
265+
case Normal -> mc.player.swingHand(Hand.MAIN_HAND);
266+
}
254267

255268
breaking = true;
256269
breakingThisTick = true;
257270

258271
return true;
259272
}
260273

274+
public enum SwingMode {
275+
None,
276+
SendPacket,
277+
Normal
278+
}
279+
261280
public static boolean canBreak(BlockPos blockPos, BlockState state) {
262281
if (!mc.player.isCreative() && state.getHardness(mc.world, blockPos) < 0) return false;
263282
return state.getOutlineShape(mc.world, blockPos) != VoxelShapes.empty();

0 commit comments

Comments
 (0)