Skip to content

RitnProtoTech

Data-stage manipulator for data.raw["technology"][<name>]. A full toolkit for technologies: research cost, unlocked recipes, science packs (both in research and in labs), prerequisites, and disabling with cascade purge. Every setter writes back to data.raw (via :update()) and returns self (chainable).

The actual class name is RitnProtoTech (not RitnProtoTechnology).

Warning — Factorio 1.x API: this class hasn't been revised since Factorio 2.0; it keeps 1.x API constructs. Usable at data stage, but not validated for 2.0 — see Factorio 2.0 migration.

Source classes/prototypes/Technology.lua
Stage data
Access require(ritnlib.defines.class.prototype.tech) (alias …prototype.technology)
Inherits from RitnPrototype
object_name "RitnProtoTech"
-- my-mod/data.lua
require("__RitnLib__.defines")
local RitnProtoTech = require(ritnlib.defines.class.prototype.tech)

Constructor

RitnProtoTech(tech_name) → RitnProtoTech

Sets the basics via RitnPrototype.init then deep-copies data.raw["technology"][tech_name] into prototype. If the technology doesn't exist, prototype stays nil (setters become no-ops).

Parameters - tech_name :: string — technology name in data.raw.


Attributes

name :: string [Read]

Technology name (inherited from RitnPrototype).

type :: string [Read]

Resolved type ("technology").

prototype :: table? [Read]

Working copy of data.raw["technology"][name]. nil if the technology doesn't exist.

object_name :: "RitnProtoTech" [Read]

Type sentinel.

Note — The class also keeps internal mutable flags (addit, doit, disable_recipe, amount_pack, delete_prerequisite) that methods reset between calls. These are implementation details, not public fields.


Methods — research cost

These methods only apply to science pack technologies (unit). On a research trigger technology (Factorio 2.x), they do nothing.

:setCount(count) → RitnProtoTech

Sets the cycle count (prototype.unit.count).

:setTime(time) → RitnProtoTech

Sets the time per cycle (prototype.unit.time).

:setIngredients(ingredients) → RitnProtoTech

Replaces the whole research ingredient list (prototype.unit.ingredients).

Parameters: ingredients :: table[] — ingredient list ({ {"automation-science-pack", 1}, … }).

:multipliedPack(coeff) → RitnProtoTech

Multiplies prototype.unit.count by coeff.


Methods — unlock mode

In Factorio 2.x, a technology is unlocked either with science packs (unit) or with a research trigger (research_trigger: craft an item, mine an entity, etc.).

:getUnlockMode() → "unit"|"trigger"|nil

Returns "unit" (science packs), "trigger" (research trigger) or nil if the technology does not exist.

:isUnit() → boolean

true if the technology is unlocked with science packs.

:isTrigger() → boolean

true if the technology is unlocked with a research trigger.

:setUnit(unit) → RitnProtoTech

Replaces the whole research cost (prototype.unit) and removes research_trigger. Turns a trigger technology into a science pack technology.

Parameters: unit :: table — TechnologyUnit ({count = 100, ingredients = { {"automation-science-pack", 1} }, time = 30}).

:setTrigger(trigger) → RitnProtoTech

Replaces the research trigger (prototype.research_trigger) and removes unit. Turns a science pack technology into a trigger technology. No-op if trigger has no type.

Parameters: trigger :: table — TechnologyTrigger ({type = "craft-item", item = "iron-plate", count = 50}).

RitnProtoTech("oil-processing"):setUnit({
    count = 100,
    ingredients = { {"automation-science-pack", 1}, {"logistic-science-pack", 1} },
    time = 30
})
RitnProtoTech("my-tech"):setTrigger({type = "craft-item", item = "iron-plate", count = 50})

Methods — research trigger

These methods only apply to trigger technologies. On a science pack technology, they do nothing.

:getTrigger() → table?

Returns a copy of the research trigger, or nil if the technology has none.

:setTriggerTarget(target) → RitnProtoTech

Changes the trigger target according to its type:

Trigger type Field changed
craft-item, send-item-to-orbit item
craft-fluid fluid
build-entity, capture-spawner entity
mine-entity entities (a single name is turned into a list)

No-op for types without target (create-space-platform, scripted).

Parameters: target :: string|string[]

:setTriggerCount(count) → RitnProtoTech

Changes the required quantity: count (craft-item) or amount (craft-fluid). No-op for other types.

Parameters: count :: number

local tech = RitnProtoTech("steam-power")
if tech:isTrigger() then
    tech:setTriggerTarget("stone-brick"):setTriggerCount(20)
end

Methods — unlocked recipes

:addRecipe(recipe_name) → RitnProtoTech

Adds an {type = "unlock-recipe", recipe = recipe_name} effect (unless duplicate). The recipe must exist in data.raw.recipe.

:removeRecipe(recipe, complete?) → RitnProtoTech

Removes the matching unlock-recipe effect. If complete == true, also disables the recipe via RitnProtoRecipe(recipe):disable().


Methods — science packs (research)

Like the research cost methods, these do nothing on a trigger technology. A pack can be a tool or an item (Factorio 2.1: vanilla packs are item).

:addPack(pack, count?) → RitnProtoTech

Adds a pack to prototype.unit.ingredients (count defaults to 1). If the pack is already present, increments its amount by count. pack must exist in data.raw.tool or data.raw.item.

:removePack(pack) → RitnProtoTech

Removes every entry matching pack.

:replacePack(old, new) → RitnProtoTech

Replaces old with new, preserving the total amount. new must exist in data.raw.tool or data.raw.item.


Methods — packs on labs

:addPackLab(pack, index?) → RitnProtoTech

Adds pack to the inputs of every lab that doesn't already contain it (position index, default 1). pack must exist in data.raw.tool or data.raw.item.

:removePackLab(pack, lab?) → RitnProtoTech

Removes pack from every lab's inputs, or from a specific lab if provided.


Methods — prerequisites

:addPrerequisite(prerequisite) → RitnProtoTech

Adds prerequisite to prototype.prerequisites (unless duplicate). Must reference an existing technology.

:removePrerequisite(prerequisite) → RitnProtoTech

Removes prerequisite from the list.

:replacePrerequisite(remove_prerequisite, add_prerequisite) → RitnProtoTech

Shortcut: :removePrerequisite(...) then :addPrerequisite(...).


Methods — disabling

:disable(delete_prerequisites?) → RitnProtoTech

Disables and hides the technology. If delete_prerequisites == true, cascade-purges: removes this tech from the prerequisites list of every other tech that references it.

RitnProtoTech('steel-axe'):disable(true)

Methods inherited from RitnPrototype

:changePrototype, :setPrototype, :changeSubPrototype, :getProperties, :update, :changeSubgroup — see RitnPrototype.


Usage examples

Unlock a recipe + tune the time (RetroFactorio/prototypes/technologies.lua):

ProtoTech('light-armor'):addRecipe('light-armor')
ProtoTech('landfill'):setTime(25)

Disable a tech and purge the prerequisites pointing to it (RetroFactorio/prototypes/technologies.lua):

ProtoTech('steel-axe'):disable(true)
ProtoTech('logistic-science-pack'):disable(true)

Chaining on a mod technology (RitnHiladdar/prototypes/robots/update-technology.lua):

local rTech = RitnProtoTech("hsmd-logistic-robotics-2")
RitnProtoTech("hsmd-bot-recaller"):disable(true)

Remarks

  • Data stage only — use from data.lua / data-updates.lua / data-final-fixes.lua.
  • Copy + write-back — mutations apply to prototype, written back by :update() (called by every setter). No manual data:extend.
  • Existence required — addRecipe/addPack/replacePack/addPrerequisite check the target exists in data.raw (recipe, tool, technology) and are no-ops otherwise.

See also