package com.thebrokenrail.herobrine.client.entity;

import com.thebrokenrail.herobrine.HerobrineRewoven;
import com.thebrokenrail.herobrine.entity.HerobrineEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer;
import net.minecraft.client.render.entity.feature.StuckArrowsFeatureRenderer;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class HerobrineEntityRenderer extends LivingEntityRenderer<HerobrineEntity, HerobrineEntityRenderer.Model> {
    protected static class Model extends PlayerEntityModel<HerobrineEntity> {
        public Model(float scale, boolean thinArms) {
            super(scale, thinArms);
        }

        @Override
        protected void method_29353(HerobrineEntity livingEntity, float f) {
            super.method_29353(livingEntity, f);
            // Set Arm Angles
            switch (livingEntity.getDataTracker().get(HerobrineEntity.POSE)) {
                case FIREBALL: {
                    leftArm.pitch = -45;
                    leftArm.yaw = -6;
                    leftArm.roll = 0;
                    rightArm.pitch = -45;
                    rightArm.yaw = 6;
                    rightArm.roll = 0;
                    break;
                }
                case LIGHTNING: {
                    leftArm.roll = -128;
                    leftArm.yaw = 0;
                    leftArm.pitch = 0;
                    rightArm.roll = 210;
                    leftArm.yaw = 0;
                    rightArm.pitch = 0;
                    break;
                }
                case NORMAL:
                default: {
                    leftArm.yaw = 0;
                    leftArm.roll = 0;
                    rightArm.yaw = 0;
                    rightArm.roll = 0;
                    break;
                }
            }
        }
    }

    public HerobrineEntityRenderer(EntityRenderDispatcher dispatcher) {
        super(dispatcher, new Model(0.0f, false), 0.5f);
        addFeature(new HeldItemFeatureRenderer<>(this));
        addFeature(new StuckArrowsFeatureRenderer<>(this));
    }

    @Override
    public Identifier getTexture(HerobrineEntity entity) {
        return new Identifier(HerobrineRewoven.NAMESPACE, "textures/entity/herobrine.png");
    }

    @Override
    protected void renderLabelIfPresent(HerobrineEntity herobrineEntity, Text text, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
        matrixStack.push();
        super.renderLabelIfPresent(herobrineEntity, text, matrixStack, vertexConsumerProvider, i);
        matrixStack.pop();
    }

    @Override
    protected boolean hasLabel(HerobrineEntity livingEntity) {
        return true;
    }
}
