package codechicken.lib.model;

import codechicken.lib.util.TransformUtils;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.resources.model.BakedModel;
import org.jetbrains.annotations.Nullable;

/**
 * A simple {@link BakedModel} implementation, with automatic handling of
 * {@link PerspectiveModelState}s.
 * <p>
 * Created by covers1624 on 9/7/22.
 *
 * @see TransformUtils
 */
public interface PerspectiveModel extends BakedModel {

    /**
     * The {@link PerspectiveModelState} for this model.
     *
     * @return The state or {@code null} for vanilla behaviour.
     */
    @Nullable
    PerspectiveModelState getModelState();

    @Override
    default BakedModel applyTransform(ItemTransforms.TransformType transformType, PoseStack pStack, boolean leftFlip) {
        PerspectiveModelState modelState = getModelState();
        if (modelState != null) {
            getModelState().getTransform(transformType).push(pStack);
            if (leftFlip) {
                TransformUtils.applyLeftyFlip(pStack);
            }
            return this;
        }
        return BakedModel.super.applyTransform(transformType, pStack, leftFlip);
    }
}

@@ -113,16 +113,88 @@
 eStack;%0A
+import com.mojang.math.Transformation;%0Aimport com.mojang.math.Vector3f;%0A
 import n
@@ -1033,16 +1033,43 @@
         
+ Transformation transform =
  getMode
@@ -1108,22 +1108,359 @@
 ype)
-.push(pStack);
+;%0A%0A            Vector3f trans = transform.getTranslation();%0A            pStack.translate(trans.x(), trans.y(), trans.z());%0A%0A            pStack.mulPose(transform.getLeftRotation());%0A%0A            Vector3f scale = transform.getScale();%0A            pStack.scale(scale.x(), scale.y(), scale.z());%0A%0A            pStack.mulPose(transform.getRightRotation());%0A
 %0A   

Fix issues with uneven pose stack push-pop in IItemRenderer