/*
 * Copyright (c) 2026 盐灯水母
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package com.remains_cave.item.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import com.remains_cave.item.custom.BonePauldronItem;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import software.bernie.geckolib.renderer.GeoItemRenderer;

public class BonePauldronRenderer extends GeoItemRenderer<BonePauldronItem> {
    public BonePauldronRenderer() {
        super(new BonePauldronModel());
    }

    @Override
    public void renderByItem(ItemStack stack, ItemDisplayContext transformType,
                             PoseStack poseStack, MultiBufferSource bufferSource,
                             int packedLight, int packedOverlay) {
        // 隐藏所有手持状态，因为这些状态会被手臂上的模型覆盖
        if (transformType == ItemDisplayContext.FIRST_PERSON_LEFT_HAND ||
                transformType == ItemDisplayContext.THIRD_PERSON_LEFT_HAND ||
                transformType == ItemDisplayContext.HEAD) {
            return;
        }

        poseStack.pushPose();

        switch (transformType) {
            case THIRD_PERSON_RIGHT_HAND://第三人称主手
                poseStack.mulPose(Axis.YP.rotationDegrees(90));
                poseStack.translate(-0.5, -1.25, -0.0);
                break;
            case FIRST_PERSON_RIGHT_HAND://第一人称主手
                poseStack.mulPose(Axis.YP.rotationDegrees(90));
                poseStack.translate(-0.25, -1.0, 0.25);
                break;
            case GUI://GUI
                poseStack.mulPose(Axis.ZP.rotationDegrees(-45));
                poseStack.translate(-0.1, -1.05, 0);
                break;
            case GROUND://掉落物
                poseStack.mulPose(Axis.ZP.rotationDegrees(-45));
                poseStack.translate(-0.3, -1.05, 0.0);
                break;
            case FIXED:
                poseStack.mulPose(Axis.ZP.rotationDegrees(-45));
                poseStack.mulPose(Axis.YP.rotationDegrees(-90));
                poseStack.translate(0.375, -1.05, -0.5);
                break;
            default:
                break;
        }

        super.renderByItem(stack, transformType, poseStack, bufferSource, packedLight, packedOverlay);

        poseStack.popPose();
    }
}