Skip to content

Commit

Permalink
[VirtualInput] Added calculations for pitch and yaw
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Feb 13, 2024
1 parent 780274f commit 4371a78
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
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.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
Expand All @@ -18,6 +17,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.math.MathHelper;

/**
* Redirects the camera to use {@link VirtualInput.VirtualCameraAngleInput}.<br>
Expand All @@ -30,11 +30,23 @@ public class MixinEntityRenderer implements SubtickDuck {
private Minecraft mc;


@Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;turn(FF)V", shift = Shift.AFTER))
public void playback_injectAfterTurn(CallbackInfo ci) {
TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(mc.player.rotationPitch, mc.player.rotationYaw);
mc.player.rotationPitch = TASmodClient.virtual.CAMERA_ANGLE.getCurrentPitch();
mc.player.rotationYaw = TASmodClient.virtual.CAMERA_ANGLE.getCurrentYaw();
@ModifyArgs(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;turn(FF)V"))
public void playback_injectAfterTurn(Args arguments) {
double pitchDelta = (double)(float) arguments.get(1);
double yawDelta = (double)(float) arguments.get(0);

pitchDelta *=0.15D;
yawDelta *= 0.15D;

float pitch = (float) ((double)mc.player.rotationPitch - pitchDelta);
pitch = MathHelper.clamp(pitch, -90.0F, 90.0F);

float yaw = (float) ((double)mc.player.rotationYaw + yawDelta);

TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(pitch, yaw);

arguments.set(0, 0f);
arguments.set(1, 0f);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public float getCurrentYaw() {

public Triple<Float, Float, Float> getInterpolatedState(float partialTick, float pitch, float yaw, boolean enable){
if(!enable) {
return Triple.of(nextCameraAngle.getPitch(), nextCameraAngle.getYaw()+180, 0f);
return Triple.of(pitch, yaw, 0f);
}

float interpolatedPitch = 0f;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/tasmod/virtual/VirtualInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.minecrafttas.tasmod.virtual.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.minecrafttas.tasmod.virtual.VirtualInput;
Expand Down

0 comments on commit 4371a78

Please sign in to comment.