loadTextures({
    "base": "skarlet:cyclops_cannon",
    "lights": "skarlet:cyclops_cannon_lights.tx.json",
    "lights_item": "skarlet:cyclops_cannon_lights_0",
    "crosshair": "skarlet:crosshairs/cyclops_cannon"
});

var utils = implement("fisktag:external/utils");
var railgun_charge = implement("fisktag:external/railgun_charge");

var model;

function init(renderer) {
    model = utils.createModel(renderer, "skarlet:cyclops_cannon", "base", "lights");
    renderer.setModel(model);

    utils.makeDilatingCrosshair(renderer, "crosshair", 57, 7, [
        { "pos": [28, 3], "size": [1, 1] }, // Center
        { "pos": [24, 3], "size": [3, 1], "axis": [-1, 0] }, // Left
        { "pos": [30, 3], "size": [3, 1], "axis": [1, 0] }, // Right
        { "pos": [0, 0], "size": [57, 2], "axis": [0, -1] }, // Top
        { "pos": [0, 5], "size": [57, 2], "axis": [0, 1] } // Bottom
    ], 0, 3, 2);

    utils.bindScopedBeam(renderer, "skarlet:cyclops_beam", 0xFF3200, [
        { "firstPerson": [-4.5, 3.8, -18.0], "offset": [-4.0, 21.0, -17.8], "size": [6, 0.5] }
    ], [3.5, -0.5, -5.0]);
}

function render(renderer, entity, glProxy, renderType, scopeTimer, recoil, isLeftSide) {
    if (renderType === "EQUIPPED_FIRST_PERSON") {
        model.texture.set("base", "lights");
        var f = easeInOutSine(entity.getInterpolatedData("fiskheroes:scope_timer"));
        glProxy.rotate(-7 * f, 1, 0, 0);
        glProxy.translate(-0.1 * f, -0.1 * f, -0.2 * f + recoil * (0.7 - 0.2 * scopeTimer));
    }
    else if (renderType === "ENTITY" || renderType === "INVENTORY") {
        model.texture.set("base", "lights_item");
        glProxy.translate(0, -0.1, 0.2);
    }
    else {
        model.texture.set("base", "lights");
    }

    glProxy.translate(0, -0.75, -0.55);
    glProxy.scale(1.25);
}

function easeInOutSine(x) {
    return -(Math.cos(Math.PI * x) - 1) / 2;
}
