SANDBOX — this is a test environment. No servers are actually deployed and no real payments are charged.
Source-checkedLibraries & compatibility

RitnLib

by Ritn · for Factorio

Function library for Ritn Mod.

125KDownloads
46d agoLast updated
MITLicense
2.1Latest game version

About RitnLib

From Factorio Mod Portal

Function library for Ritn Mod.

RitnLib

> FR — Bibliothèque pour mods Factorio : raccourcis sur data.raw, wrappers sur les classes runtime (LuaPlayer, LuaForce, LuaEntity…), constructeur de GUI, builder de mod settings, snapshot d'inventaires. > > EN — Library for Factorio mods: shortcuts over data.raw, wrappers for the runtime classes (LuaPlayer, LuaForce, LuaEntity…), GUI builder, mod settings builder, inventory snapshot.


🇬🇧 English

RitnLib is a library mod for Factorio 2.0. It doesn't add anything to the game — it serves as a dependency for other mods, shortening the Factorio patterns that come up in every non-trivial mod: mutating data.raw, handling entities, dispatching events, building a GUI, declaring mod settings, snapshotting an inventory…

What it looks like

Without RitnLib, snapshot and restore on respawn:

script.on_event(defines.events.on_player_died, function(event)
    storage.snapshots = storage.snapshots or {}
    local player = game.get_player(event.player_index)
    if not storage.snapshots[player.name] then
        storage.snapshots[player.name] = {
            [defines.inventory.character_main]  = game.create_inventory(65535),
            [defines.inventory.character_guns]  = game.create_inventory(65535),
            [defines.inventory.character_ammo]  = game.create_inventory(65535),
            [defines.inventory.character_armor] = game.create_inventory(65535),
            [defines.inventory.character_trash] = game.create_inventory(65535),
        }
    end
    for define, snapshot in pairs(storage.snapshots[player.name]) do
        local inv = player.get_inventory(define)
        for i = 1, #inv do
            if inv[i].valid then snapshot[i].swap_stack(inv[i]) end
        end
    end
end)

script.on_event(defines.events.on_player_respawned, function(event)
    -- … mirror of the above, the other way around …
end)

With RitnLib:

script.on_event(defines.events.on_player_died, function(event)
    storage.snapshots = storage.snapshots or {}
    RitnLibInventory(game.get_player(event.player_index), storage.snapshots):save()
end)

script.on_event(defines.events.on_player_respawned, function(event)
    RitnLibInventory(game.get_player(event.player_index), storage.snapshots):load()
end)

That's the idea across the whole library: you state what you want to do, RitnLib handles the Factorio plumbing.

What's inside

Data stage — mutating data.raw

  • RitnProtoRecipe — disable, hide, modify ingredients, retint science packs.
  • RitnProtoTechnology — disable (with prerequisite purge), add/remove/replace science packs, manage lab.inputs, unlock/remove recipes.
  • RitnProtoEntity, RitnProtoItem, RitnProtoOre (with autoplace), RitnProtoSprite, RitnProtoStyle.
  • RitnProtoItemGroup, RitnProtoItemSubgroup, RitnProtoRecipeCategory, RitnProtoFuelCategory, RitnProtoCustomInput, RitnProtoUtilityConst.
  • Ready-to-require fonts ritn-default-{12..20} (normal + bold) and a set of GUI styles *-ritngui.
  • Helpers for data.raw['gui-style'].default and a local fork of the engine's util.lua.

Control stage — runtime

  • Wrappers: RitnLibPlayer, RitnLibSurface, RitnLibForce, RitnLibEntity, RitnLibRecipe, RitnLibTechnology.
  • RitnLibEvent(event) — normalizes any Factorio event and exposes event.player, event.surface, event.force, event.entity, event.recipe, event.technology, event.inventory, event.element, event.area, event.position… without having to remember each event's structure.
  • RitnLibInventory — snapshot/restore (main, guns, ammo, armor, trash, cursor) via game.create_inventory.
  • RitnLibGui + RitnLibGuiElement + RitnLibStyle — chained GUI construction, click dispatcher via remote.call("<your-mod>", "gui_action_<gui_name>", …).

Settings stage

  • RitnLibSetting — builder for data:extend({...}) (bool-setting, int-setting, double-setting, string-setting, color-setting; scope startup/runtime-global/runtime-per-user).

Integrations with other mods

  • Ready remote.calls for the freeplay scenario: set_created_items, set_respawn_items, set_skip_intro, set_disable_crashsite.
  • remote.call("silo_script", "set_no_victory", …).
  • Optional DiscoScience.setIngredientColor hook for custom science packs.
  • Automatic detection of gvv (global-state debugger) and zk-lib (optimized event_handler).

Status

Factorio 2.0 migration is in progress. A few methods still carry 1.x branches (recipe normal/expensive, force.items_launched, hr_version on sprites…). Code is being cleaned up version after version — see changelog.txt.

Installation

Subscribe via the in-game Mod Portal, or clone this repository into Factorio/mods/RitnLib/.

Then add "RitnLib" to your own mod's info.json dependencies:

{
  "name": "my-mod",
  "dependencies": [ "base", "RitnLib" ]
}

Documentation

Source / Issues


License

The Lua source code is © 2021-2026 Ritn. Embedded third-party content is licensed individually — notably rxi/json.lua (MIT).


🇫🇷 Français

Read the full description on Factorio Mod Portal →

Highlights

From source data

Game versions

Built for Factorio 2.1.

Footprint

Rated a light load on a server.

License

Published under MIT.

RitnLib on Nxeon

From our catalogue
One-click install
Supported on Nxeon Factorio servers. We download it from Factorio Mod Portal, place it, and restart the server.
Server side
Required on the server
Server load
light
Smallest plan we suggest
Factorio — 2 GB (2 GB RAM). This follows our own load rating above, not a benchmark.
Latest build
0.10.7, released 2026-10-06

Recent builds

BuildReleasedGame versionsLoaders
0.10.72026-10-062.1n/a
0.10.52026-10-012.1n/a
0.10.42026-09-122.1n/a

Run RitnLib on a Factorio server

Pick a server or deploy a new one above; it is installed in one click.

What kind of mod it is

From the catalog
Listed on Factorio Mod Portal as “Mods”

Libraries & compatibility

Foundations and fixes other mods build on. Usually installed because something else needs it.

Runs on your server

From source side support

Factorio Mod Portal lists RitnLib as required on the server. Check its Factorio Mod Portal page to see whether players need it too.

Compatibility

Game
Factorio
Runs on
Serverrequired on the server
Game versions
2.1

Verified at the source

  • ✓Factorio Mod PortalOfficial listing, checked 2026-10-09Open ↗
  • ✓AuthorRitn, as published on Factorio Mod Portal
  • ✓LicenseMITFree

RitnLib, answered

Generated from the mod’s own source data.

Do my players need to install RitnLib?

Factorio Mod Portal lists RitnLib as required on the server. Check its Factorio Mod Portal page to see whether players need it too.

Is it free?

Yes. RitnLib is free to download from Factorio Mod Portal. Its license is MIT.

How do I add it to my Nxeon server?

Use “Add to a server” on this page, or open NxLabs from your dashboard. We install it, restart your server and switch it on.

NxLabs

Run RitnLib on a Factorio server.

Deploy in about a minute from $2.99 a month, then add RitnLib in one click.