Skip to content

Commit c663685

Browse files
committed
Merge branch 'master' into feature/packetmine-rewrite
# Conflicts: # common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java # common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java # common/src/main/resources/lambda.accesswidener
2 parents 56a2abf + 1811bf1 commit c663685

File tree

6 files changed

+367
-10
lines changed

6 files changed

+367
-10
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import com.lambda.module.modules.player.PortalGui;
2828
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2929
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
30+
import com.lambda.module.modules.render.ViewModel;
3031
import net.minecraft.client.MinecraftClient;
3132
import net.minecraft.client.gui.screen.Screen;
3233
import net.minecraft.client.input.Input;
34+
import net.minecraft.client.network.AbstractClientPlayerEntity;
3335
import net.minecraft.client.network.ClientPlayerEntity;
3436
import net.minecraft.entity.MovementType;
3537
import net.minecraft.entity.damage.DamageSource;
@@ -146,6 +148,18 @@ float fixHeldItemPitch(ClientPlayerEntity instance) {
146148
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
147149
}
148150

151+
@Redirect(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
152+
private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
153+
ViewModel viewModel = ViewModel.INSTANCE;
154+
155+
if (!viewModel.isEnabled()) {
156+
instance.swingHand(hand, false);
157+
return;
158+
}
159+
160+
viewModel.adjustSwing(hand, instance);
161+
}
162+
149163
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
150164
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
151165
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) cir.setReturnValue(false);

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
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;
24+
import com.lambda.module.modules.render.ViewModel;
2325
import com.lambda.interaction.request.rotating.RotationManager;
2426
import net.minecraft.entity.LivingEntity;
2527
import net.minecraft.util.math.MathHelper;
2628
import net.minecraft.util.math.Vec3d;
2729
import org.spongepowered.asm.mixin.Mixin;
2830
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;
31+
import org.spongepowered.asm.mixin.Unique;
32+
import org.spongepowered.asm.mixin.injection.*;
3333
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3434

3535
@Mixin(LivingEntity.class)
@@ -38,6 +38,9 @@ public abstract class LivingEntityMixin extends EntityMixin {
3838
@Shadow
3939
protected abstract float getJumpVelocity();
4040

41+
@Unique
42+
private final LivingEntity lambda$instance = (LivingEntity) (Object) this;
43+
4144
/**
4245
* Overwrites the jump function to use our rotation and movements
4346
* <pre>{@code
@@ -55,7 +58,7 @@ public abstract class LivingEntityMixin extends EntityMixin {
5558
*/
5659
@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
5760
void onJump(CallbackInfo ci) {
58-
LivingEntity self = (LivingEntity) (Object) this;
61+
LivingEntity self = lambda$instance;
5962
if (self != Lambda.getMc().player) return;
6063
ci.cancel();
6164

@@ -78,15 +81,14 @@ void onJump(CallbackInfo ci) {
7881

7982
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
8083
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
81-
LivingEntity entity = (LivingEntity) (Object) this;
82-
if (EventFlow.post(new MovementEvent.Entity.Pre(entity, movementInput)).isCanceled()) {
84+
if (EventFlow.post(new MovementEvent.Entity.Pre(lambda$instance, movementInput)).isCanceled()) {
8385
ci.cancel();
8486
}
8587
}
8688

8789
@Inject(method = "travel", at = @At("TAIL"))
8890
void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
89-
EventFlow.post(new MovementEvent.Entity.Post((LivingEntity) (Object) this, movementInput));
91+
EventFlow.post(new MovementEvent.Entity.Post(lambda$instance, movementInput));
9092
}
9193

9294
/**
@@ -123,7 +125,7 @@ private float hookModifyFallFlyingPitch(LivingEntity entity) {
123125
*/
124126
@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)))
125127
private float rotBody(LivingEntity entity) {
126-
if ((Object) this != Lambda.getMc().player) {
128+
if (lambda$instance != Lambda.getMc().player) {
127129
return entity.getYaw();
128130
}
129131

@@ -154,11 +156,18 @@ private float rotBody(LivingEntity entity) {
154156
*/
155157
@Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
156158
private float rotHead(LivingEntity entity) {
157-
if ((Object) this != Lambda.getMc().player) {
159+
if (lambda$instance != Lambda.getMc().player) {
158160
return entity.getYaw();
159161
}
160162

161163
Float yaw = RotationManager.getHeadYaw();
162164
return (yaw == null) ? entity.getYaw() : yaw;
163165
}
166+
167+
@ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6))
168+
private int getHandSwingDuration(int constant) {
169+
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return constant;
170+
171+
return ViewModel.INSTANCE.getSwingDuration();
172+
}
164173
}
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+
}

0 commit comments

Comments
 (0)