Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
gerhalt edited this page Dec 17, 2012 · 3 revisions

The World object is the main subject of user interaction with Python scripts. It provides the standard interface for a user or script to modify a level.

Behavior

World objects are fairly simple, containing a path to the root world directory (right now it assumes that a server has already created and populated this directory). Each World also stores a information on what Regions and Chunks are currently in memory.

Regions are stored in a linked-list format; when a region is modified it is moved to the front of the list. When the maximum length of the list is exceeded, the most ancient region is saved and unloaded from memory.

Chunks are referenced in a hash table of PyObject pointers. A simple hash function is used based on the Chunk's coordinates. When a new Chunk is requested that hashes to the same value, the older Chunk is saved and the reference is decremented. It isn't necessarily unloaded, since Chunks are full Python objects and references may be in use elsewhere.

Interface

World objects have more functions, but some of them are redundant or uninteresting (such as World.load_chunk), and I don't anticipate a user interacting with them much.

  • World.get_block(x, y, z) - Returns the block at the given set of coordinates.
  • World.put_block(x, y, z, Block) - Inserts a block into the World at the given location.
  • World.save() - Saves the world to disk, including any updates to regions currently in memory.

Unimplemented:

  • World.set_entity()
Clone this wiki locally