extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:puss_in_boots_layer1",
    "layer2": "pkg:puss_in_boots_layer2",
    "cape": "pkg:puss_in_boots_cape",
    "lights": "pkg:puss_in_boots_lights",
    "pants_robes": "pkg:puss_in_boots_pants_robes",
    "sword": "pkg:puss_in_boots_sword"
});

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

var cape;
var sword;
var sword_back;

function init(renderer) {
    parent.init(renderer);
    renderer.setLights((entity, renderLayer) => renderLayer == "CHESTPLATE" ? "lights" : null);

    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm");
    renderer.fixHatLayer("CHESTPLATE");
}

function initEffects(renderer) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    cape = capes.createDefault(renderer, 17, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 12;

    sword = renderer.createEffect("fiskheroes:model");
    sword.setModel(utils.createModel(renderer, "pkg:sword", "sword", null));
    sword.anchor.set("rightArm");
    sword.mirror = false;

}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    addAnimation(renderer, "WALL_RUN", "pkg:wall_running").setData((entity, data) => {
        var input_rotate = entity.getInterpolatedData("pkg:dyn/climb") > 0 ? 1 : 0;
        data.load(0, entity.getInterpolatedData("pkg:dyn/climb") * 2);
        data.load(1, entity.getInterpolatedData("pkg:dyn/climb") * 2);
        data.load(2, input_rotate); // rotation data var doesnt work for this
        data.load(4, -(input_rotate / 3.5));

    })
    addAnimationWithData(renderer, "iron_man.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;
    utils.addHoverAnimation(renderer, "general_zod.HOVER", "fiskheroes:flight/idle/neutral");

}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity);
    }
    if (entity.getData("fiskheroes:blade_timer") > 0.6) {
        var sword_anchor = sword.anchor.set("rightArm");
        var sword_offSet = sword.setOffset(0.0, 0.0, 0.0);
        var sword_rot = sword.setRotation(0, 0, 0);

        sword.anchor = sword_anchor, sword_offSet, sword_rot;
        sword.render();
    }
    else {
        var back_anchor = sword.anchor.set("body");
        var back_offSet = sword.setOffset(-4.7, 4.5, -1);
        var back_rot = sword.setRotation(-30.0, -175.0, -5.0);

        sword.anchor = back_anchor, back_offSet, back_rot;
        sword.render();
    }
}