world

package
v0.0.0-...-f16ec75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2016 License: MIT Imports: 17 Imported by: 0

README

World notes

Level files

The only file really required for a directory to be a Minecraft level!

Example
TAG_Compound(u''): 1 entries
{
  TAG_Compound(u'Data'): 23 entries
  {
    TAG_Byte(u'raining'): 0
    TAG_Int(u'generatorVersion'): 1
    TAG_Long(u'Time'): 4950
    TAG_Int(u'GameType'): 0
    TAG_String(u'generatorOptions'): u''
    TAG_Byte(u'MapFeatures'): 1
    TAG_String(u'generatorName'): u'default'
    TAG_Byte(u'initialized'): 1
    TAG_Byte(u'hardcore'): 0
    TAG_Long(u'RandomSeed'): 2603059821051629081
    TAG_Long(u'SizeOnDisk'): 0
    TAG_Byte(u'allowCommands'): 0
    TAG_Int(u'SpawnZ'): 220
    TAG_Long(u'LastPlayed'): 1406080954413
    TAG_Long(u'DayTime'): 4950
    TAG_Compound(u'GameRules'): 9 entries
    {
      TAG_String(u'doTileDrops'): u'true'
      TAG_String(u'doMobSpawning'): u'true'
      TAG_String(u'keepInventory'): u'false'
      TAG_String(u'naturalRegeneration'): u'true'
      TAG_String(u'doDaylightCycle'): u'true'
      TAG_String(u'doMobLoot'): u'true'
      TAG_String(u'mobGriefing'): u'true'
      TAG_String(u'doFireTick'): u'true'
      TAG_String(u'commandBlockOutput'): u'true'
    }
    TAG_Int(u'SpawnY'): 64
    TAG_Int(u'SpawnX'): -208
    TAG_Int(u'thunderTime'): 98924
    TAG_Int(u'version'): 19133
    TAG_Int(u'rainTime'): 17092
    TAG_Byte(u'thundering'): 0
    TAG_String(u'LevelName'): u'ExampleWorld'
  }
}

Region files

Coordinates

Region files have names like "region/r.x.z.mcr" where x and z are "region coordinates". These coordinates can be found this way:

regionX := chunkX >> 5
regionZ := chunkZ >> 5
Format

Region files begin with 8kiB header with what chunks are present, when last updated, and where found.

Location in file of chunk at chunk coordinates (x, z) can be found at:

xmod := Mod(x, 32)
if xmod < 0 {
  xmod = xmod + 32
}
zmod := Mod(z, 32)
if zmod < 0 {
  zmod = zmod + 32
}
offset := 4 * (xmod + zmod * 32)

Timestamp of chunk is 4096 bytes later in file.

bytes description
0-4095 locations (1024 entries)
4096-8191 timestamps (1024 entries)
8192+ chunks and unused space?

Chunks

Location
byte description
0-2 offset (big-endian, in 4KiB sectors)
3 count (number of 4KiB sectors)

Note: a chunk with an offset of 2 will begin right after timestamps table!

Timestamps
byte description
0-3 timestamp (four-byte big-endian integer)
Data
byte description
0-3 length (in bytes)
4 compression type (1=gzip, 2=zlib)
5 compressed data (length-1 bytes)

Note: all chunks must be padded to multiples of 4096 bytes

Note: gzip is unused in practice

Note: uncompressed data is in NBT format, in chunk format(?)

Format
  • "sections" list tag with (up to 16) compound tags
  • each section has 16x16x16 "Blocks", "Data", "SkyLight", "BlockLight" (chunk)
  • each section has "Y" byte tag 0 bottom 15 top
  • each section has optinoal "Add" tag, duplicate of "Data" (used to calculate blockid = (add << 8) + base)
  • each chunk has 16x16 byte array "Biomes"
  • new format y z x ((y * 16 + z) * 16 + x)
  • ".mca" extension
  • "Heightmap" tag uses NBT Int Array.
NBT Format

Compound "": root tag

  • Compound "Level": chunk data
    • Int "xPos": X position of chunk
    • Int "zPos": Z position of chunk
    • Long "LastUpdate": tick when chunk was last saved (0.0)
    • Byte "LightPopulated": unknown 1/0 (true/false) -> (0)
    • Byte "TerrainPopulated": have "special things" been added (ore, trees) 1/abs (true/false) -> (1)
    • Byte "V": 1 (likely chunk version tag)
    • Long "InhabitedTime": cumulative number of ticks players have been here (0)
    • Byte_Array "Biomes": 256 bytes, one per column, in what order?
    • Int_Array "HeightMap": 256 TAG_Int (all 0?)
    • List "Sections":
      • Byte "Y": index (not coordinate!) (0-15)
      • Byte_Array "Blocks": 4096 bytes of block IDs
      • Byte_Array "Add": optional, 2048 bytes of additional data (makes block values 12 bits long)
      • Byte_Array "Data": 2048 bytes of block data (4bits/block)
      • Byte-Array "BlockLight": 4bits/block (all 0?)
      • Byte-Array "SkyLight": 4bits/block (all 0?)
    • List "Entities": list of Compounds (do I care)
    • List "TileEntities": list of Compounds (ditto)
    • List "TileTicks": may not exist (so it won't)

Blocks

Values shown for some items are not the default!

  • Wheat, Carrot, Potato, Pumpkin Stem, and Melon Stem are all full-grown

Some value range are not included because the server will handle it for us.

  • Redstone (wire, repeaters, comparators), Daylight Sensors, Farmland

Many other things are not supported because they are currently outside the scope of this project. If someone else wants to add them, pull requests are accepted!

  • Torches and Redstone Torches
  • Piston and Piston Extension
  • Stairs
  • Beds
  • Signs
  • Doors
  • Rails
  • Ladders, Wall Signs, Furnaces, Chest (facing/attached)
  • Dispensers, Droppers, Hoppers (down, up, powered)
  • Levers (power, facing, wall/ground/ceiling)
  • Pressure Plates (pressed or not)
  • Buttons (set, direction)
  • Snow (depth)
  • Jukebox
  • Pumpkins and Jack o'Lanterns
  • Cake
  • Redstone Repeaters and Comparators
  • Trapdoors
  • Monster Eggs
  • Huge mushrooms
  • Vines
  • Fence Gates
  • Nether Wart
  • Brewing Stand
  • Cauldron
  • End Portal Block
  • Cocoa
  • Tripwire and Tripwire Hook
  • Heads

Stuff to keep in mind

Optimization

Check to see if a section is empty and just don't write it?

Skip writing any air blocks at first?

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Biome = map[string]int{
	"Ocean":                   0,
	"Plains":                  1,
	"Desert":                  2,
	"Extreme Hills":           3,
	"Forest":                  4,
	"Taiga":                   5,
	"Swampland":               6,
	"River":                   7,
	"Nether":                  8,
	"End":                     9,
	"Frozen Ocean":            10,
	"Frozen River":            11,
	"Ice Plains":              12,
	"Ice Mountains":           13,
	"Mushroom Island":         14,
	"Mushroom Island Shore":   15,
	"Beach":                   16,
	"Desert Hills":            17,
	"Forest Hills":            18,
	"Taiga Hills":             19,
	"Extreme Hills Edge":      20,
	"Jungle":                  21,
	"Jungle Hills":            22,
	"Jungle Edge":             23,
	"Deep Ocean":              24,
	"Stone Beach":             25,
	"Cold Beach":              26,
	"Birch Forest":            27,
	"Birch Forest Hills":      28,
	"Roofed Forest":           29,
	"Cold Taiga":              30,
	"Cold Taiga Hills":        31,
	"Mega Taiga":              32,
	"Mega Taiga Hills":        33,
	"Extreme Hills+":          34,
	"Savanna":                 35,
	"Savanna Plateau":         36,
	"Mesa":                    37,
	"Mesa Plateau F":          38,
	"Mesa Plateau":            39,
	"Sunflower Plains":        129,
	"Desert M":                130,
	"Extreme Hills M":         131,
	"Flower Forest":           132,
	"Taiga M":                 133,
	"Swampland M":             134,
	"Ice Plains Spikes":       140,
	"Jungle M":                149,
	"JungleEdge M":            151,
	"Birch Forest M":          155,
	"Birch Forest Hills M":    156,
	"Roofed Forest M":         157,
	"Cold Taiga M":            158,
	"Mega Spruce Taiga":       160,
	"Mega Spruce Taiga Hills": 161,
	"Extreme Hills+ M":        162,
	"Savanna M":               163,
	"Savanna Plateau M":       164,
	"Mesa (Bryce)":            165,
	"Mesa Plateau F M":        166,
	"Mesa Plateau M":          167,
	"(Uncalculated)":          -1,
}
View Source
var Debug = false

Functions

func Nibble

func Nibble(arr []byte, i int) byte

JMT: no bounds checking at this time

func WriteChunkToRegion

func WriteChunkToRegion(in chan Chunk, out chan CTROut, i int)

func WriteNibble

func WriteNibble(arr []byte, i int, b byte)

JMT: no bounds checking at this time

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

func BlockNamed

func BlockNamed(name string) (*Block, error)

func MakeBlock

func MakeBlock(block int, data int) Block

func (Block) BlockName

func (b Block) BlockName() (string, error)

func (Block) String

func (b Block) String() string

type CTROut

type CTROut struct {
	// contains filtered or unexported fields
}

type Chunk

type Chunk struct {
	Sections map[int]Section
	// contains filtered or unexported fields
}

func MakeChunk

func MakeChunk(xPos int32, zPos int32) Chunk

func (Chunk) Name

func (c Chunk) Name() string

func (*Chunk) Read

func (c *Chunk) Read(t nbt.Tag) error

type Entity

type Entity struct {
	// contains filtered or unexported fields
}

func MakeEntity

func MakeEntity() Entity

func ReadEntity

func ReadEntity(tags []nbt.Tag) Entity

func (Entity) String

func (e Entity) String() string

type Location

type Location struct {
	X float64
	Y float64
	Z float64
}

func MakeLocation

func MakeLocation(X float64, Y float64, Z float64) Location

func (Location) String

func (l Location) String() string

func (Location) ToPoint

func (l Location) ToPoint() Point

type Point

type Point struct {
	X int32
	Y int32
	Z int32
}

func MakePoint

func MakePoint(X int32, Y int32, Z int32) Point

func (Point) ChunkXZ

func (p Point) ChunkXZ() XZ

func (Point) Index

func (pt Point) Index() int

func (Point) String

func (p Point) String() string

type Points

type Points []Point

func (Points) Len

func (slice Points) Len() int

func (Points) Less

func (slice Points) Less(i, j int) bool

func (Points) Swap

func (slice Points) Swap(i, j int)

type Section

type Section struct {
	Blocks     []byte
	Add        []byte
	Data       []byte
	BlockLight []byte
	SkyLight   []byte
}

func MakeSection

func MakeSection() Section

func ReadSection

func ReadSection(tarr []nbt.Tag) (*Section, error)

func (Section) String

func (s Section) String() string

type TileEntity

type TileEntity struct {
	// contains filtered or unexported fields
}

func MakeTileEntity

func MakeTileEntity() TileEntity

func ReadTileEntity

func ReadTileEntity(tags []nbt.Tag) TileEntity

func (TileEntity) String

func (e TileEntity) String() string

type TileTick

type TileTick struct {
	// contains filtered or unexported fields
}

TileTick is a TAG_Compound TileTicks TAG_List of TAG_Compound (unless none exist, in which case no tag is sent)

func MakeTileTick

func MakeTileTick() TileTick

func ReadTileTick

func ReadTileTick(tarr []nbt.Tag) TileTick

func (TileTick) String

func (t TileTick) String() string

type World

type World struct {
	SaveDir string
	Name    string
	Spawn   Point

	RandomSeed int64
	ChunkMap   map[XZ]Chunk
	RegionMap  map[XZ][]XZ
	// contains filtered or unexported fields
}

func MakeWorld

func MakeWorld(Name string) World

func ReadWorld

func ReadWorld(dir string, name string, loadAllChunks bool) (*World, error)

func (*World) Biome

func (w *World) Biome(xz XZ) (byte, error)

func (World) Block

func (w World) Block(pt Point) (*Block, error)

func (*World) BlockLight

func (w *World) BlockLight(pt Point) (byte, error)

JMT: currently unused

func (World) Chunk

func (w World) Chunk(pt Point) (*Chunk, error)

func (*World) HeightMap

func (w *World) HeightMap(xz XZ) (int32, error)

func (*World) MakeChunk

func (w *World) MakeChunk(xz XZ, tag nbt.Tag) (*Chunk, error)

func (World) Section

func (w World) Section(pt Point) (*Section, error)

func (*World) SetBiome

func (w *World) SetBiome(xz XZ, b byte) error

func (*World) SetBlock

func (w *World) SetBlock(pt Point, b Block) error

func (*World) SetBlockLight

func (w *World) SetBlockLight(pt Point, b byte) error

func (*World) SetHeightMap

func (w *World) SetHeightMap(xz XZ, i int32) error

func (*World) SetRandomSeed

func (w *World) SetRandomSeed(seed int64)

func (*World) SetSaveDir

func (w *World) SetSaveDir(dir string) error

func (*World) SetSkyLight

func (w *World) SetSkyLight(pt Point, b byte) error

func (*World) SetSpawn

func (w *World) SetSpawn(p Point)

func (*World) SkyLight

func (w *World) SkyLight(pt Point) (byte, error)

func (World) String

func (w World) String() string

func (World) Write

func (w World) Write() error

type XZ

type XZ struct {
	X int32
	Z int32
}

func (XZ) Point

func (xz XZ) Point(y int32) Point

func (XZ) String

func (xz XZ) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL