extend("skarlet:ash_williams_base");
loadTextures({
    "boots": "skarlet:ash_williams/doombot_boots",
    "layer2": "skarlet:ash_williams/doombot_layer2",
    "chest": "skarlet:ash_williams/doombot_chest",
    "cape": "skarlet:ash_williams/doombot_cape",
    "chainsaw_chest": "skarlet:ash_williams/chainsaw_doombot_chest",
	"holster": "skarlet:ash_williams/knight_holster"
});

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

var cape;
var boomstick_back;
var holster;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => renderLayer == "CHESTPLATE" && entity.getData('fiskheroes:blade_timer') >= 0.3 ? "chainsaw_chest" : renderLayer == "CHESTPLATE" ? "chest" : renderLayer == "LEGGINGS" ? "layer2" : "boots");

    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm", "rightLeg", "leftLeg");

    renderer.setLights((entity, renderLayer) => renderLayer == "CHESTPLATE" ? null : null);
}

function initEffects(renderer) {
    parent.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, 23, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 17;
	
    var model_holster = renderer.createResource("MODEL", "skarlet:holster");
    model_holster.texture.set("holster");

    holster = renderer.createEffect("fiskheroes:model").setModel(model_holster);
    holster.anchor.set("body");
    holster.setOffset(-0.6, 0.0, 0.0);
	
    var model_boomstick_back = renderer.createResource("MODEL", "skarlet:back_boomstick");
    model_boomstick_back.texture.set("boomstick");

    boomstick_back = renderer.createEffect("fiskheroes:model").setModel(model_boomstick_back);
    boomstick_back.anchor.set("body");
    boomstick_back.setOffset(-0.4, 0.0, 0.4);
	boomstick_back.setScale(0.9);
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
}

function render(entity, renderLayer, isFirstPersonArm) {
    parent.render(entity, renderLayer, isFirstPersonArm);
    
    if (renderLayer == "CHESTPLATE") {
		if (!isFirstPersonArm) {
			holster.render();
			cape.render(entity);
			if (!entity.getData("fiskheroes:aiming")) {
				boomstick_back.render();
			}
		}
	}
}
