Skip to content

Commit 5ecf6c9

Browse files
committed
Merge branch 'master' into feature/freelook-module
2 parents 04802dc + 1811bf1 commit 5ecf6c9

File tree

18 files changed

+409
-53
lines changed

18 files changed

+409
-53
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2025 Lambda
2+
* Copyright 2024 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
@@ -26,10 +26,13 @@
2626
import com.lambda.interaction.request.rotation.RotationManager;
2727
import com.lambda.module.modules.player.PortalGui;
2828
import net.minecraft.client.MinecraftClient;
29+
import net.minecraft.client.gui.screen.DeathScreen;
2930
import net.minecraft.client.gui.screen.Screen;
31+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
3032
import net.minecraft.client.input.Input;
3133
import net.minecraft.client.network.ClientPlayerEntity;
3234
import net.minecraft.entity.MovementType;
35+
import net.minecraft.entity.damage.DamageSource;
3336
import net.minecraft.util.Hand;
3437
import net.minecraft.util.math.Vec3d;
3538
import org.spongepowered.asm.mixin.Final;
@@ -46,6 +49,8 @@
4649
@Mixin(value = ClientPlayerEntity.class, priority = Integer.MAX_VALUE)
4750
public abstract class ClientPlayerEntityMixin extends EntityMixin {
4851

52+
@Shadow
53+
public Input input;
4954
@Shadow
5055
private boolean autoJumpEnabled;
5156

@@ -77,11 +82,11 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
7782
this.autoJump(currX - prevX, currZ - prevZ);
7883
}
7984

80-
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
81-
void processMovement(Input input) {
82-
input.tick();
83-
RotationManager.BaritoneProcessor.processPlayerMovement(input);
84-
EventFlow.post(new MovementEvent.InputUpdate(input));
85+
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V"))
86+
void processMovement(Input input, boolean slowDown, float slowDownFactor) {
87+
input.tick(slowDown, slowDownFactor);
88+
RotationManager.BaritoneProcessor.processPlayerMovement(input, slowDown, slowDownFactor);
89+
EventFlow.post(new MovementEvent.InputUpdate(input, slowDown, slowDownFactor));
8590
}
8691

8792
/**
@@ -111,7 +116,7 @@ void redirectSneaking(CallbackInfoReturnable<Boolean> cir) {
111116
if (self != Lambda.getMc().player) return;
112117

113118
if (self.input == null) return;
114-
cir.setReturnValue(EventFlow.post(new MovementEvent.Sneak(self.input.playerInput.sneak())).getSneak());
119+
cir.setReturnValue(EventFlow.post(new MovementEvent.Sneak(self.input.sneaking)).getSneak());
115120
}
116121

117122
/**
@@ -134,12 +139,12 @@ void onTickPost(CallbackInfo ci) {
134139
EventFlow.post(new TickEvent.Player.Post());
135140
}
136141

137-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
142+
@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
138143
float fixHeldItemYaw(ClientPlayerEntity instance) {
139144
return Objects.requireNonNullElse(RotationManager.getHandYaw(), instance.getYaw());
140145
}
141146

142-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
147+
@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
143148
float fixHeldItemPitch(ClientPlayerEntity instance) {
144149
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
145150
}
@@ -149,27 +154,24 @@ void onSwingHandPre(Hand hand, CallbackInfo ci) {
149154
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
150155
}
151156

152-
@Inject(method = "updateHealth", at = @At("HEAD"))
153-
public void damage(float health, CallbackInfo ci) {
154-
EventFlow.post(new PlayerEvent.Damage(health));
157+
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
158+
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
159+
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) cir.setReturnValue(false);
155160
}
156161

157162
/**
158163
* Prevents the game from closing Guis when the player is in a nether portal
159164
* <pre>{@code
160-
* if (this.client.currentScreen != null
161-
* && !this.client.currentScreen.shouldPause()
162-
* && !(this.client.currentScreen instanceof DeathScreen)
163-
* && !(this.client.currentScreen instanceof CreditsScreen)) {
165+
* if (this.client.currentScreen != null && !this.client.currentScreen.shouldPause() && !(this.client.currentScreen instanceof DeathScreen)) {
164166
* if (this.client.currentScreen instanceof HandledScreen) {
165167
* this.closeHandledScreen();
166168
* }
167169
*
168-
* this.client.setScreen(null);
170+
* this.client.setScreen((Screen)null);
169171
* }
170172
* }</pre>
171173
*/
172-
@Redirect(method = "tickNausea", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"))
174+
@Redirect(method = "updateNausea", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"))
173175
Screen keepScreensInPortal(MinecraftClient instance) {
174176
if (PortalGui.INSTANCE.isEnabled()) return null;
175177
else return client.currentScreen;

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
2323
import com.lambda.interaction.request.rotation.RotationManager;
24+
import com.lambda.module.modules.render.ViewModel;
2425
import net.minecraft.entity.LivingEntity;
2526
import net.minecraft.util.math.MathHelper;
2627
import net.minecraft.util.math.Vec3d;
2728
import org.spongepowered.asm.mixin.Mixin;
2829
import org.spongepowered.asm.mixin.Shadow;
29-
import org.spongepowered.asm.mixin.injection.At;
30-
import org.spongepowered.asm.mixin.injection.Inject;
31-
import org.spongepowered.asm.mixin.injection.Redirect;
32-
import org.spongepowered.asm.mixin.injection.Slice;
30+
import org.spongepowered.asm.mixin.Unique;
31+
import org.spongepowered.asm.mixin.injection.*;
3332
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3433

3534
@Mixin(LivingEntity.class)
@@ -38,6 +37,9 @@ public abstract class LivingEntityMixin extends EntityMixin {
3837
@Shadow
3938
protected abstract float getJumpVelocity();
4039

40+
@Unique
41+
private final LivingEntity lambda$instance = (LivingEntity) (Object) this;
42+
4143
/**
4244
* Overwrites the jump function to use our rotation and movements
4345
* <pre>{@code
@@ -55,7 +57,7 @@ public abstract class LivingEntityMixin extends EntityMixin {
5557
*/
5658
@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
5759
void onJump(CallbackInfo ci) {
58-
LivingEntity self = (LivingEntity) (Object) this;
60+
LivingEntity self = lambda$instance;
5961
if (self != Lambda.getMc().player) return;
6062
ci.cancel();
6163

@@ -78,15 +80,14 @@ void onJump(CallbackInfo ci) {
7880

7981
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
8082
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
81-
LivingEntity entity = (LivingEntity) (Object) this;
82-
if (EventFlow.post(new MovementEvent.Entity.Pre(entity, movementInput)).isCanceled()) {
83+
if (EventFlow.post(new MovementEvent.Entity.Pre(lambda$instance, movementInput)).isCanceled()) {
8384
ci.cancel();
8485
}
8586
}
8687

8788
@Inject(method = "travel", at = @At("TAIL"))
8889
void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
89-
EventFlow.post(new MovementEvent.Entity.Post((LivingEntity) (Object) this, movementInput));
90+
EventFlow.post(new MovementEvent.Entity.Post(lambda$instance, movementInput));
9091
}
9192

9293
/**
@@ -123,7 +124,7 @@ private float hookModifyFallFlyingPitch(LivingEntity entity) {
123124
*/
124125
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1)))
125126
private float rotBody(LivingEntity entity) {
126-
if ((Object) this != Lambda.getMc().player) {
127+
if (lambda$instance != Lambda.getMc().player) {
127128
return entity.getYaw();
128129
}
129130

@@ -154,11 +155,18 @@ private float rotBody(LivingEntity entity) {
154155
*/
155156
@Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
156157
private float rotHead(LivingEntity entity) {
157-
if ((Object) this != Lambda.getMc().player) {
158+
if (lambda$instance != Lambda.getMc().player) {
158159
return entity.getYaw();
159160
}
160161

161162
Float yaw = RotationManager.getRenderYaw();
162163
return (yaw == null) ? entity.getYaw() : yaw;
163164
}
165+
166+
@ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6))
167+
private int getHandSwingDuration(int constant) {
168+
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return constant;
169+
170+
return ViewModel.INSTANCE.getSwingDuration();
171+
}
164172
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.google.common.base.MoreObjects;
4+
import com.lambda.Lambda;
5+
import com.lambda.module.modules.render.ViewModel;
6+
import net.minecraft.client.MinecraftClient;
7+
import net.minecraft.client.network.AbstractClientPlayerEntity;
8+
import net.minecraft.client.render.VertexConsumerProvider;
9+
import net.minecraft.client.render.item.HeldItemRenderer;
10+
import net.minecraft.client.util.math.MatrixStack;
11+
import net.minecraft.item.ItemStack;
12+
import net.minecraft.util.Hand;
13+
import org.spongepowered.asm.mixin.Final;
14+
import org.spongepowered.asm.mixin.Mixin;
15+
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.injection.At;
17+
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.ModifyArg;
19+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
20+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
21+
22+
@Mixin(HeldItemRenderer.class)
23+
public class HeldItemRendererMixin {
24+
@Final @Shadow private MinecraftClient client;
25+
@Shadow private ItemStack mainHand;
26+
@Shadow private ItemStack offHand;
27+
@Shadow private float equipProgressMainHand;
28+
@Shadow private float equipProgressOffHand;
29+
30+
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IFFLnet/minecraft/util/Arm;)V"))
31+
private void onRenderArmHoldingItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
32+
if (!ViewModel.INSTANCE.isEnabled()) return;
33+
34+
ViewModel.INSTANCE.transform(itemStack, hand, matrices);
35+
}
36+
37+
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"))
38+
private void onRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
39+
if (!ViewModel.INSTANCE.isEnabled()) return;
40+
41+
ViewModel.INSTANCE.transform(itemStack, hand, matrices);
42+
}
43+
44+
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0)
45+
private float modifyEquipProgressMainHand(float value) {
46+
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;
47+
48+
ViewModel config = ViewModel.INSTANCE;
49+
ItemStack currentStack = client.player.getMainHandStack();
50+
if (config.getOldAnimations() && !config.getSwapAnimation()) {
51+
mainHand = currentStack;
52+
}
53+
54+
float progress = config.getOldAnimations() ? 1 : (float) Math.pow(client.player.getAttackCooldownProgress(1), 3);
55+
56+
return (ItemStack.areEqual(mainHand, currentStack) ? progress : 0) - equipProgressMainHand;
57+
}
58+
59+
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 3), index = 0)
60+
private float modifyEquipProgressOffHand(float value) {
61+
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;
62+
63+
ViewModel config = ViewModel.INSTANCE;
64+
65+
ItemStack currentStack = client.player.getOffHandStack();
66+
if (config.getOldAnimations() && !config.getSwapAnimation()) {
67+
offHand = currentStack;
68+
}
69+
70+
return (ItemStack.areEqual(offHand, currentStack) ? 1 : 0) - equipProgressOffHand;
71+
}
72+
73+
@ModifyVariable(method = "renderItem(FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/network/ClientPlayerEntity;I)V", at = @At(value = "STORE", ordinal = 0), index = 6)
74+
private float modifySwing(float swingProgress) {
75+
ViewModel config = ViewModel.INSTANCE;
76+
MinecraftClient mc = Lambda.getMc();
77+
if (config.isDisabled() || mc.player == null) return swingProgress;
78+
Hand hand = MoreObjects.firstNonNull(mc.player.preferredHand, Hand.MAIN_HAND);
79+
80+
if (hand == Hand.MAIN_HAND) {
81+
return swingProgress + config.getMainSwingProgress();
82+
} else if (hand == Hand.OFF_HAND) {
83+
return swingProgress + config.getOffhandSwingProgress();
84+
}
85+
86+
return swingProgress;
87+
}
88+
}

common/src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ abstract class Configurable(
284284
description: String = "",
285285
unit: String = "",
286286
visibility: () -> Boolean = { true },
287-
) = DoubleSetting(name, defaultValue, range, step, description, visibility, unit).register()
287+
) = DoubleSetting(name, defaultValue, range, step, description, unit, visibility).register()
288288

289289
/**
290290
* Creates a [FloatSetting] with the provided parameters and adds it to the [settings].
@@ -309,7 +309,7 @@ abstract class Configurable(
309309
description: String = "",
310310
unit: String = "",
311311
visibility: () -> Boolean = { true },
312-
) = FloatSetting(name, defaultValue, range, step, description, visibility, unit).register()
312+
) = FloatSetting(name, defaultValue, range, step, description, unit, visibility).register()
313313

314314
/**
315315
* Creates an [IntegerSetting] with the provided parameters and adds it to the [settings].
@@ -334,7 +334,7 @@ abstract class Configurable(
334334
description: String = "",
335335
unit: String = "",
336336
visibility: () -> Boolean = { true },
337-
) = IntegerSetting(name, defaultValue, range, step, description, visibility, unit).register()
337+
) = IntegerSetting(name, defaultValue, range, step, description, unit, visibility).register()
338338

339339
/**
340340
* Creates a [LongSetting] with the provided parameters and adds it to the [settings].
@@ -359,7 +359,7 @@ abstract class Configurable(
359359
description: String = "",
360360
unit: String = "",
361361
visibility: () -> Boolean = { true },
362-
) = LongSetting(name, defaultValue, range, step, description, visibility, unit).register()
362+
) = LongSetting(name, defaultValue, range, step, description, unit, visibility).register()
363363

364364
/**
365365
* Creates a [KeyBindSetting] with the provided parameters and adds it to the [settings].

common/src/main/kotlin/com/lambda/config/groups/Targeting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.lambda.interaction.request.rotation.Rotation.Companion.dist
2424
import com.lambda.interaction.request.rotation.Rotation.Companion.rotation
2525
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
2626
import com.lambda.threading.runSafe
27+
import com.lambda.util.extension.fullHealth
2728
import com.lambda.util.math.distSq
2829
import com.lambda.util.world.fastEntitySearch
2930
import net.minecraft.client.network.ClientPlayerEntity
@@ -201,7 +202,7 @@ abstract class Targeting(
201202
/**
202203
* Prioritizes entities based on their health.
203204
*/
204-
HEALTH({ it.health.toDouble() }),
205+
HEALTH({ it.fullHealth }),
205206

206207
/**
207208
* Prioritizes entities based on their angle relative to the player's field of view.

common/src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ abstract class NumericSetting<T>(
3131
open val range: ClosedRange<T>,
3232
open val step: T,
3333
description: String,
34-
visibility: () -> Boolean,
3534
val unit: String,
35+
visibility: () -> Boolean
3636
) : AbstractSetting<T>(
3737
value,
3838
TypeToken.get(value::class.java).type,

common/src/main/kotlin/com/lambda/config/settings/numeric/DoubleSetting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class DoubleSetting(
3535
override val range: ClosedRange<Double>,
3636
override val step: Double,
3737
description: String,
38-
visibility: () -> Boolean,
3938
unit: String,
39+
visibility: () -> Boolean
4040
) : NumericSetting<Double>(
4141
defaultValue,
4242
range,
4343
step,
4444
description,
45-
visibility,
46-
unit
45+
unit,
46+
visibility
4747
) {
4848
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
4949
required(double(name, range.start, range.endInclusive)) { parameter ->

common/src/main/kotlin/com/lambda/config/settings/numeric/FloatSetting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class FloatSetting(
3434
override val range: ClosedRange<Float>,
3535
override val step: Float = 1f,
3636
description: String,
37-
visibility: () -> Boolean,
3837
unit: String,
38+
visibility: () -> Boolean
3939
) : NumericSetting<Float>(
4040
defaultValue,
4141
range,
4242
step,
4343
description,
44-
visibility,
45-
unit
44+
unit,
45+
visibility
4646
) {
4747
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
4848
required(float(name, range.start, range.endInclusive)) { parameter ->

common/src/main/kotlin/com/lambda/config/settings/numeric/IntegerSetting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class IntegerSetting(
3434
override val range: ClosedRange<Int>,
3535
override val step: Int = 1,
3636
description: String,
37-
visibility: () -> Boolean,
3837
unit: String,
38+
visibility: () -> Boolean
3939
) : NumericSetting<Int>(
4040
defaultValue,
4141
range,
4242
step,
4343
description,
44-
visibility,
45-
unit
44+
unit,
45+
visibility
4646
) {
4747
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {
4848
required(integer(name, range.start, range.endInclusive)) { parameter ->

0 commit comments

Comments
 (0)