package com.xfestudio.mydimensionlord.client.gear;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;

/** Shared model-space bone animation for all six ports, including GUI/dropped items. */
public final class GearAnimation {
    public static final String[] GEAR = {"dimension_blade", "dimension_pickaxe", "lord_helmet", "lord_chestplate", "lord_leggings", "lord_boots"};
    public static final String[] PARTS = {"body", "core", "halo", "shards"};
    private GearAnimation() {}
    public static boolean hasPart(String gear, int part) {
        if (gear.equals("lord_helmet") && part == 1) return false;
        return part != 2 || gear.startsWith("dimension_");
    }
    public static double bob(long millis, double phase) {
        return Math.sin(millis * (Math.PI * 2.0 / 3200.0) + phase);
    }
    public static void pose(PoseStack pose, String gear, int part, long millis) {
        if (part == 0) return;
        boolean weapon = gear.startsWith("dimension_");
        double y = gear.equals("dimension_blade") ? 12.69 : gear.equals("dimension_pickaxe") ? 20.67 : 8.0;
        if (part == 2 && gear.equals("dimension_pickaxe")) y = 23.4;
        double turn = (millis % 8000L) * (360.0 / 8000.0);
        pose.translate(0.5, y / 16.0, 0.5);
        if (part == 1) {
            pose.translate(0, bob(millis, 0) * (weapon ? .022 : .008), 0);
            double coreTurn = gear.equals("dimension_blade") ? bob(millis, 1) * 18 : weapon ? turn : bob(millis, 1) * 7;
            pose.mulPose((weapon ? Axis.YP : Axis.ZP).rotationDegrees((float)coreTurn));
        } else if (part == 2) {
            // Slow independent orbit around the core; the pick's upper halo has
            // its own height, so it never passes through the head or fingers.
            pose.mulPose(Axis.YP.rotationDegrees((float)-turn));
        } else {
            pose.translate(0, bob(millis, 2) * .035, 0);
            pose.mulPose((weapon ? Axis.YP : Axis.ZP).rotationDegrees((float)(weapon ? turn : bob(millis, 2) * 4)));
        }
        pose.translate(-0.5, -y / 16.0, -0.5);
    }
}
