extend("fiskheroes:hero_basic");
loadTextures({
    "suit": "tgheroes:thor/thor/thor_suit",
	"hair": "tgheroes:thor/thor/thor_hair",
    "leggings": "tgheroes:thor/thor/thor_layer2",
    "mjolner": "tgheroes:thor/mjolner",
	"boots": "tgheroes:thor/thor/thor_boots",
	"cape": "tgheroes:thor/thor/thor_cape"
});

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

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "suit" : "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) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.3;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;
    cape = capes.createDefault(renderer, 26, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 19;
	
	var model_mjolner = renderer.createResource("MODEL", "tgheroes:mjolner");
    model_mjolner.texture.set("mjolner");


    mjolner = renderer.createEffect("fiskheroes:model").setModel(model_mjolner);
    mjolner.anchor.set("rightArm");
    mjolner.setScale(1);

	
	var beam = renderer.createResource("BEAM_RENDERER", "tgheroes:doom_beam");
    utils.bindBeam(renderer, "fiskheroes:charged_beam", beam, "rightArm", 0x0022FF, [
        {"firstPerson": [-3.0, 1.0, -5.0], "offset": [0.0, 0.0, 0.0], "size": [4.0, 4.0] }
    ]);

}

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

    // Charged Beam
    addAnimation(renderer, "LIGHTNING", "tgheroes:thor_aim").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, "thor.FLIGHT", "tgheroes:flight/thor.anim.json");
    utils.addHoverAnimation(renderer, "thor.HOVER", "fiskheroes:flight/idle/martian_comics");;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
        if (entity.getData("fiskheroes:blade_timer") > 0.9) {
            var blade_anchor = mjolner.anchor.set("rightArm");
            var blade_offSet = mjolner.setOffset(1.0, 9.0, -6.5);
            var blade_rot = mjolner.setRotation(90, 90, 0);
            

			
            mjolner.anchor = blade_anchor, blade_offSet, blade_rot;
            mjolner.render();
        }


}
		        if (renderLayer == "CHESTPLATE") {
            cape.render(entity);
}
}