Skip to content

Commit a5fd6f3

Browse files
committed
fix rotation render accuracy and potentially other issues
1 parent e1ab355 commit a5fd6f3

File tree

4 files changed

+21
-43
lines changed

4 files changed

+21
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private float rotBody(LivingEntity entity) {
127127
return entity.getYaw();
128128
}
129129

130-
Float yaw = RotationManager.getRenderYaw();
130+
Float yaw = RotationManager.getHeadYaw();
131131
return (yaw == null) ? entity.getYaw() : yaw;
132132
}
133133

@@ -158,7 +158,7 @@ private float rotHead(LivingEntity entity) {
158158
return entity.getYaw();
159159
}
160160

161-
Float yaw = RotationManager.getRenderYaw();
161+
Float yaw = RotationManager.getHeadYaw();
162162
return (yaw == null) ? entity.getYaw() : yaw;
163163
}
164164
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private float injectHeadYaw(PlayerEntity instance) {
4242
return instance.getYaw();
4343
}
4444

45-
Float yaw = RotationManager.getRenderYaw();
45+
Float yaw = RotationManager.getHeadYaw();
4646
return (yaw != null) ? yaw : instance.getYaw();
4747
}
4848

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,16 @@
1717

1818
package com.lambda.mixin.render;
1919

20-
import com.lambda.Lambda;
2120
import com.lambda.interaction.request.rotating.RotationManager;
22-
import net.minecraft.client.render.VertexConsumerProvider;
2321
import net.minecraft.client.render.entity.LivingEntityRenderer;
24-
import net.minecraft.client.util.math.MatrixStack;
2522
import net.minecraft.entity.LivingEntity;
2623
import net.minecraft.util.math.MathHelper;
2724
import org.spongepowered.asm.mixin.Mixin;
28-
import org.spongepowered.asm.mixin.Unique;
2925
import org.spongepowered.asm.mixin.injection.At;
30-
import org.spongepowered.asm.mixin.injection.Inject;
3126
import org.spongepowered.asm.mixin.injection.Redirect;
32-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
33-
34-
import java.util.Objects;
3527

3628
@Mixin(LivingEntityRenderer.class)
3729
public class LivingEntityRendererMixin<T extends LivingEntity> {
38-
@Unique
39-
private Float lambda$pitch = null;
40-
41-
@Inject(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("HEAD"))
42-
private void injectRender(T livingEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
43-
Float rotationPitch = RotationManager.getRenderPitch();
44-
45-
this.lambda$pitch = null;
46-
47-
if (livingEntity != Lambda.getMc().player || rotationPitch == null) {
48-
return;
49-
}
50-
51-
this.lambda$pitch = rotationPitch;
52-
}
53-
5430
/**
5531
* Uses the current rotation render pitch
5632
* <pre>{@code
@@ -63,6 +39,9 @@ private void injectRender(T livingEntity, float f, float g, MatrixStack matrixSt
6339
*/
6440
@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 0), require = 0)
6541
private float injectRotationPitch(float g, float f, float s) {
66-
return Objects.requireNonNullElseGet(lambda$pitch, () -> MathHelper.lerp(g, f, s));
42+
Float headPitch = RotationManager.getHeadPitch();
43+
if (headPitch != null) {
44+
return MathHelper.lerp(g, RotationManager.INSTANCE.getPrevServerRotation().getPitchF(), headPitch);
45+
} else return MathHelper.lerp(g, f, s);
6746
}
6847
}

common/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import com.lambda.interaction.request.rotating.visibilty.lookAt
3636
import com.lambda.module.modules.client.Baritone
3737
import com.lambda.threading.runGameScheduled
3838
import com.lambda.threading.runSafe
39+
import com.lambda.util.extension.partialTicks
3940
import com.lambda.util.extension.rotation
4041
import com.lambda.util.math.MathUtils.toRadian
4142
import com.lambda.util.math.Vec2d
@@ -160,48 +161,46 @@ object RotationManager : RequestHandler<RotationRequest>(
160161
activeRequest = null
161162
}
162163

164+
private val smoothRotation
165+
get() = lerp(mc.partialTicks, serverRotation, activeRotation)
166+
163167
@JvmStatic
164168
val lockRotation
165-
get() =
166-
if (activeRequest?.mode == RotationMode.Lock) activeRotation else null
169+
get() = if (activeRequest?.mode == RotationMode.Lock) smoothRotation else null
167170

168171
@JvmStatic
169-
val renderYaw
170-
get() =
171-
if (activeRequest == null) null else activeRotation.yaw.toFloat()
172+
val headYaw
173+
get() = if (activeRequest == null) null else activeRotation.yawF
172174

173175
@JvmStatic
174-
val renderPitch
175-
get() =
176-
if (activeRequest == null) null else activeRotation.pitch.toFloat()
176+
val headPitch
177+
get() = if (activeRequest == null) null else activeRotation.pitchF
177178

178179
@JvmStatic
179180
val handYaw
180-
get() =
181-
if (activeRequest?.mode == RotationMode.Lock) activeRotation.yaw.toFloat() else null
181+
get() = if (activeRequest?.mode == RotationMode.Lock) activeRotation.yawF else null
182182

183183
@JvmStatic
184184
val handPitch
185-
get() =
186-
if (activeRequest?.mode == RotationMode.Lock) activeRotation.pitch.toFloat() else null
185+
get() = if (activeRequest?.mode == RotationMode.Lock) activeRotation.pitchF else null
187186

188187
@JvmStatic
189188
val movementYaw: Float?
190189
get() {
191-
if (activeRequest?.mode == RotationMode.Silent) return null
190+
if (activeRequest == null || activeRequest?.mode == RotationMode.Silent) return null
192191
return activeRotation.yaw.toFloat()
193192
}
194193

195194
@JvmStatic
196195
val movementPitch: Float?
197196
get() {
198-
if (activeRequest?.mode == RotationMode.Silent) return null
197+
if (activeRequest == null || activeRequest?.mode == RotationMode.Silent) return null
199198
return activeRotation.pitch.toFloat()
200199
}
201200

202201
@JvmStatic
203202
fun getRotationForVector(deltaTime: Double): Vec2d? {
204-
if (activeRequest?.mode == RotationMode.Silent) return null
203+
if (activeRequest == null || activeRequest?.mode == RotationMode.Silent) return null
205204

206205
val rot = lerp(deltaTime, serverRotation, activeRotation)
207206
return Vec2d(rot.yaw, rot.pitch)

0 commit comments

Comments
 (0)