From 26314dbb8ddcbcb54bfc32f95b8dfab2398e2229 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 14 Dec 2024 14:18:56 -0500 Subject: [PATCH] Cleanup --- .../MixinClientPlayerInteractionManager.java | 2 +- .../MixinFishingBobberEntityRenderer.java | 24 +++++++------------ .../mixins/MixinFlyingItemEntityRenderer.java | 7 +++--- .../mixins/MixinHeldItemRenderer.java | 9 ++++--- .../mixins/MixinLivingEntityRenderer.java | 4 ++-- .../animatium/mixins/MixinWorldRenderer.java | 16 ++++++------- .../util/{HandUtils.java => PlayerUtils.java} | 12 +++++++++- 7 files changed, 40 insertions(+), 34 deletions(-) rename src/main/java/me/mixces/animatium/util/{HandUtils.java => PlayerUtils.java} (55%) diff --git a/src/main/java/me/mixces/animatium/mixins/MixinClientPlayerInteractionManager.java b/src/main/java/me/mixces/animatium/mixins/MixinClientPlayerInteractionManager.java index 4623567..6a506d3 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinClientPlayerInteractionManager.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinClientPlayerInteractionManager.java @@ -13,7 +13,7 @@ public abstract class MixinClientPlayerInteractionManager { @Shadow private float currentBreakingProgress; - @Inject(method = "getBlockBreakingProgress", at = @At(value = "HEAD"), cancellable = true) + @Inject(method = "getBlockBreakingProgress", at = @At(value = "RETURN"), cancellable = true) private void animatium$oldBlockMiningProgress(CallbackInfoReturnable cir) { if (AnimatiumConfig.oldBlockMiningProgress) { cir.setReturnValue((int) (this.currentBreakingProgress * 10.0f) - 1); diff --git a/src/main/java/me/mixces/animatium/mixins/MixinFishingBobberEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/MixinFishingBobberEntityRenderer.java index 30c58aa..8105f5b 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinFishingBobberEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinFishingBobberEntityRenderer.java @@ -6,7 +6,7 @@ import com.llamalad7.mixinextras.sugar.Local; import me.mixces.animatium.config.AnimatiumConfig; import me.mixces.animatium.mixins.accessor.CameraAccessor; -import me.mixces.animatium.util.HandUtils; +import me.mixces.animatium.util.PlayerUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderer; @@ -20,7 +20,6 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -33,12 +32,12 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) { } @Inject(method = "render(Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;peek()Lnet/minecraft/client/util/math/MatrixStack$Entry;", ordinal = 0)) - private void animatium$oldFishingBobberPosition(FishingBobberEntityState fishingBobberEntityState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { + private void animatium$oldFishingBobberPosition(FishingBobberEntityState fishingBobberEntityState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { if (AnimatiumConfig.oldFishingBobberPosition) { assert MinecraftClient.getInstance().player != null; - int multiplier = HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher); + int multiplier = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher); //TODO: Fix line - matrixStack.translate(multiplier * 0.5F, 0.0F, 0.0F); + matrices.translate(multiplier * 0.5F, 0.0F, 0.0F); } } @@ -47,9 +46,10 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) { if (AnimatiumConfig.fishingRodLineInterpolation) { CameraAccessor cameraAccessor = (CameraAccessor) dispatcher.camera; float eyeHeight = MathHelper.lerp(v, cameraAccessor.getLastCameraY(), cameraAccessor.getCameraY()); - return this.animatium$getCameraPosVec(instance, v, eyeHeight); + return PlayerUtils.lerpPlayerWithEyeHeight(instance, v, eyeHeight); + } else { + return original.call(instance, v); } - return original.call(instance, v); } @ModifyExpressionValue(method = "getHandPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isInSneakingPose()Z")) @@ -70,15 +70,7 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) { @ModifyArg(method = "updateRenderState(Lnet/minecraft/entity/projectile/FishingBobberEntity;Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/FishingBobberEntityRenderer;getHandPos(Lnet/minecraft/entity/player/PlayerEntity;FF)Lnet/minecraft/util/math/Vec3d;"), index = 1) private float animatium$fixCastLineSwing(float f) { assert MinecraftClient.getInstance().player != null; - int multiplier = HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher); + int multiplier = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher); return f * (AnimatiumConfig.fixCastLineSwing ? multiplier : 1); } - - @Unique - private Vec3d animatium$getCameraPosVec(PlayerEntity entity, float tickDelta, float eyeHeight) { - double d = MathHelper.lerp(tickDelta, entity.prevX, entity.getX()); - double e = MathHelper.lerp(tickDelta, entity.prevY, entity.getY()) + eyeHeight; - double f = MathHelper.lerp(tickDelta, entity.prevZ, entity.getZ()); - return new Vec3d(d, e, f); - } } diff --git a/src/main/java/me/mixces/animatium/mixins/MixinFlyingItemEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/MixinFlyingItemEntityRenderer.java index d44b9d7..e6abcb9 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinFlyingItemEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinFlyingItemEntityRenderer.java @@ -1,7 +1,7 @@ package me.mixces.animatium.mixins; import me.mixces.animatium.config.AnimatiumConfig; -import me.mixces.animatium.util.HandUtils; +import me.mixces.animatium.util.PlayerUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderer; @@ -23,10 +23,11 @@ protected MixinFlyingItemEntityRenderer(EntityRendererFactory.Context ctx) { } @Inject(method = "render(Lnet/minecraft/client/render/entity/state/FlyingItemEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderState;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V")) - private void animatium$oldProjectilePosition(FlyingItemEntityRenderState flyingItemEntityRenderState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { + private void animatium$oldProjectilePosition(FlyingItemEntityRenderState flyingItemEntityRenderState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { if (AnimatiumConfig.oldProjectilePosition) { assert MinecraftClient.getInstance().player != null; - matrixStack.translate(HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher) * 0.25F, 0.0F, 0.25F); + int direction = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher); + matrices.translate(direction * 0.25F, 0.0F, 0.25F); } } } diff --git a/src/main/java/me/mixces/animatium/mixins/MixinHeldItemRenderer.java b/src/main/java/me/mixces/animatium/mixins/MixinHeldItemRenderer.java index 609a497..8bc6840 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinHeldItemRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinHeldItemRenderer.java @@ -34,12 +34,15 @@ public abstract class MixinHeldItemRenderer { @WrapOperation(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;scale(FFF)V", ordinal = 1)) private void animatium$postBowTransform(MatrixStack instance, float x, float y, float z, Operation original, @Local(argsOnly = true) AbstractClientPlayerEntity player, @Local(argsOnly = true) Hand hand) { + final Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); + final int direction = arm == Arm.RIGHT ? 1 : -1; if (AnimatiumConfig.tiltItemPositions) { - final Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); - final int direction = arm == Arm.RIGHT ? 1 : -1; instance.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * -335)); instance.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -50.0F)); - original.call(instance, x, y, z); + } + + original.call(instance, x, y, z); + if (AnimatiumConfig.tiltItemPositions) { instance.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 50.0F)); instance.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * 335)); } diff --git a/src/main/java/me/mixces/animatium/mixins/MixinLivingEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/MixinLivingEntityRenderer.java index 7e986f4..3cfa3ca 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinLivingEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinLivingEntityRenderer.java @@ -24,7 +24,7 @@ @Mixin(LivingEntityRenderer.class) public abstract class MixinLivingEntityRenderer { @Inject(method = "render(Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V", ordinal = 1)) - private void animatium$syncPlayerModelWithEyeHeight(S livingEntityRenderState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { + private void animatium$syncPlayerModelWithEyeHeight(S livingEntityRenderState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { if (AnimatiumConfig.syncPlayerModelWithEyeHeight) { MinecraftClient client = MinecraftClient.getInstance(); ClientPlayerEntity player = client.player; @@ -32,7 +32,7 @@ public abstract class MixinLivingEntityRenderer= 0.0) { ShaderProgram shaderProgram = RenderSystem.setShader(ShaderProgramKeys.POSITION); @@ -79,14 +79,14 @@ public abstract class MixinWorldRenderer { RenderSystem.setShaderColor(skyColorVec.x, skyColorVec.y, skyColorVec.z, 1.0F); } - matrixStack.push(); - matrixStack.multiplyPositionMatrix(RenderSystem.getModelViewMatrix()); - matrixStack.translate(0.0F, -((float) (depth - 16.0)), 0.0F); + matrices.push(); + matrices.multiplyPositionMatrix(RenderSystem.getModelViewMatrix()); + matrices.translate(0.0F, -((float) (depth - 16.0)), 0.0F); SkyRenderingAccessor skyRenderingAccessor = (SkyRenderingAccessor) this.skyRendering; skyRenderingAccessor.getDarkSkyBuffer().bind(); - skyRenderingAccessor.getDarkSkyBuffer().draw(matrixStack.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), shaderProgram); + skyRenderingAccessor.getDarkSkyBuffer().draw(matrices.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), shaderProgram); VertexBuffer.unbind(); - matrixStack.pop(); + matrices.pop(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } diff --git a/src/main/java/me/mixces/animatium/util/HandUtils.java b/src/main/java/me/mixces/animatium/util/PlayerUtils.java similarity index 55% rename from src/main/java/me/mixces/animatium/util/HandUtils.java rename to src/main/java/me/mixces/animatium/util/PlayerUtils.java index 256ac01..732129f 100644 --- a/src/main/java/me/mixces/animatium/util/HandUtils.java +++ b/src/main/java/me/mixces/animatium/util/PlayerUtils.java @@ -3,14 +3,24 @@ import com.google.common.base.MoreObjects; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Arm; import net.minecraft.util.Hand; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; -public class HandUtils { +public class PlayerUtils { public static int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); int i = dispatcher.gameOptions.getPerspective().isFirstPerson() ? 1 : -1; return arm == Arm.RIGHT ? i : -i; } + + public static Vec3d lerpPlayerWithEyeHeight(PlayerEntity entity, float tickDelta, float eyeHeight) { + double d = MathHelper.lerp(tickDelta, entity.prevX, entity.getX()); + double e = MathHelper.lerp(tickDelta, entity.prevY, entity.getY()) + eyeHeight; + double f = MathHelper.lerp(tickDelta, entity.prevZ, entity.getZ()); + return new Vec3d(d, e, f); + } }