Worldgen Main
Based on game build 714014 | Last updated: 2026-03-10
Overview
worldgen_main.lua is the main entry point for the world generation process in Don't Starve Together. It handles initialization of the Lua module loader (including custom NACL-compatible loaders), platform detection, seed management, and orchestration of the world generation pipeline via GenerateNew. It also integrates mod support, loads required map/task/room systems, and outputs structured world data ready for serialization.
Usage example
This module is not used directly by modders as a component. Instead, it is invoked internally during world generation via LoadParametersAndGenerate, which expects GEN_PARAMETERS to be a JSON-encoded string containing world generation parameters.
However, a modder may override aspects of world generation by patching functions defined here (e.g., SetWorldGenSeed), or by interacting with modules it loads (e.g., map/levels, map/tasks, prefabswaps).
Dependencies & tags
Components used: None — this is a top-level script, not an entity component.
Tags: None identified.
Properties
No public properties are defined or exposed by this script.
Main functions
SetWorldGenSeed(seed)
- Description: Sets the global random seed for world generation. If
seedisnil, it derives a deterministic seed from the current system time (last 6 digits of reversedos.time()). It reseeds Lua’smath.randomand discards one value to avoid bias. - Parameters:
seed(number?) — Optional; ifnil, auto-generated. - Returns: number — The effective seed used.
- Error states: None.
GenerateNew(debug, world_gen_data)
- Description: Executes the core world generation pipeline: loads level configuration, selects tasks and set pieces, runs
forest_map.Generate, and structures the resulting world data for serialization. - Parameters:
debug(boolean) — Iftrue, forces generation of a debug map with all tasks (tasks.oneofeverything).
world_gen_data(table) — Required; contains keyslevel_type,level_data, and optionallyshow_debugandDLCEnabled. - Returns: table — A nested table of serialized world data (keys:
map,ents,mods,meta), with each value stringified viaDataDumper. - Error states: Returns
nilif world generation fails after 5 retries. Throwsasserterrors for missing level data or invalid structures.
LoadParametersAndGenerate(debug)
- Description: Parses
GEN_PARAMETERS(a JSON string), decodes it intoworld_gen_data, enables DLCs accordingly, and callsGenerateNew. - Parameters:
debug(boolean) — Passed toGenerateNew. - Returns: table — Same as
GenerateNew. - Error states: Throws if
GEN_PARAMETERSisnil.
Platform & Utility Helpers
IsConsole(),IsPS4(),IsPS5(),IsXB1(),IsSteam(),IsLinux(),IsRail(),IsSteamDeck()— Returntrue/falsebased onPLATFORMorIS_STEAM_DECKconstants.LoadScript(filename),RunScript(filename)— Caching script loaders usingkleiloadluaand the patchedloadfile.GetTickTime(),GetTime(),GetStaticTime(),GetTick(),GetStaticTick()— Return0; placeholders for runtime-only timing functions (not used in worldgen).GetTimeReal()— Callsgetrealtime()to retrieve real-world time.ValidateLineNumber(num)— No-op; present for compatibility.PROFILE_world_gen(debug)— Wraps world generation with a profiler and writesprofile.txt.
Events & listeners
This file does not define or interact with entity events; it is a procedural script, not an entity component.
- Listens to: None
- Pushes: None