extend("fiskheroes:hero_basic");
loadTextures({
	"hair": "tgheroes:crystal/crystal_hair_noskin",
	"suit": "tgheroes:crystal/crystal_suit",
    "leggings": "tgheroes:crystal/crystal_legs",
    "boots": "tgheroes:crystal/crystal_boots",
	"suit_hair": "tgheroes:crystal/crystal_suit_hair"
});

var chest;

var utils = implement("fiskheroes:external/utils");


function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "suit_hair" : "suit";
        }
	    else if (renderLayer == "LEGGINGS") {
            return entity.getWornChestplate().suitType() == $SUIT_NAME ? "leggings" : "leggings";
		}
        return renderLayer == "HELMET" ? "hair" : "boots" 
    });

    renderer.showModel("HELMET", "head", "headwear", "body");
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");
}

function initEffects(renderer) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1).setYOffset(1);


    utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:lightning_cast", "body", 0x0022FF, [
        { "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [1.5, 1.5] }])
}



function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("LIGHTNING");

    // Charged Beam
    addAnimation(renderer, "LIGHTNING", "fiskheroes:dual_hand_beam").setData((entity, data) => {
        var charge = entity.getInterpolatedData("fiskheroes:beam_charge");
        data.load(Math.max(entity.getInterpolatedData("fiskheroes:aiming_timer"), entity.getData("fiskheroes:beam_charging") ? Math.min(charge * 3, 1) : Math.max(charge * 5 - 4, 0)));
    });
    

   utils.addFlightAnimation(renderer, "crystal.FLIGHT", "fiskheroes:flight/martian_comics.anim.json");
    utils.addHoverAnimation(renderer, "crystal.HOVER", "fiskheroes:flight/idle/martian_comics");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        chest.render();
    }
}
