extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "pkg:kang_layer1",
    "layer2": "pkg:kang_layer2",
    "cape": "pkg:kang_cape",
    "lights": "pkg:kang_lights_layer1",
    "mask": "pkg:kang_mask",
    "mask_anim": "pkg:kang_mask.tx.json"
});

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

var cape;

function init(renderer) {
    parent.init(renderer);
   // renderer.setLights((entity, renderLayer) => renderLayer == "" ? "" : "mask");

    renderer.setLights((entity, renderLayer) => {
        if (renderLayer == "HELMET" && entity.getData("fiskheroes:mask_open_timer2") <= 0) {
            return "mask";
        }
        return 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.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.texture.set("cape");
    cape.effect.width = 16;

    utils.bindCloud(renderer, "fiskheroes:telekinesis", "pkg:telekinesis_kang");

    //utils.bindTrail(renderer, "pkg:anodite");


    overlay = renderer.createEffect("fiskheroes:overlay");
    overlay.texture.set(null, "mask_anim");

    var color = 0x2327E8;

    var magic = renderer.bindProperty("fiskheroes:spellcasting");
    magic.colorGeneric.set(color);
    magic.colorWhip.set(color);

    // Charged Beam
    var beam = renderer.createResource("BEAM_RENDERER", "fiskheroes:mysterio_beam");
    utils.bindBeam(renderer, "fiskheroes:charged_beam", beam, "body", color, [{
        "firstPerson": [0.0, 6.0, 0.0], "offset": [0.0, 5.0, -4.0], "size": [4.0, 4.0]
    }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_charged_beam"));
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    renderer.removeCustomAnimation("basic.CHARGED_BEAM");

    addAnimation(renderer, "loki.CHARGED_BEAM", "fiskheroes:dual_hand_beam").setData((entity, data) => data.load(Math.max(entity.getInterpolatedData("fiskheroes:beam_charge") * 5 - 4, 0)));
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
            cape.render(entity);
        }
    if (!isFirstPersonArm && renderLayer == "HELMET") {
        overlay.opacity = 1 - entity.getInterpolatedData("fiskheroes:mask_open_timer2");

        if (overlay.opacity < 1) {
            overlay.render();
        }
      }
}