# mceditlib.anvil package — mceditlib 0.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- mceditlib 0.1 documentation »
- mceditlib package »

# mceditlib.anvil package

## Submodules

## mceditlib.anvil.adapter module

adapter

exception `mceditlib.anvil.adapter.``AnvilChunkFormatError`

  Bases: `exceptions.IOError`

  Raised when an Anvil chunk’s data is not as expected

exception `mceditlib.anvil.adapter.``SessionLockLost`

  Bases: `exceptions.IOError`

  Raised when the session lock is lost because another program (Minecraft) opened the level while we were editing it.

`mceditlib.anvil.adapter.``unpackNibbleArray`(dataArray)

`mceditlib.anvil.adapter.``packNibbleArray`(unpackedData)

`mceditlib.anvil.adapter.``deflate`(data)

`mceditlib.anvil.adapter.``inflate`(data)

`mceditlib.anvil.adapter.``sanitizeBlocks`(section, blocktypes)

class `mceditlib.anvil.adapter.``AnvilSection`(section_tag=None)

  Bases: `object`

  Internal representation of a 16x16x16 chunk section. Arrays are indexed YZX.

  4-bit arrays are unpacked to byte arrays to make them work with numpy’s array routines.

  To create the full 12-bit block ID, the Blocks array is extended to 16 bits and the Add array is merged into the Blocks array.

  Variables:

  - Y – section’s Y value [0..(world.Height+15) >> 4]
  - Blocks – Block IDs [0..4095]
  - Data – Block sub-data [0..15]
  - BlockLight – Light emitted by blocks [0..15]
  - SkyLight – Light emitted by the sun/moon [0..15]

  `buildNBTTag`()

    Return a TAG_Compound for saving this section to a chunk.

class `mceditlib.anvil.adapter.``AnvilChunkData`(adapter, cx, cz, dimName, rootTag=None, create=False)

  Bases: `object`

  This is the chunk data backing a WorldEditorChunk. Chunk data is retained by the WorldEditor until its WorldEditorChunk is no longer used, then it is either cached in memory, discarded, or written to disk according to resource limits.

  `buildNBTTag`()

    does not recalculate any data or light

  `sectionPositions`()
  `getSection`(cy, create=False)

    Parameters:

    - cy – Section number (y coordinate >> 4)
    - create – If False, returns None if the section is not present, otherwise creates the section.

    Returns: | The requested section, or None if it wasn’t created.
    Return type: | AnvilSection
    Raises: | ValueError if create is True and the requested section can’t be stored in this chunk.

  `bounds`
  `blocktypes`
  `Biomes`
  `HeightMap`
  `TerrainPopulated`

class `mceditlib.anvil.adapter.``AnvilWorldMetadata`(metadataTag)

  Bases: `object`

  `worldSpawnPosition`()
  `setWorldSpawnPosition`(pos)

class `mceditlib.anvil.adapter.``AnvilWorldAdapter`(filename=None, create=False, readonly=False, resume=None)

  Bases: `object`

  Provides an interface to AnvilWorldFolder/RevisionHistory that is usable by WorldEditor

  This interface is the base used for all adapter classes. When writing a new adapter, make sure to implement all required methods and attributes. Required methods and attrs are the ones with docstrings.

  `minHeight` = 0
  `maxHeight` = 256
  `blocktypes` = <BlockTypeSet (Alpha)>
  `hasLights` = True
  `EntityRef`

    alias of `PCEntityRef`

  `TileEntityRef`

    alias of `PCTileEntityRef`

  `loadMetadata`()
  `loadFMLMapping`()
  `syncToDisk`()

    Write cached items (metadata from level.dat and players in players/ folder) to the current revision. :return: :rtype:

  `saveChanges`()

    Write all changes from all revisions into the world folder.

    Returns: |
    Return type: | None

  `close`()

    Close the world, deleting temporary files and freeing resources. Operations on a closed world are undefined.

    Returns: |
    Return type: | None

  `requireRevisions`()

    Enforce the creation of new revisions by making the world folder’s revision read-only. :return: :rtype:

  `createRevision`()

    Create a new undo revision. Subsequent changes should be stored in the new revision.

    Returns: |
    Return type: |

  `closeRevision`()

    Close the current revision and mark it read-only. Subsequent edits will not be possible until createRevision is called.

    Returns: |
    Return type: |

  `setRevisionInfo`(info)

    Attach some arbitrary JSON-serializable data to the current revision

    Parameters: | info (list | dict | str | unicode | int) – JSON-serializable data

  `getRevisionInfo`()

    Return JSON-serializable data attached previously to the current revision via setRevisionInfo, or None if no data is attached.

    Returns: |
    Return type: | list | dict | str | unicode | int | None

  `selectRevision`(index)
    Select the current revision by index. Return changes between the previous revision and this one. If

      the index is invalid, returns None and does nothing.

      (XXX use an ID instead of index?)

    Parameters: | index –
    Returns: |
    Return type: | RevisionChanges

  `listRevisions`()

    List the revision indexes and infos as (index, info) tuples. Info is JSON-serializable data previously attached with setRevisionInfo, or None.

    Returns: |
    Return type: | iterator[(int, list | dict | str | unicode | int)]

  `acquireSessionLock`()

    Acquire the world’s session.lock. Formats without this file may do nothing.

    Returns: |
    Return type: |

  `checkSessionLock`()

    Make sure the lock previously acquired by acquireSessionLock is still valid. Raise SessionLockLost if it is not. Raising the exception will abort any writes done to the main world folder.

    Returns: |
    Return type: |

  classmethod `canOpenFile`(filename)

    Ask this adapter if it can open the given file.

    Parameters: | filename (str | unicode) – File to identify
    Returns: |
    Return type: | boolean

  `listDimensions`()

    List the names of all dimensions in this world.

    Returns: |
    Return type: | iterator of str

  `chunkCount`(dimName)

    Count the chunks in the given dimension

    Parameters: | dimName (str) –
    Returns: |
    Return type: | int

  `chunkPositions`(dimName)

    List the chunk positions (cx, cz) in the given dimension.

    Returns: |
    Return type: | Iterator of (int, int)

  `containsChunk`(cx, cz, dimName)

    Return whether the given chunk is present in the given dimension

    Returns: |
    Return type: | bool

  `readChunk`(cx, cz, dimName)

    Return chunk (cx, cz) in the given dimension as an AnvilChunkData. Raise ChunkNotPresent if not found.

    Returns: |
    Return type: | AnvilChunkData

  `writeChunk`(chunk)

    Write the given AnvilChunkData to the current revision.

  `createChunk`(cx, cz, dimName)

    Create a new empty chunk at the given position in the given dimension.

    Returns: |
    Return type: | AnvilChunkData

  `deleteChunk`(cx, cz, dimName)

    Delete the chunk at the given position in the given dimension.

  `listPlayers`()

    List the names of all players in this world (XXX players folder in dimension folders??)

    Returns: |
    Return type: | Iterator of [str]

  `getPlayer`(playerUUID='')
  `getPlayerTag`(playerUUID='')

    Return the root NBT tag for the named player. Raise PlayerNotFound if not present.

    Parameters: | playerUUID (unicode) –
    Returns: |
    Return type: | PCPlayer

  `savePlayerTag`(tag, playerUUID)
  `createPlayer`(playerUUID='')
    Create a new player with the given name and return the PlayerRef. Raises some kind of IOError if the player
      could not be created.

    Parameters: | playerUUID (str) –
    Returns: |
    Return type: | PCPlayer

class `mceditlib.anvil.adapter.``PlayerAbilitiesAttrs`(rootTag)

  Bases: `mceditlib.nbtattr.CompoundAttrs`

class `mceditlib.anvil.adapter.``AnvilPlayerRef`(adapter, playerUUID)

  Bases: `object`

  `GAMETYPE_SURVIVAL` = 0
  `GAMETYPE_CREATIVE` = 1
  `GAMETYPE_ADVENTURE` = 2
  `setAbilities`(gametype)
  `setGameType`(gametype)
  `Spawn`
  `save`()
  `dimName`

## mceditlib.anvil.biome_types module

biome_types.py

Definitions for biome names, climate info, water color, and more.

class `mceditlib.anvil.biome_types.``BiomeType`

  Bases: `mceditlib.anvil.biome_types.BiomeType`

  `watercolor`

## mceditlib.anvil.entities module

entities

class `mceditlib.anvil.entities.``PCEntityRef`(rootTag, chunk=None)

  Bases: `object`

  `raw_tag`()
  `copy`()
  `copyWithOffset`(copyOffset, newEntityClass=None)

class `mceditlib.anvil.entities.``PCTileEntityRef`(rootTag, chunk=None)

  Bases: `object`

  `raw_tag`()
  `Position`
  `copy`()
  `copyWithOffset`(copyOffset, newEntityClass=None)

## mceditlib.anvil.worldfolder module

worldfolder

class `mceditlib.anvil.worldfolder.``AnvilWorldFolder`(filename, create=False)

  Bases: `object`

  `getFilePath`(path)
  `getFolderPath`(path)
  `containsFile`(path)
  `deleteFile`(path)
  `readFile`(path)
  `writeFile`(path, data)
  `listFolder`(path)
  `listAllFiles`()
  `listDimensions`()
  `getRegionFolderPath`(dimName)
  `getRegionFilename`(rx, rz, dimName)
  `getRegionFile`(rx, rz, dimName)

    Returns: |
    Return type: | RegionFile

  `getRegionForChunk`(cx, cz, dimName)
  `close`()
  `chunkCount`(dimName)

    Parameters: | dimName (unicode or str) – Name of dimension
    Returns: | Number of chunks in given dimension
    Return type: | int

  `chunkPositions`(dimName)

    Iterate over chunk positions :type dimName: unicode or str :return: iterator :rtype: iterator [(int, int)]

  `containsChunk`(cx, cz, dimName)
  `deleteChunk`(cx, cz, dimName)
  `readChunkBytes`(cx, cz, dimName)
  `writeChunkBytes`(cx, cz, dimName, data)
  `copyChunkFrom`(sourceFolder, cx, cz, dimName)

    Copy chunk from another source folder without decompression :param sourceFolder: :type sourceFolder: AnvilWorldFolder :param cx: :type cx: int :param cz: :type cz: int :param dimName: :type dimName: unicode :return: :rtype:

## Module contents

Anvil world format introduced with Minecraft 1.2 for PC

### Navigation

- index
- modules |
- next |
- previous |
- mceditlib 0.1 documentation »
- mceditlib package »