extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarredheroes:wolverine/x23_wolverine_layer1",
    "layer2": "skarredheroes:wolverine/x23_wolverine_layer2",
	"chest": "skarredheroes:wolverine/x23_wolverine_chest",
	"mask": "skarredheroes:wolverine/x23_wolverine_mask",
    "claws": "skarredheroes:wolverine/x23_claws",
    "foot_claws": "skarredheroes:wolverine/x23_foot_claws"
});

var chest;
var ears;
var claws;
var foot_claws;
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 ? "layer1" : "chest";
        }
        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 model_claws = renderer.createResource("MODEL", "skarredheroes:claws");
    model_claws.texture.set("claws");
    model_claws.generateMirror();

    claws = renderer.createEffect("fiskheroes:model").setModel(model_claws);
    claws.anchor.set("rightArm");
    claws.mirror = true;
	
    ears = renderer.createEffect("fiskheroes:ears");
    ears.anchor.set("head");
    ears.angle = 18;
    ears.inset = 0.005;
	
	var model_foot_claws = renderer.createResource("MODEL", "skarredheroes:foot_claws");
    model_foot_claws.texture.set("foot_claws");
    model_foot_claws.generateMirror();

    foot_claws = renderer.createEffect("fiskheroes:model").setModel(model_foot_claws);
    foot_claws.anchor.set("rightLeg");
    foot_claws.mirror = true;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
        var unfold = entity.getInterpolatedData("fiskheroes:blade_timer");
        claws.setOffset(1.5, -12.0 + 1.35 * Math.min(unfold * 5, 3.5), -1.0);
        claws.render();
        chest.render();
	}
    if (renderLayer == "LEGGINGS") {
        var unfold = entity.getInterpolatedData("fiskheroes:blade_timer");
        foot_claws.setOffset(-0.5, -6.0, 2.0 + 1.35 * Math.min(unfold * -2.5, 1.0));
        foot_claws.render();
	}
    if (!isFirstPersonArm && renderLayer == "HELMET") {
        ears.render();
    }
}
