Skip to content

Commit 4266828

Browse files
committed
swing duration, swing progress, no swing delay settings and refactors / small fixes
1 parent aae80d3 commit 4266828

File tree

4 files changed

+160
-165
lines changed

4 files changed

+160
-165
lines changed

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
}

common/src/main/java/com/lambda/mixin/render/HeldItemRendererMixin.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.lambda.mixin.render;
22

3+
import com.google.common.base.MoreObjects;
4+
import com.lambda.Lambda;
35
import com.lambda.module.modules.render.ViewModel;
46
import net.minecraft.client.MinecraftClient;
57
import net.minecraft.client.network.AbstractClientPlayerEntity;
@@ -14,6 +16,7 @@
1416
import org.spongepowered.asm.mixin.injection.At;
1517
import org.spongepowered.asm.mixin.injection.Inject;
1618
import org.spongepowered.asm.mixin.injection.ModifyArg;
19+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
1720
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1821

1922
@Mixin(HeldItemRenderer.class)
@@ -44,26 +47,42 @@ private float modifyEquipProgressMainHand(float value) {
4447

4548
ViewModel config = ViewModel.INSTANCE;
4649
ItemStack currentStack = client.player.getMainHandStack();
47-
if (!config.getSwapAnimation()) {
50+
if (config.getOldAnimations() && !config.getSwapAnimation()) {
4851
mainHand = currentStack;
4952
}
5053

51-
float progress = config.getOldAnimations() || !config.getSwapAnimation() ? 1 : (float) Math.pow(client.player.getAttackCooldownProgress(1), 3);
54+
float progress = config.getOldAnimations() ? 1 : (float) Math.pow(client.player.getAttackCooldownProgress(1), 3);
5255

5356
return (ItemStack.areEqual(mainHand, currentStack) ? progress : 0) - equipProgressMainHand;
5457
}
5558

5659
@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 3), index = 0)
57-
private float modifyEquipProgressOffhand(float value) {
60+
private float modifyEquipProgressOffHand(float value) {
5861
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;
5962

6063
ViewModel config = ViewModel.INSTANCE;
6164

6265
ItemStack currentStack = client.player.getOffHandStack();
63-
if (!config.getSwapAnimation()) {
66+
if (config.getOldAnimations() && !config.getSwapAnimation()) {
6467
offHand = currentStack;
6568
}
6669

67-
return (ItemStack.areEqual(offHand, currentStack) || !config.getSwapAnimation() ? 1 : 0) - equipProgressOffHand;
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;
6887
}
6988
}

0 commit comments

Comments
 (0)