var LOADTEXTURES = {
    "null": "tmf:null",
    "fourarms": "tmf:omnitrix/p1/aliens/fourarms",
    "fourarms_lights": "tmf:omnitrix/p1/lights/fourarms_lights.tx.json",
    "fourarms_spin": "tmf:omnitrix/p1/aliens/fourarms_spin"
};

var IMPLEMENTS = {
    utils: "fiskheroes:external/utils"
};

function init(renderer, getAlien, isCurrent) {

    utils.bindParticles(renderer, "tmf:alien_particles_p1").setCondition(entity => isCurrent(entity));
    
    var model_Fourarms = renderer.createResource("MODEL", "tmf:omnitrix/aliens/fourarms");
    model_Fourarms.bindAnimation("tmf:omnitrix/aliens/fourarms").setData((entity, data) => {
        data.load(0, entity.getInterpolatedData('tmf:dyn/pt_2'));
        data.load(1, entity.getInterpolatedData('tmf:dyn/pc_2'));
        data.load(2, entity.getInterpolatedData('tmf:dyn/pt_3'));
        data.load(3, entity.getInterpolatedData('tmf:dyn/pc_3'));
        data.load(4, entity.isSneaking() ? 1-entity.getInterpolatedData('fiskheroes:heat_vision_timer') : 0);
        data.load(5, entity.loop(84));
        data.load(6, entity.getData('fiskheroes:beam_charging') && entity.getData('fiskheroes:beam_shooting_timer') == 0 ? entity.getInterpolatedData('fiskheroes:beam_charge') : 0);
        data.load(7, entity.getInterpolatedData('fiskheroes:beam_shooting_timer'));
        data.load(8, entity.getInterpolatedData('fiskheroes:heat_vision_timer'));
    });
    model_Fourarms.texture.set("fourarms", "fourarms_lights");
    fourarms = renderer.createEffect("fiskheroes:model").setModel(model_Fourarms);
    fourarms.anchor.ignoreAnchor(true);

    var model_FourarmsFP = renderer.createResource("MODEL", "tmf:omnitrix/aliens/fourarms_fp");
    model_FourarmsFP.bindAnimation("tmf:omnitrix/aliens/fourarms2").setData((entity, data) => {
        data.load(0, entity.getInterpolatedData('tmf:dyn/pt_2'));
        data.load(1, entity.getInterpolatedData('tmf:dyn/pc_2'));
        data.load(2, entity.getInterpolatedData('tmf:dyn/pt_3'));
        data.load(3, entity.getInterpolatedData('tmf:dyn/pc_3'));
        data.load(4, entity.isSneaking() ? 1 : 0);
        data.load(5, entity.loop(84));
        data.load(6, entity.getData('fiskheroes:beam_charging') && entity.getData('fiskheroes:beam_shooting_timer') == 0 ? entity.getInterpolatedData('fiskheroes:beam_charge') : 0);
        data.load(7, entity.getInterpolatedData('fiskheroes:beam_shooting_timer'));
    });
    model_FourarmsFP.texture.set("fourarms", "fourarms_lights");
    fourarmsFp = renderer.createEffect("fiskheroes:model").setModel(model_FourarmsFP);
    fourarmsFp.setRotation(-25, 0, 0);
    fourarmsFp.setOffset(0, 6, 7);
    fourarmsFp.setScale(0.75);
    fourarmsFp.anchor.ignoreAnchor(true);

    var model_FASpin = renderer.createResource("MODEL", "tmf:omnitrix/powers/fourarms_spin");
    model_FASpin.bindAnimation("tmf:omnitrix/powers/fourarms_spin").setData((entity, data) => {
        data.load(1, entity.getData('fiskheroes:heat_vision') ? entity.loop(20) * entity.getInterpolatedData('fiskheroes:heat_vision_timer') : 0);
    });
    model_FASpin.texture.set("fourarms_spin");
    fourarmsSpin = renderer.createEffect("fiskheroes:model").setModel(model_FASpin);
    fourarmsSpin.anchor.ignoreAnchor(true);

    utils.bindBeam(renderer, "fiskheroes:charged_beam", "tmf:thunder_clap", "body", 0xCACBCB, [
        { "firstPerson": [0, 0, -20.0], "offset": [0.0, 0.0, -20.0], "size": [10.0, 10.0, 10.0] }
    ]).setCondition(entity => isCurrent(entity));

    utils.bindBeam(renderer, "fiskheroes:heat_vision", "tmf:thunder_clap", "body", 0xCACBCB, [
    ]).setCondition(entity => isCurrent(entity));

    addAnimation(renderer, "fourarms.ARM", "tmf:omnitrix/powers/remove_arm").setData((entity, data) => {
        data.load(0, 1);
        }).setCondition(entity => isCurrent(entity));
    addAnimation(renderer, "fourarms.SPIN", "tmf:omnitrix/powers/spin").setData((entity, data) => {
        data.load(9, entity.getData('fiskheroes:heat_vision') ? entity.loop(8) * entity.getInterpolatedData('fiskheroes:heat_vision_timer') : 0);
        }).setCondition(entity => isCurrent(entity));

    var shakeFourArms1 = renderer.bindProperty("fiskheroes:camera_shake").setCondition(entity => {
        shakeFourArms1.factor = 0.15 * entity.getInterpolatedData("fiskheroes:heat_vision_timer");
        return isCurrent(entity);
        });

    var shakeFourArms2 = renderer.bindProperty("fiskheroes:camera_shake").setCondition(entity => {
        shakeFourArms2.factor = 0.3 * entity.getInterpolatedData("fiskheroes:beam_shooting_timer");
        return isCurrent(entity);
        });

    return {
        getTexture: entity => "null",
        getLights: entity => "null",
        render: (entity, isFirstPersonArm) => {
            if (isFirstPersonArm) {
                fourarmsFp.render();
            }
            if (!isFirstPersonArm) {
                fourarms.render();
            }
            if (entity.getData('fiskheroes:heat_vision')) {
                fourarmsSpin.opacity = 0.6*entity.getInterpolatedData('fiskheroes:heat_vision_timer');
                fourarmsSpin.render();
            }
        }
    };
}

