From 935c1cdf9fe01183312bb37e8fdd667bfa641915 Mon Sep 17 00:00:00 2001 From: lowercasebtw <126462578+lowercasebtw@users.noreply.github.com> Date: Tue, 20 Aug 2024 02:22:11 -0500 Subject: [PATCH] Apply slight rotation for non-block-items in rendering in <= 1.7.10 (#535) * Tilt Firstperson Handheld Items <=1.7.x * Reformat Code * Reformat Code Again * Made Requested Changes * Move Method To Bottom --- .../minecraft/item/MixinHeldItemRenderer.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java index c14d3c40..a35e5762 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java @@ -19,11 +19,14 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import de.florianmichael.viafabricplus.settings.impl.VisualSettings; 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.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.util.Arm; import net.minecraft.util.Hand; @@ -64,4 +67,20 @@ public abstract class MixinHeldItemRenderer { matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * 78.05F)); } + + @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", ordinal = 1)) + private void transformItemPosition1_7(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack stack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { + // Modifies the handheld position to be slightly tilted like in 1.7 and prior + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6) && !(stack.getItem() instanceof BlockItem)) { + final Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); + final int direction = arm == Arm.RIGHT ? 1 : -1; + + final float scale = 0.7585F / 0.86F; + matrices.scale(scale, scale, scale); + matrices.translate(direction * -0.084F, 0.059F, 0.08F); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 5.0F)); + } + } + }