setGlobal();

function bindBeam(renderer, propertyName, beamType, anchor, color, beams) {
    var prop = renderer.bindProperty(propertyName).setAnchor(anchor);
    var constln = renderer.createResource("BEAM_CONSTELLATION", null);

    for (var i = 0; i < beams.length; ++i) {
        constln.bindBeam(beams[i]);
    }

    prop.setConstellation(constln);
    prop.setRenderer(renderer.createResource("BEAM_RENDERER", beamType));
    prop.color.set(color);
    return prop;
}

function bindParticles(renderer, particleType) {
    return renderer.bindProperty("fiskheroes:particles").setParticles(renderer.createResource("PARTICLE_EMITTER", particleType));
}

function bindCloud(renderer, propertyName, cloudType) {
    return renderer.bindProperty(propertyName).setCloud(renderer.createResource("PARTICLE_CLOUD", cloudType));
}

function bindTrail(renderer, trailType) {
    var prop = renderer.bindProperty("fiskheroes:trail");
    prop.setTrail(renderer.createResource("TRAIL", trailType));
    prop.setCondition(entity => entity.getData("fiskheroes:speeding"));
    return prop;
}

function setOpacity(renderer, min, max, delta) {
    renderer.bindProperty("fiskheroes:opacity").setOpacity((entity, renderLayer) => {
        return max + (min - max) * delta;
    });
}

function setOpacityWithData(renderer, min, max, data) {
    renderer.bindProperty("fiskheroes:opacity").setOpacity((entity, renderLayer) => {
        return max + (min - max) * entity.getInterpolatedData(data);
    });
}

function isJetpacking(entity) {
    return entity.getData("fiskheroes:jetpacking") || entity.getData("fiskheroes:hovering");
}