Skip to content

Commit e1a7b1d

Browse files
beanbag44Avanatikeremyfops
authored
Managers, Packetmine, Tick Stages, and more... (#134)
- **New Features** - Introduced enhanced configuration options for block breaking and placing, offering more granular control over tool usage, swing behavior, and confirmation modes. - Rolled out updated hotbar and inventory settings that improve container access and overall item management. - Added a new `ContainerSelection` class for improved material container selection. - Introduced `BreakSettings` and `PlaceSettings` classes to manage breaking and placing configurations. - Added new methods for handling block breaking and placement events, enhancing interaction responsiveness. - **Improvements** - Refined block interaction logic and tool selection for more efficient and responsive gameplay. - Enhanced hand swing animations and rotation handling for smoother in-game actions. - Streamlined item count display in the inventory system for better clarity. - Improved logic for managing player actions during block interactions. - **Refactor** - Consolidated various settings and event systems to provide a more stable and maintainable gameplay experience. - Updated method signatures and logic for improved encapsulation and clarity in the codebase. --------- Co-authored-by: Constructor <fractalminds@protonmail.com> Co-authored-by: Edouard127 <46357922+Edouard127@users.noreply.github.com>
1 parent 545aa15 commit e1a7b1d

File tree

160 files changed

+7392
-1539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+7392
-1539
lines changed

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

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,82 @@
2424
import com.lambda.event.events.TickEvent;
2525
import com.lambda.gui.DearImGui;
2626
import com.lambda.module.modules.player.Interact;
27+
import com.lambda.module.modules.player.PacketMine;
28+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
29+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
30+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
2731
import net.minecraft.client.MinecraftClient;
28-
import net.minecraft.client.RunArgs;
2932
import net.minecraft.client.gui.screen.Screen;
3033
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
34+
import net.minecraft.client.network.ClientPlayerEntity;
3135
import net.minecraft.client.network.ClientPlayerInteractionManager;
32-
import net.minecraft.client.util.Window;
36+
import net.minecraft.client.render.WorldRenderer;
37+
import net.minecraft.client.sound.SoundManager;
3338
import net.minecraft.util.thread.ThreadExecutor;
39+
import net.minecraft.util.Hand;
40+
import net.minecraft.util.hit.HitResult;
3441
import org.jetbrains.annotations.Nullable;
35-
import org.spongepowered.asm.mixin.Final;
3642
import org.spongepowered.asm.mixin.Mixin;
3743
import org.spongepowered.asm.mixin.Shadow;
3844
import org.spongepowered.asm.mixin.injection.At;
3945
import org.spongepowered.asm.mixin.injection.Inject;
4046
import org.spongepowered.asm.mixin.injection.Redirect;
4147
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
4248

43-
@Mixin(MinecraftClient.class)
49+
@Mixin(value = MinecraftClient.class, priority = Integer.MAX_VALUE)
4450
public class MinecraftClientMixin {
4551
@Shadow
4652
@Nullable
4753
public Screen currentScreen;
54+
@Shadow
55+
@Nullable
56+
public HitResult crosshairTarget;
4857

4958
@Inject(method = "close", at = @At("HEAD"))
5059
void closeImGui(CallbackInfo ci) {
5160
DearImGui.INSTANCE.destroy();
5261
}
5362

54-
@Inject(method = "tick", at = @At("HEAD"))
55-
void onTickPre(CallbackInfo ci) {
56-
EventFlow.post(new TickEvent.Pre());
63+
@WrapMethod(method = "render")
64+
void onLoopTick(boolean tick, Operation<Void> original) {
65+
EventFlow.post(TickEvent.Render.Pre.INSTANCE);
66+
original.call(tick);
67+
EventFlow.post(TickEvent.Render.Post.INSTANCE);
5768
}
5869

59-
@Inject(method = "tick", at = @At("RETURN"))
60-
void onTickPost(CallbackInfo ci) {
61-
EventFlow.post(new TickEvent.Post());
70+
@WrapMethod(method = "tick")
71+
void onTick(Operation<Void> original) {
72+
EventFlow.post(TickEvent.Pre.INSTANCE);
73+
original.call();
74+
EventFlow.post(TickEvent.Post.INSTANCE);
6275
}
6376

64-
@Inject(method = "render", at = @At("HEAD"))
65-
void onLoopTickPre(CallbackInfo ci) {
66-
EventFlow.post(new TickEvent.Render.Pre());
77+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;tick()V"))
78+
void onNetwork(ClientPlayerInteractionManager instance, Operation<Void> original) {
79+
EventFlow.post(TickEvent.Network.Pre.INSTANCE);
80+
original.call(instance);
81+
EventFlow.post(TickEvent.Network.Post.INSTANCE);
6782
}
6883

69-
@Inject(method = "render", at = @At("RETURN"))
70-
void onLoopTickPost(CallbackInfo ci) {
71-
EventFlow.post(new TickEvent.Render.Post());
84+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;handleInputEvents()V"))
85+
void onInput(MinecraftClient instance, Operation<Void> original) {
86+
EventFlow.post(TickEvent.Input.Pre.INSTANCE);
87+
original.call(instance);
88+
EventFlow.post(TickEvent.Input.Post.INSTANCE);
89+
}
90+
91+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;tick()V"))
92+
void onWorldRenderer(WorldRenderer instance, Operation<Void> original) {
93+
EventFlow.post(TickEvent.WorldRender.Pre.INSTANCE);
94+
original.call(instance);
95+
EventFlow.post(TickEvent.WorldRender.Post.INSTANCE);
96+
}
97+
98+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundManager;tick(Z)V"))
99+
void onSound(SoundManager instance, boolean paused, Operation<Void> original) {
100+
EventFlow.post(TickEvent.Sound.Pre.INSTANCE);
101+
original.call(instance, paused);
102+
EventFlow.post(TickEvent.Sound.Post.INSTANCE);
72103
}
73104

74105
@Inject(at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;)V", shift = At.Shift.AFTER, remap = false), method = "stop")
@@ -100,8 +131,16 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
100131
}
101132
}
102133

134+
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
135+
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
136+
if (this.crosshairTarget == null) return;
137+
if (this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled()) {
138+
instance.swingHand(hand);
139+
}
140+
}
141+
103142
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
104-
boolean injectMultiActon(ClientPlayerInteractionManager instance) {
143+
boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
105144
if (instance == null) return true;
106145

107146
if (Interact.INSTANCE.isEnabled() && Interact.getMultiAction()) return false;

src/main/java/com/lambda/mixin/baritone/MixinBaritonePlayerContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import baritone.Baritone;
2121
import baritone.api.utils.Rotation;
2222
import baritone.utils.player.BaritonePlayerContext;
23-
import com.lambda.interaction.request.rotation.RotationManager;
23+
import com.lambda.interaction.request.rotating.RotationManager;
2424
import com.lambda.util.BaritoneUtils;
2525
import org.spongepowered.asm.mixin.Final;
2626
import org.spongepowered.asm.mixin.Mixin;
@@ -42,7 +42,7 @@ void syncRotationWithBaritone(CallbackInfoReturnable<Rotation> cir) {
4242

4343
RotationManager rm = RotationManager.INSTANCE;
4444
cir.setReturnValue(new Rotation(
45-
(float) rm.getCurrentRotation().getYaw(), (float) rm.getCurrentRotation().getPitch())
45+
(float) rm.getActiveRotation().getYaw(), (float) rm.getActiveRotation().getPitch())
4646
);
4747
}
4848
}

src/main/java/com/lambda/mixin/baritone/MixinLookBehavior.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import baritone.api.event.events.RotationMoveEvent;
2222
import baritone.api.utils.Rotation;
2323
import baritone.behavior.LookBehavior;
24-
import com.lambda.interaction.request.rotation.RotationManager;
24+
import com.lambda.interaction.request.rotating.RotationManager;
2525
import com.lambda.util.BaritoneUtils;
2626
import org.spongepowered.asm.mixin.Mixin;
2727
import org.spongepowered.asm.mixin.injection.At;

src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Lambda
2+
* Copyright 2025 Lambda
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -23,9 +23,11 @@
2323
import com.lambda.event.events.PlayerEvent;
2424
import com.lambda.event.events.TickEvent;
2525
import com.lambda.interaction.PlayerPacketManager;
26-
import com.lambda.interaction.request.rotation.RotationManager;
26+
import com.lambda.interaction.request.rotating.RotationManager;
2727
import com.lambda.module.modules.player.PortalGui;
2828
import com.lambda.module.modules.render.ViewModel;
29+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
30+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2931
import com.mojang.authlib.GameProfile;
3032
import net.minecraft.client.MinecraftClient;
3133
import net.minecraft.client.gui.screen.Screen;
@@ -51,6 +53,9 @@
5153
@Mixin(value = ClientPlayerEntity.class, priority = Integer.MAX_VALUE)
5254
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
5355

56+
@Shadow
57+
public Input input;
58+
5459
@Shadow
5560
private boolean autoJumpEnabled;
5661

@@ -90,6 +95,7 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
9095
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
9196
void processMovement(Input input) {
9297
input.tick();
98+
RotationManager.processRotations();
9399
RotationManager.BaritoneProcessor.processPlayerMovement(input);
94100
EventFlow.post(new MovementEvent.InputUpdate(input));
95101
}
@@ -134,14 +140,11 @@ void sendBegin(CallbackInfo ci) {
134140
autoJumpEnabled = Lambda.getMc().options.getAutoJump().getValue();
135141
}
136142

137-
@Inject(method = "tick", at = @At(value = "HEAD"))
138-
void onTickPre(CallbackInfo ci) {
139-
EventFlow.post(new TickEvent.Player.Pre());
140-
}
141-
142-
@Inject(method = "tick", at = @At(value = "RETURN"))
143-
void onTickPost(CallbackInfo ci) {
144-
EventFlow.post(new TickEvent.Player.Post());
143+
@WrapMethod(method = "tick")
144+
void onTick(Operation<Void> original) {
145+
EventFlow.post(TickEvent.Player.Pre.INSTANCE);
146+
original.call();
147+
EventFlow.post(TickEvent.Player.Post.INSTANCE);
145148
}
146149

147150
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
@@ -155,15 +158,10 @@ float fixHeldItemPitch(ClientPlayerEntity instance) {
155158
}
156159

157160
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)
158-
void onSwingHandPre(Hand hand, CallbackInfo ci) {
161+
void onSwing(Hand hand, CallbackInfo ci) {
159162
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
160163
}
161164

162-
@Inject(method = "updateHealth", at = @At("HEAD"))
163-
public void damage(float health, CallbackInfo ci) {
164-
EventFlow.post(new PlayerEvent.Damage(health));
165-
}
166-
167165
@Redirect(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
168166
private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
169167
ViewModel viewModel = ViewModel.INSTANCE;
@@ -176,6 +174,11 @@ private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
176174
viewModel.adjustSwing(hand, instance);
177175
}
178176

177+
@Inject(method = "updateHealth", at = @At("HEAD"))
178+
public void damage(float health, CallbackInfo ci) {
179+
EventFlow.post(new PlayerEvent.Damage(health));
180+
}
181+
179182
/**
180183
* Prevents the game from closing Guis when the player is in a nether portal
181184
* <pre>{@code

src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.EntityEvent;
2323
import com.lambda.event.events.PlayerEvent;
24-
import com.lambda.interaction.request.rotation.RotationManager;
24+
import com.lambda.interaction.request.rotating.RotationManager;
2525
import com.lambda.util.math.Vec2d;
2626
import net.minecraft.entity.Entity;
2727
import net.minecraft.entity.MovementType;

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
23-
import com.lambda.interaction.request.rotation.RotationManager;
2423
import com.lambda.module.modules.render.ViewModel;
24+
import com.lambda.interaction.request.rotating.RotationManager;
2525
import net.minecraft.entity.LivingEntity;
2626
import net.minecraft.util.math.MathHelper;
2727
import net.minecraft.util.math.Vec3d;
@@ -128,7 +128,7 @@ private float rotBody(LivingEntity entity) {
128128
return entity.getYaw();
129129
}
130130

131-
Float yaw = RotationManager.getRenderYaw();
131+
Float yaw = RotationManager.getHeadYaw();
132132
return (yaw == null) ? entity.getYaw() : yaw;
133133
}
134134

@@ -159,7 +159,7 @@ private float rotHead(LivingEntity entity) {
159159
return entity.getYaw();
160160
}
161161

162-
Float yaw = RotationManager.getRenderYaw();
162+
Float yaw = RotationManager.getHeadYaw();
163163
return (yaw == null) ? entity.getYaw() : yaw;
164164
}
165165

src/main/java/com/lambda/mixin/entity/PlayerEntityMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
23-
import com.lambda.interaction.request.rotation.RotationManager;
23+
import com.lambda.interaction.request.rotating.RotationManager;
2424
import net.minecraft.entity.player.PlayerEntity;
2525
import org.spongepowered.asm.mixin.Mixin;
2626
import org.spongepowered.asm.mixin.injection.At;
@@ -42,7 +42,7 @@ private float injectHeadYaw(PlayerEntity instance) {
4242
return instance.getYaw();
4343
}
4444

45-
Float yaw = RotationManager.getRenderYaw();
45+
Float yaw = RotationManager.getHeadYaw();
4646
return (yaw != null) ? yaw : instance.getYaw();
4747
}
4848

src/main/java/com/lambda/mixin/entity/PlayerInventoryMixin.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,30 @@
1717

1818
package com.lambda.mixin.entity;
1919

20-
import net.minecraft.client.MinecraftClient;
21-
import net.minecraft.client.network.ClientPlayerInteractionManager;
22-
import net.minecraft.entity.player.PlayerEntity;
20+
import com.lambda.interaction.request.hotbar.HotbarManager;
21+
import com.lambda.interaction.request.hotbar.HotbarRequest;
22+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2323
import net.minecraft.entity.player.PlayerInventory;
24-
import net.minecraft.item.ItemStack;
25-
import net.minecraft.util.collection.DefaultedList;
26-
import org.spongepowered.asm.mixin.Final;
24+
import org.objectweb.asm.Opcodes;
2725
import org.spongepowered.asm.mixin.Mixin;
28-
import org.spongepowered.asm.mixin.Shadow;
2926
import org.spongepowered.asm.mixin.injection.At;
3027
import org.spongepowered.asm.mixin.injection.Inject;
3128
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3229

33-
import static net.minecraft.entity.player.PlayerInventory.isValidHotbarIndex;
34-
3530
@Mixin(PlayerInventory.class)
3631
public class PlayerInventoryMixin {
37-
@Shadow @Final private DefaultedList<ItemStack> main;
38-
39-
@Shadow @Final public PlayerEntity player;
40-
41-
@Inject(method = "getSelectedStack", at = @At(value = "HEAD"), cancellable = true)
42-
public void handleSpoofedMainHandStack(CallbackInfoReturnable<ItemStack> cir) {
43-
MinecraftClient mc = MinecraftClient.getInstance();
44-
ClientPlayerInteractionManager interaction = mc.interactionManager;
45-
46-
if (player != mc.player || interaction == null) return;
47-
48-
int actualSlot = interaction.lastSelectedSlot;
32+
@SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"})
33+
@ModifyExpressionValue(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerInventory;selectedSlot:I", opcode = Opcodes.GETFIELD))
34+
private int modifySelectedSlot(int original) {
35+
final HotbarRequest hotbarRequest = HotbarManager.INSTANCE.getActiveRequest();
36+
if (hotbarRequest == null) return original;
37+
return hotbarRequest.getSlot();
38+
}
4939

50-
cir.setReturnValue(
51-
isValidHotbarIndex(actualSlot) ? main.get(actualSlot) : ItemStack.EMPTY
52-
);
40+
@Inject(method = "getSelectedSlot", at = @At("HEAD"), cancellable = true)
41+
private void redirectGetSelectedSlot(CallbackInfoReturnable<Integer> cir) {
42+
final HotbarRequest hotbarRequest = HotbarManager.INSTANCE.getActiveRequest();
43+
if (hotbarRequest == null) return;
44+
cir.setReturnValue(hotbarRequest.getSlot());
5345
}
5446
}

src/main/java/com/lambda/mixin/render/CameraMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.lambda.interaction.request.rotation.RotationManager;
20+
import com.lambda.interaction.request.rotating.RotationManager;
2121
import com.lambda.module.modules.player.Freecam;
2222
import com.lambda.module.modules.render.CameraTweaks;
2323
import com.lambda.module.modules.render.FreeLook;

src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.lambda.interaction.request.rotation.RotationManager;
20+
import com.lambda.interaction.request.rotating.RotationManager;
2121
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2222
import net.minecraft.client.render.entity.LivingEntityRenderer;
23-
import net.minecraft.entity.LivingEntity;
2423
import org.spongepowered.asm.mixin.Mixin;
2524
import org.spongepowered.asm.mixin.injection.At;
26-
import org.spongepowered.asm.mixin.injection.Redirect;
2725

2826
import java.util.Objects;
2927

@@ -48,6 +46,6 @@ public class LivingEntityRendererMixin {
4846
*/
4947
@ModifyExpressionValue(method = "updateRenderState(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getLerpedPitch(F)F"))
5048
private float injectRotationPitch(float original) {
51-
return Objects.requireNonNullElse(RotationManager.getRenderPitch(), original);
49+
return Objects.requireNonNullElse(RotationManager.getHeadPitch(), original);
5250
}
5351
}

0 commit comments

Comments
 (0)