extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:miss_martian/miss_martian_layer1",
    "layer2": "skarlet:miss_martian/miss_martian_layer2",
    "mask": "skarlet:miss_martian/miss_martian_mask",
    "boots": "skarlet:miss_martian/miss_martian_boots",
    "boots_leggings": "skarlet:miss_martian/miss_martian_boots_leggings",
    "chest": "skarlet:miss_martian/miss_martian_chest",
    "cape": "skarlet:miss_martian/miss_martian_cape",
    "capehair": "skarlet:miss_martian/miss_martian_cape_hair"
});

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

var physics;

var cape;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "layer1" : "chest";
        }
        else if (renderLayer == "BOOTS") {
            return entity.getWornLeggings().suitType() == $SUIT_NAME ? "boots_leggings" : "boots";
        }
        return renderLayer == "HELMET" ? "mask" : renderLayer == "LEGGINGS" ? "layer2" : "layer1";
    });

    renderer.showModel("HELMET", "head", "headwear", "body");
}

function initEffects(renderer) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.5).setYOffset(1);
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 1.3;
    physics.maxFlare = 0.6;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.width = 14;
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "mmc.FLIGHT", "fiskheroes:flight/martian_comics.anim.json");
    utils.addHoverAnimation(renderer, "mmc.HOVER", "fiskheroes:flight/idle/martian_comics");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
        chest.render();
        if (entity.getEquipmentInSlot(4).nbt().getString('HeroType') == 'skarlet:miss_martian') {
			cape.effect.texture.set("capehair");
        } else {
			cape.effect.texture.set("cape");
		}
    }
}
