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
This commit is contained in:
lowercasebtw 2024-08-20 02:22:11 -05:00 committed by GitHub
parent a71bb0b552
commit 935c1cdf9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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));
}
}
}