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.

TypeBytesNotes
Bool1Either 0 for false, or 1 for true
Byte1Unsigned 0 .. 255
Int162Signed -32,768 .. 32,767
Int324Signed -2,147,483,648 .. 2,147,483,647
String*Pascal string. First byte contains the length of the string.
Single4Single-precision float
Double8Double-precision float
Rect164 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.

TypeVersionDescription
String0World Name
String179World Seed
Int64179Generator Version
Byte[16]181GUID
Int320World ID
Rect0World Bounds
Int320World Height in Tiles
Int320World Width in Tiles
Int32209Game Mode (0 = Normal, 1 = Expert, 2 = Master, 3 = Journey)
Bool222Drunk World (has both crimson and corruption)
Bool227"Get Good" World (for the worthy world gen)
Bool112Expert mode (field replaced with Game Mode)
Bool208Master mode (field replaced with Game Mode)
Int64141Creation Time
Byte63Moon Type
Int32[3]44Tree Type X Coordinates
Int32[4]44Tree Styles
Int32[3]60Cave Back X Coordinates
Int32[4]60Cave Back Styles
Int3260Ice Back Style
Int3261Jungle Back Style
Int3261Hell Back Style
Int320Spawn X
Int320Spawn Y
Double0World Surface Y
Double0Rock Layer Y
Double0Game Time
Bool0Day/Night (0 = night, 1 = day)
Int320Moon Phase
Bool0Blood Moon
Bool70Eclipse
Int320Dungeon X
Int320Dungeon Y
Bool56Crimson World
Bool0Killed Eye of Cthulu
Bool0Killed Eater of Worlds/Brain of Cthulhu
Bool0Killed Skeletron
Bool66Killed Queen Bee
Bool44Killed The Destroyer
Bool44Killed The Twins
Bool44Killed Skeletron Prime
Bool44Killed Any Hardmode Boss
Bool64Killed Plantera
Bool64Killed Golem
Bool118Killed Slime King
Bool29Saved Goblin Tinkerer
Bool29Saved Wizard
Bool34Saved Mechanic
Bool29Defeated Goblin Invasion
Bool32Killed Clown
Bool37Defeated Frost Legion
Bool56Defeated Pirates
Bool0Broke a Shadow Orb
Bool0Meteor Spawned
Byte0Shadow Orbs broken mod 3
Int3223Altars Smashed
Bool23Hard Mode
Int320Invasion Delay
Int320Invasion Size
Int320Invasion Type
Double0Invasion X
Double118Slime Rain Time
Byte113Sundial Cooldown
Bool53Is Raining
Int3253Rain Time
Single53Max Rain
Int3254Tier 1 Ore ID
Int3254Tier 2 Ore ID
Int3254Tier 3 Ore ID
Byte55Tree Style
Byte55Corruption Style
Byte55Jungle Style
Byte60Snow Style
Byte60Hallow Style
Byte60Crimson Style
Byte60Desert Style
Byte60Ocean Style
Int3260Cloud Background
Int1662Number of Clouds
Single62Wind Speed
Int3295Number of Players in Array
String[]95Players who did today's fishing quest
Bool99Saved Angler
Int32101Current Angler's Quest
Bool104Saved Stylist
Bool129Saved Tax Collector
Bool201Saved Golfer
Int32107Invasion Size Start
Int32108Cultist Delay
Int16109Kill Count Length
Int32[]109Kill Count
Bool128Time Fast Forwarding
Bool131Killed Duke Fishron
Bool131Defeated Martian Invasion
Bool131Killed Ancient Cultist
Bool131Killed Moonlord
Bool131Killed Pumpking
Bool131Killed Spooky Wood
Bool131Killed Ice Queen
Bool131Killed San-tank
Bool131Killed Christmas Tree
Bool140Solar Pillar down
Bool140Vortex Pillar down
Bool140Nebula Pillar down
Bool140Stardust Pillar down
Bool140Solar Pillar Barrier active
Bool140Vortex Pillar Barrier active
Bool140Nebula Pillar Barrier active
Bool140Stardust Pillar Barrier active
Bool140Lunar Apocalpyse
Bool170Manual Party Active
Bool170Genuine Party Active
Int32170Party Cooldown
Int32170Number of Partiers
Int32[]170Partying NPCs
Bool174Sandstorm active
Int32174Sandstorm Time Left
Single174Sandstorm Severity
Single174Sandstorm Max Severity
Bool178Saved Bartender
Bool178Finished DD2 Invasion 1
Bool178Finished DD2 Invasion 2
Bool178Finished DD2 Invasion 3
Byte195Style 8
Byte215Style 9
Byte196Style 10
Byte196Style 11
Byte196Style 12
Bool204Combat Book Used
Int32207Lantern Night Cooldown
Bool207Genuine Lantern Night
Bool207Manual Lanter Night
Bool207Next Lantern Night will be Genuine
Int32211Number of Tree Tops
Int32[]211Tree Tops
Bool212Forced Halloween
Bool212Forced Christmas
Int32216Copper Type ID
Int32216Iron Type ID
Int32216Silver Type ID
Int32216Gold Type ID
Bool217Bought Cat
Bool217Bought Dog
Bool217Bought Bunny
Bool223Killed Empress of Light
Bool223Killed 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.

TypeDescription
ByteActiveFlags
If ActiveFlags bit 0
TypeDescription
ByteTileFlags
If TileFlags bit 0
TypeDescription
ByteTileFlags High Byte
If ActiveFlags bit 1
TypeDescription
ByteTile Type
If ActiveFlags bit 5
TypeDescription
ByteTile Type High Byte
If Tile Type is Important:
TypeDescription
Int16Texture U
Int16Texture V
If TileFlags bit 11
TypeDescription
ByteTile Color
If ActiveFlags bit 2
TypeDescription
ByteWall Type
If TileFlags bit 12
TypeDescription
ByteWall Color
ActiveFlags bits 3-4 non-zero
TypeDescription
ByteLiquid Amount
TileFlags2 bit 6:
TypeDescription
ByteHigh Byte of Wall ID
ActiveFlags bits 6-7 = 1
TypeDescription
ByteRLE Length
ActiveFlags bits 6-7 = 2
TypeDescription
Int16RLE Length
Active Flag BitDescription
0Tile Flags present
1Tile present
2Wall present
3 - 4Liquid Type (1 = Water, 2 = Lava, 3 = Honey)
5Unused
6 - 7RLE Field Length
Tile Flag BitDescription
0Tile Flags is an Int16
1Red Wire Present
2Blue Wire Present
3Green Wire Present
4 - 6Tile Slope (1 = half block)
7 - 8Unused
9Actuator present
10TIle actuated
11Tile is painted
12Wall is painted
13Yellow Wire Present
14Wall 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.

TypeVersionDescription
Int1688Number of Chests
Int1688Number of slots in every chest
For each chest:
TypeVersionDescription
Int3288Chest X
Int3288Chest Y
String88Chest Name
For each item:
TypeVersionDescription
Int1688Stack Size
If Stack Size not 0:
TypeVersionDescription
Int3288Item ID
Byte88Item Prefix

Signs

Section 4 is a list of all the signs in the world.

TypeVersionDescription
Int1688Number of Signs
For each Sign:
TypeVersionDescription
String88Sign Text
Int3288Sign X
Int3288Sign 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.

TypeVersionDescription
Bool88NPC Active
Int32190NPC Sprite ID
String88NPC Sprite Name (version < 190)
String0NPC Name
Single0NPC X
Single0NPC Y
Bool0Is Homeless
Int320NPC Home X
Int320NPC Home Y
Bool213Town Variation Present
Int32213Town Variation (if previous bool set)

If version is at least 140, there's a second list, stored in the same fashion, of homeless NPCs.

TypeVersionDescription
Bool88NPC Active
Int32190NPC Sprite ID
String88NPC Sprite Name (version < 190)
Single0NPC X
Single0NPC Y

Entities

Section 6 contains a list of Entities if the version is at least 122.

TypeVersionDescription
Int32122Number of Entities
For each entity:
TypeVersionDescription
Byte122Entity Type
Entity122Entity Data (see below)

Each entity has a different data layout:

For Entity Type 0: Training Dummy

TypeVersionDescription
Int32122ID
Int16122X
Int16122Y
Int16122NPC

For Entity Type 1: Item Frame

TypeVersionDescription
Int32122ID
Int16122X
Int16122Y
Int16122Item ID
Byte122Item Prefix
Int16122Item Stack

For Entity Type 2: Logic Sensor

TypeVersionDescription
Int32122ID
Int16122X
Int16122Y
Byte122Sensor Type
Bool122Sensor On

Pressure Plates

Section 7 (if version is at least 170) contains the list of weighted pressure plates in the world.

TypeVersionDescription
Int32170Number of Pressure Plates
For each plate:
TypeVersionDescription
Int32170X
Int32170Y

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.

TypeVersionDescription
Int32189Number of Rooms
For each room:
TypeVersionDescription
Int32189NPC
Int32189X
Int32189Y

Bestiary

Section 9 (if version is at least 210) contains the bestiary.

TypeVersionDescription
Int32210Number of Kills
For each kill:
TypeVersionDescription
String210NPC
Int32210Number of times killed
Int32210Number of Seen
For each seen:
TypeVersionDescription
String210NPC
Int32210Number of Chatted with
For each chatted with:
TypeVersionDescription
String210NPC

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.