Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import com.lambda.interaction.PlayerPacketManager;
import com.lambda.interaction.request.rotation.RotationManager;
import com.lambda.module.modules.player.PortalGui;
import com.lambda.module.modules.render.ViewModel;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.damage.DamageSource;
Expand Down Expand Up @@ -154,6 +154,18 @@ void onSwingHandPre(Hand hand, CallbackInfo ci) {
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
}

@Redirect(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
ViewModel viewModel = ViewModel.INSTANCE;

if (!viewModel.isEnabled()) {
instance.swingHand(hand, false);
return;
}

viewModel.adjustSwing(hand, instance);
}

@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) cir.setReturnValue(false);
Expand Down
28 changes: 18 additions & 10 deletions common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import com.lambda.event.EventFlow;
import com.lambda.event.events.MovementEvent;
import com.lambda.interaction.request.rotation.RotationManager;
import com.lambda.module.modules.render.ViewModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

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

@Unique
private final LivingEntity lambda$instance = (LivingEntity) (Object) this;

/**
* Overwrites the jump function to use our rotation and movements
* <pre>{@code
Expand All @@ -55,7 +57,7 @@ public abstract class LivingEntityMixin extends EntityMixin {
*/
@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
void onJump(CallbackInfo ci) {
LivingEntity self = (LivingEntity) (Object) this;
LivingEntity self = lambda$instance;
if (self != Lambda.getMc().player) return;
ci.cancel();

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

@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;
if (EventFlow.post(new MovementEvent.Entity.Pre(entity, movementInput)).isCanceled()) {
if (EventFlow.post(new MovementEvent.Entity.Pre(lambda$instance, movementInput)).isCanceled()) {
ci.cancel();
}
}

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

/**
Expand Down Expand Up @@ -123,7 +124,7 @@ private float hookModifyFallFlyingPitch(LivingEntity entity) {
*/
@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)))
private float rotBody(LivingEntity entity) {
if ((Object) this != Lambda.getMc().player) {
if (lambda$instance != Lambda.getMc().player) {
return entity.getYaw();
}

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

Float yaw = RotationManager.getRenderYaw();
return (yaw == null) ? entity.getYaw() : yaw;
}

@ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6))
private int getHandSwingDuration(int constant) {
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return constant;

return ViewModel.INSTANCE.getSwingDuration();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.lambda.mixin.render;

import com.google.common.base.MoreObjects;
import com.lambda.Lambda;
import com.lambda.module.modules.render.ViewModel;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HeldItemRenderer.class)
public class HeldItemRendererMixin {
@Final @Shadow private MinecraftClient client;
@Shadow private ItemStack mainHand;
@Shadow private ItemStack offHand;
@Shadow private float equipProgressMainHand;
@Shadow private float equipProgressOffHand;

@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"))
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) {
if (!ViewModel.INSTANCE.isEnabled()) return;

ViewModel.INSTANCE.transform(itemStack, hand, matrices);
}

@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"))
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) {
if (!ViewModel.INSTANCE.isEnabled()) return;

ViewModel.INSTANCE.transform(itemStack, hand, matrices);
}

@ModifyArg(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", ordinal = 2), index = 0)
private float modifyEquipProgressMainHand(float value) {
if (client.player == null || ViewModel.INSTANCE.isDisabled()) return value;

ViewModel config = ViewModel.INSTANCE;
ItemStack currentStack = client.player.getMainHandStack();
if (config.getOldAnimations() && !config.getSwapAnimation()) {
mainHand = currentStack;
}

float progress = config.getOldAnimations() ? 1 : (float) Math.pow(client.player.getAttackCooldownProgress(1), 3);

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

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

ViewModel config = ViewModel.INSTANCE;

ItemStack currentStack = client.player.getOffHandStack();
if (config.getOldAnimations() && !config.getSwapAnimation()) {
offHand = currentStack;
}

return (ItemStack.areEqual(offHand, currentStack) ? 1 : 0) - equipProgressOffHand;
}

@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)
private float modifySwing(float swingProgress) {
ViewModel config = ViewModel.INSTANCE;
MinecraftClient mc = Lambda.getMc();
if (config.isDisabled() || mc.player == null) return swingProgress;
Hand hand = MoreObjects.firstNonNull(mc.player.preferredHand, Hand.MAIN_HAND);

if (hand == Hand.MAIN_HAND) {
return swingProgress + config.getMainSwingProgress();
} else if (hand == Hand.OFF_HAND) {
return swingProgress + config.getOffhandSwingProgress();
}

return swingProgress;
}
}
Loading