Overall
The world format has become a little more complicated over the years.
It is now broken into chunks.
Type Formats
The types used in the world file are below, all are stored little-endian.
Type | Bytes | Notes |
Bool | 1 | Either 0 for false, or 1 for true |
Byte | 1 | Unsigned 0 .. 255 |
Int16 | 2 | Signed -32,768 .. 32,767 |
Int32 | 4 | Signed -2,147,483,648 .. 2,147,483,647 |
String | * | Pascal string. First byte contains the length of the string. |
Single | 4 | Single-precision float |
Double | 8 | Double-precision float |
Rect | 16 | 4 Int32s that form a rectangle (left, right, top, bottom) |
Framework
The world file has an overall section structure. The very first Int32 in the file is the map version. This will be used to determine which fields and
sections to load and which to skip.
If the version is at least 135, a 7-byte "relogic" string follows the
version number. This helps identify the world file. Following that is
a 1-byte filetype. World files have type 2. Finally there are 12 bytes of
revision and favorite data that you can ignore.
If the version is at least 88, the next thing the file is the number of
sections as an Int16. This is followed by a list of Int32s (one for each
section) which are offsets from the beginning of the file to each section.
Finally, there is an Int16 which represents the number of tiles in the
tile mask, and that many bits (rounded up to the nearest byte) following
which represent whether or not that tile has UV coordinates or not.
Header
The first section in the file is the Header. The header contains general
information about the world, including what state the world is in, what
bosses have been killed, etc.
Some fields are only present in certain versions of the map. I've
included the minimum map version for each field. If the current version
is less than that, you should act as if that field doesn't exist.
Type | Version | Description |
String | 0 | World Name |
String | 179 | World Seed |
Int64 | 179 | Generator Version |
Byte[16] | 181 | GUID |
Int32 | 0 | World ID |
Rect | 0 | World Bounds |
Int32 | 0 | World Height in Tiles |
Int32 | 0 | World Width in Tiles |
Int32 | 209 | Game Mode (0 = Normal, 1 = Expert, 2 = Master, 3 = Journey) |
Bool | 222 | Drunk World (has both crimson and corruption) |
Bool | 227 | "Get Good" World (for the worthy world gen) |
Bool | 112 | Expert mode (field replaced with Game Mode) |
Bool | 208 | Master mode (field replaced with Game Mode) |
Int64 | 141 | Creation Time |
Byte | 63 | Moon Type |
Int32[3] | 44 | Tree Type X Coordinates |
Int32[4] | 44 | Tree Styles |
Int32[3] | 60 | Cave Back X Coordinates |
Int32[4] | 60 | Cave Back Styles |
Int32 | 60 | Ice Back Style |
Int32 | 61 | Jungle Back Style |
Int32 | 61 | Hell Back Style |
Int32 | 0 | Spawn X |
Int32 | 0 | Spawn Y |
Double | 0 | World Surface Y |
Double | 0 | Rock Layer Y |
Double | 0 | Game Time |
Bool | 0 | Day/Night (0 = night, 1 = day) |
Int32 | 0 | Moon Phase |
Bool | 0 | Blood Moon |
Bool | 70 | Eclipse |
Int32 | 0 | Dungeon X |
Int32 | 0 | Dungeon Y |
Bool | 56 | Crimson World |
Bool | 0 | Killed Eye of Cthulu |
Bool | 0 | Killed Eater of Worlds/Brain of Cthulhu |
Bool | 0 | Killed Skeletron |
Bool | 66 | Killed Queen Bee |
Bool | 44 | Killed The Destroyer |
Bool | 44 | Killed The Twins |
Bool | 44 | Killed Skeletron Prime |
Bool | 44 | Killed Any Hardmode Boss |
Bool | 64 | Killed Plantera |
Bool | 64 | Killed Golem |
Bool | 118 | Killed Slime King |
Bool | 29 | Saved Goblin Tinkerer |
Bool | 29 | Saved Wizard |
Bool | 34 | Saved Mechanic |
Bool | 29 | Defeated Goblin Invasion |
Bool | 32 | Killed Clown |
Bool | 37 | Defeated Frost Legion |
Bool | 56 | Defeated Pirates |
Bool | 0 | Broke a Shadow Orb |
Bool | 0 | Meteor Spawned |
Byte | 0 | Shadow Orbs broken mod 3 |
Int32 | 23 | Altars Smashed |
Bool | 23 | Hard Mode |
Int32 | 0 | Invasion Delay |
Int32 | 0 | Invasion Size |
Int32 | 0 | Invasion Type |
Double | 0 | Invasion X |
Double | 118 | Slime Rain Time |
Byte | 113 | Sundial Cooldown |
Bool | 53 | Is Raining |
Int32 | 53 | Rain Time |
Single | 53 | Max Rain |
Int32 | 54 | Tier 1 Ore ID |
Int32 | 54 | Tier 2 Ore ID |
Int32 | 54 | Tier 3 Ore ID |
Byte | 55 | Tree Style |
Byte | 55 | Corruption Style |
Byte | 55 | Jungle Style |
Byte | 60 | Snow Style |
Byte | 60 | Hallow Style |
Byte | 60 | Crimson Style |
Byte | 60 | Desert Style |
Byte | 60 | Ocean Style |
Int32 | 60 | Cloud Background |
Int16 | 62 | Number of Clouds |
Single | 62 | Wind Speed |
Int32 | 95 | Number of Players in Array |
String[] | 95 | Players who did today's fishing quest |
Bool | 99 | Saved Angler |
Int32 | 101 | Current Angler's Quest |
Bool | 104 | Saved Stylist |
Bool | 129 | Saved Tax Collector |
Bool | 201 | Saved Golfer |
Int32 | 107 | Invasion Size Start |
Int32 | 108 | Cultist Delay |
Int16 | 109 | Kill Count Length |
Int32[] | 109 | Kill Count |
Bool | 128 | Time Fast Forwarding |
Bool | 131 | Killed Duke Fishron |
Bool | 131 | Defeated Martian Invasion |
Bool | 131 | Killed Ancient Cultist |
Bool | 131 | Killed Moonlord |
Bool | 131 | Killed Pumpking |
Bool | 131 | Killed Spooky Wood |
Bool | 131 | Killed Ice Queen |
Bool | 131 | Killed San-tank |
Bool | 131 | Killed Christmas Tree |
Bool | 140 | Solar Pillar down |
Bool | 140 | Vortex Pillar down |
Bool | 140 | Nebula Pillar down |
Bool | 140 | Stardust Pillar down |
Bool | 140 | Solar Pillar Barrier active |
Bool | 140 | Vortex Pillar Barrier active |
Bool | 140 | Nebula Pillar Barrier active |
Bool | 140 | Stardust Pillar Barrier active |
Bool | 140 | Lunar Apocalpyse |
Bool | 170 | Manual Party Active |
Bool | 170 | Genuine Party Active |
Int32 | 170 | Party Cooldown |
Int32 | 170 | Number of Partiers |
Int32[] | 170 | Partying NPCs |
Bool | 174 | Sandstorm active |
Int32 | 174 | Sandstorm Time Left |
Single | 174 | Sandstorm Severity |
Single | 174 | Sandstorm Max Severity |
Bool | 178 | Saved Bartender |
Bool | 178 | Finished DD2 Invasion 1 |
Bool | 178 | Finished DD2 Invasion 2 |
Bool | 178 | Finished DD2 Invasion 3 |
Byte | 195 | Style 8 |
Byte | 215 | Style 9 |
Byte | 196 | Style 10 |
Byte | 196 | Style 11 |
Byte | 196 | Style 12 |
Bool | 204 | Combat Book Used |
Int32 | 207 | Lantern Night Cooldown |
Bool | 207 | Genuine Lantern Night |
Bool | 207 | Manual Lanter Night |
Bool | 207 | Next Lantern Night will be Genuine |
Int32 | 211 | Number of Tree Tops |
Int32[] | 211 | Tree Tops |
Bool | 212 | Forced Halloween |
Bool | 212 | Forced Christmas |
Int32 | 216 | Copper Type ID |
Int32 | 216 | Iron Type ID |
Int32 | 216 | Silver Type ID |
Int32 | 216 | Gold Type ID |
Bool | 217 | Bought Cat |
Bool | 217 | Bought Dog |
Bool | 217 | Bought Bunny |
Bool | 223 | Killed Empress of Light |
Bool | 223 | Killed Queen Slime |
Tile Data
The second section is the Tile Data. The tile data is
a little more complicated. Some fields are only present if previous
booleans are true.
The tiles are stored column-first. So the first tile is at 0,0, the
second tile is at 1,0. Also, in later versions, there is RLE compression,
which runs vertically for the current column only.
Finally, some tile types are marked "Important", and contain texture
coordinates, other tiles have their texture coordinates calculated at
runtime. This is determined by the bit mask read after the section offsets.
Type | Description |
Byte | ActiveFlags |
| If ActiveFlags bit 0
Type | Description |
Byte | TileFlags |
| If TileFlags bit 0
Type | Description |
Byte | TileFlags High Byte |
|
|
| If ActiveFlags bit 1
Type | Description |
Byte | Tile Type |
| If ActiveFlags bit 5
Type | Description |
Byte | Tile Type High Byte |
|
| If Tile Type is Important:
Type | Description |
Int16 | Texture U |
Int16 | Texture V |
|
| If TileFlags bit 11
Type | Description |
Byte | Tile Color |
|
|
| If ActiveFlags bit 2
Type | Description |
Byte | Wall Type |
| If TileFlags bit 12
Type | Description |
Byte | Wall Color |
|
|
| ActiveFlags bits 3-4 non-zero
Type | Description |
Byte | Liquid Amount |
|
| TileFlags2 bit 6:
Type | Description |
Byte | High Byte of Wall ID |
|
| ActiveFlags bits 6-7 = 1
Type | Description |
Byte | RLE Length |
|
| ActiveFlags bits 6-7 = 2
Type | Description |
Int16 | RLE Length |
|
Active Flag Bit | Description |
0 | Tile Flags present |
1 | Tile present |
2 | Wall present |
3 - 4 | Liquid Type (1 = Water, 2 = Lava, 3 = Honey) |
5 | Unused |
6 - 7 | RLE Field Length |
Tile Flag Bit | Description |
0 | Tile Flags is an Int16 |
1 | Red Wire Present |
2 | Blue Wire Present |
3 | Green Wire Present |
4 - 6 | Tile Slope (1 = half block) |
7 - 8 | Unused |
9 | Actuator present |
10 | TIle actuated |
11 | Tile is painted |
12 | Wall is painted |
13 | Yellow Wire Present |
14 | Wall ID has high byte |
If RLE is present and greater than 0, you should copy the current tile
and all of its information RLE times down. RLE will never be greater than
the number of tiles you have left in the current column.
Chests
Section 3 contains all the chests in the world along with their contents.
Type | Version | Description |
Int16 | 88 | Number of Chests |
Int16 | 88 | Number of slots in every chest |
| | For each chest:
Type | Version | Description |
Int32 | 88 | Chest X |
Int32 | 88 | Chest Y |
String | 88 | Chest Name |
| | For each item:
Type | Version | Description |
Int16 | 88 | Stack Size |
| | If Stack Size not 0:
Type | Version | Description |
Int32 | 88 | Item ID |
Byte | 88 | Item Prefix |
|
|
|
Signs
Section 4 is a list of all the signs in the world.
Type | Version | Description |
Int16 | 88 | Number of Signs |
| | For each Sign:
Type | Version | Description |
String | 88 | Sign Text |
Int32 | 88 | Sign X |
Int32 | 88 | Sign Y |
|
NPCs
Section 5 is a list of all the NPCs in the world. The way NPCs are stored
is each NPC is prefixed with a boolean, keep reading NPCs until that
boolean is false.
Type | Version | Description |
Bool | 88 | NPC Active |
Int32 | 190 | NPC Sprite ID |
String | 88 | NPC Sprite Name (version < 190) |
String | 0 | NPC Name |
Single | 0 | NPC X |
Single | 0 | NPC Y |
Bool | 0 | Is Homeless |
Int32 | 0 | NPC Home X |
Int32 | 0 | NPC Home Y |
Bool | 213 | Town Variation Present |
Int32 | 213 | Town Variation (if previous bool set) |
If version is at least 140, there's a second list, stored in the same
fashion, of homeless NPCs.
Type | Version | Description |
Bool | 88 | NPC Active |
Int32 | 190 | NPC Sprite ID |
String | 88 | NPC Sprite Name (version < 190) |
Single | 0 | NPC X |
Single | 0 | NPC Y |
Entities
Section 6 contains a list of Entities if the version is at least 122.
Type | Version | Description |
Int32 | 122 | Number of Entities |
| | For each entity:
Type | Version | Description |
Byte | 122 | Entity Type |
Entity | 122 | Entity Data (see below) |
|
Each entity has a different data layout:
For Entity Type 0: Training Dummy
Type | Version | Description |
Int32 | 122 | ID |
Int16 | 122 | X |
Int16 | 122 | Y |
Int16 | 122 | NPC |
For Entity Type 1: Item Frame
Type | Version | Description |
Int32 | 122 | ID |
Int16 | 122 | X |
Int16 | 122 | Y |
Int16 | 122 | Item ID |
Byte | 122 | Item Prefix |
Int16 | 122 | Item Stack |
For Entity Type 2: Logic Sensor
Type | Version | Description |
Int32 | 122 | ID |
Int16 | 122 | X |
Int16 | 122 | Y |
Byte | 122 | Sensor Type |
Bool | 122 | Sensor On |
Pressure Plates
Section 7 (if version is at least 170) contains the list of weighted
pressure plates in the world.
Type | Version | Description |
Int32 | 170 | Number of Pressure Plates |
| | For each plate:
Type | Version | Description |
Int32 | 170 | X |
Int32 | 170 | Y |
|
Town Manager
Section 8 (if version is at least 189) contains the town manager. This
contains the homes of each NPC, even if the NPC is currently dead.
Type | Version | Description |
Int32 | 189 | Number of Rooms |
| | For each room:
Type | Version | Description |
Int32 | 189 | NPC |
Int32 | 189 | X |
Int32 | 189 | Y |
|
Bestiary
Section 9 (if version is at least 210) contains the bestiary.
Type | Version | Description |
Int32 | 210 | Number of Kills |
| | For each kill:
Type | Version | Description |
String | 210 | NPC |
Int32 | 210 | Number of times killed |
|
Int32 | 210 | Number of Seen |
| | For each seen:
Type | Version | Description |
String | 210 | NPC |
|
Int32 | 210 | Number of Chatted with |
| | For each chatted with:
Type | Version | Description |
String | 210 | NPC |
|
Creative Powers
Section 10 (if version at least 220), contains the list of creative powers
active. This is the stuff found in the journey mode menu. Is time stopped, is
biome spreading disabled, etc.
I haven't bothered figuring this format out.