Feature: ViewModel module by beanbag44 · Pull Request #128 · lambda-client/lambda · GitHub
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
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();
}
}
Loading