Skip to content

Commit 9fd7234

Browse files
committed
simple packet mine as a wrapper for the break manager
1 parent 9b18907 commit 9fd7234

File tree

3 files changed

+105
-61
lines changed

3 files changed

+105
-61
lines changed

common/src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
import com.lambda.event.events.InventoryEvent;
2424
import com.lambda.event.events.TickEvent;
2525
import com.lambda.module.modules.player.Interact;
26+
import com.lambda.module.modules.player.PacketMine;
2627
import net.minecraft.client.MinecraftClient;
2728
import net.minecraft.client.gui.screen.Screen;
2829
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
30+
import net.minecraft.client.network.ClientPlayerEntity;
2931
import net.minecraft.client.network.ClientPlayerInteractionManager;
32+
import net.minecraft.util.Hand;
33+
import net.minecraft.util.hit.HitResult;
3034
import org.jetbrains.annotations.Nullable;
3135
import org.spongepowered.asm.mixin.Mixin;
3236
import org.spongepowered.asm.mixin.Shadow;
@@ -41,6 +45,10 @@ public class MinecraftClientMixin {
4145
@Nullable
4246
public Screen currentScreen;
4347

48+
@Shadow @Nullable public HitResult crosshairTarget;
49+
50+
@Shadow @Nullable public ClientPlayerEntity player;
51+
4452
@Inject(method = "tick", at = @At("HEAD"))
4553
void onTickPre(CallbackInfo ci) {
4654
EventFlow.post(new TickEvent.Pre());
@@ -90,8 +98,16 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
9098
}
9199
}
92100

101+
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
102+
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
103+
if (this.crosshairTarget == null || this.player != null) return;
104+
if (this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled()) {
105+
this.player.swingHand(hand);
106+
}
107+
}
108+
93109
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
94-
boolean injectMultiActon(ClientPlayerInteractionManager instance) {
110+
boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
95111
if (instance == null) return true;
96112

97113
if (Interact.INSTANCE.isEnabled() && Interact.getMultiAction()) return false;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.player
19+
20+
import com.lambda.config.groups.BuildSettings
21+
import com.lambda.config.groups.HotbarSettings
22+
import com.lambda.config.groups.InteractionSettings
23+
import com.lambda.config.groups.InventorySettings
24+
import com.lambda.config.groups.RotationSettings
25+
import com.lambda.event.events.PlayerEvent
26+
import com.lambda.event.listener.SafeListener.Companion.listen
27+
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
28+
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
29+
import com.lambda.interaction.construction.context.BuildContext
30+
import com.lambda.interaction.construction.result.BreakResult
31+
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
32+
import com.lambda.interaction.construction.verify.TargetState
33+
import com.lambda.interaction.request.breaking.BreakRequest
34+
import com.lambda.module.Module
35+
import com.lambda.module.tag.ModuleTag
36+
import com.lambda.util.BlockUtils.blockState
37+
import com.lambda.util.world.raycast.InteractionMask
38+
import java.util.concurrent.ConcurrentLinkedQueue
39+
40+
object PacketMine : Module(
41+
"Packet Mine",
42+
"automatically breaks blocks, and does it faster",
43+
setOf(ModuleTag.PLAYER)
44+
) {
45+
private val page by setting("Page", Page.Build)
46+
47+
private val build = BuildSettings(this) { page == Page.Build }
48+
private val rotation = RotationSettings(this) { page == Page.Rotation }
49+
private val interact = InteractionSettings(this, InteractionMask.Block) { page == Page.Interaction }
50+
private val inventory = InventorySettings(this) { page == Page.Inventory }
51+
private val hotbar = HotbarSettings(this) { page == Page.Hotbar }
52+
53+
private val pendingInteractionsList = ConcurrentLinkedQueue<BuildContext>()
54+
55+
private var breaks = 0
56+
private var itemDrops = 0
57+
58+
init {
59+
listen<PlayerEvent.Attack.Block> { event ->
60+
event.cancel()
61+
62+
val blockState = blockState(event.pos)
63+
val buildResult = event.pos
64+
.toStructure(TargetState.State(blockState.fluidState.blockState))
65+
.toBlueprint()
66+
.simulate(
67+
player.eyePos,
68+
interact = interact,
69+
rotation = rotation,
70+
inventory = inventory,
71+
build = build
72+
)
73+
.minOrNull() ?: return@listen
74+
75+
if (buildResult !is BreakResult.Break) return@listen
76+
val request = BreakRequest(
77+
listOf(buildResult.context), build, rotation, interact, inventory, hotbar,
78+
pendingInteractionsList = pendingInteractionsList,
79+
onBreak = { breaks++ }
80+
) { _ -> itemDrops++ }
81+
build.breakSettings.request(request)
82+
}
83+
}
84+
85+
enum class Page {
86+
Build, Rotation, Interaction, Inventory, Hotbar
87+
}
88+
}

common/src/main/kotlin/com/lambda/module/modules/player/PacketMineRewrite.kt

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)