world – Worlds

class bravo.world.ChunkCache[source]

Bases: object

A cache which holds references to all chunks which should be held in memory.

This cache remembers chunks that were recently used, that are in permanent residency, and so forth. Its exact caching algorithm is currently null.

When chunks dirty themselves, they are expected to notify the cache, which will then schedule an eviction for the chunk.

exception bravo.world.ImpossibleCoordinates[source]

Bases: exceptions.Exception

A coordinate could not ever be valid.

class bravo.world.World(config, name)[source]

Bases: object

Object representing a world on disk.

Worlds are composed of levels and chunks, each of which corresponds to exactly one file on disk. Worlds also contain saved player data.

Parameters:
name : str
The configuration key to use to look up configuration data.
async = False

Whether this world is using multiprocessing methods to generate geometry.

connect()[source]

Connect to the world.

destroy(coords, *args, **kwargs)[source]

Destroy a block in an unknown chunk.

Returns:a Deferred that will fire on completion
dimension = 'earth'

The world dimension. Valid values are earth, sky, and nether.

enable_cache(size)[source]

Set the permanent cache size.

Changing the size of the cache sets off a series of events which will empty or fill the cache to make it the proper size.

For reference, 3 is a large-enough size to completely satisfy the Notchian client’s login demands. 10 is enough to completely fill the Notchian client’s chunk buffer.

Parameters:size (int) – The taxicab radius of the cache, in chunks
Returns:A Deferred which will fire when the cache has been

adjusted.

factory = None

The factory managing this world.

Worlds do not need to be owned by a factory, but will not callback to surrounding objects without an owner.

flush_chunk()[source]

Flush a dirty chunk.

This method will always block when there are dirty chunks.

get_block(coords, *args, **kwargs)[source]

Get a block from an unknown chunk.

Returns:a Deferred with the requested value
get_metadata(coords, *args, **kwargs)[source]

Get a block’s metadata from an unknown chunk.

Returns:a Deferred with the requested value
level = Level(seed=0, spawn=(0, 0, 0), time=0)

The initial level data.

load_player(username)[source]

Retrieve player data.

Returns:a Deferred that will be fired with a Player
mark_dirty(coords, *args, **kwargs)[source]

Mark an unknown chunk dirty.

Returns:a Deferred that will fire on completion
postprocess_chunk(chunk)[source]

Do a series of final steps to bring a chunk into the world.

This method might be called multiple times on a chunk, but it should not be harmful to do so.

request_chunk(*args, **kwargs)[source]

Request a Chunk to be delivered later.

Returns:Deferred that will be called with the Chunk
save_chunk(chunk)[source]

Write a chunk to the serializer.

Note that this method does nothing when the given chunk is not dirty or saving is off!

Returns:A Deferred which will fire after the chunk has been

saved with the chunk.

save_off()[source]

Disable saving to disk.

This is useful for accessing the world on disk without Bravo interfering, for backing up the world.

save_on()[source]

Enable saving to disk.

saving = True

Whether objects belonging to this world may be written out to disk.

set_block(coords, *args, **kwargs)[source]

Set a block in an unknown chunk.

Returns:a Deferred that will fire on completion
set_metadata(coords, *args, **kwargs)[source]

Set a block’s metadata in an unknown chunk.

Returns:a Deferred that will fire on completion
start()[source]

Start managing a world.

Connect to the world and turn on all of the timed actions which continuously manage the world.

stop(*args, **kwargs)[source]

Stop managing the world.

This can be a time-consuming, blocking operation, while the world’s data is serialized.

Note to callers: If you want the world time to be accurate, don’t forget to write it back before calling this method!

Returns:A Deferred that fires after the world has stopped.
sync_destroy(coords, *args, **kwargs)[source]

Destroy a block in an unknown chunk.

Returns:None
sync_get_block(coords, *args, **kwargs)[source]

Get a block from an unknown chunk.

Returns:the requested block
sync_get_metadata(coords, *args, **kwargs)[source]

Get a block’s metadata from an unknown chunk.

Returns:the requested metadata
sync_mark_dirty(coords, *args, **kwargs)[source]

Mark an unknown chunk dirty.

Returns:None
sync_request_chunk(coords, *args, **kwargs)[source]

Get an unknown chunk.

Returns:the requested Chunk
sync_set_block(coords, *args, **kwargs)[source]

Set a block in an unknown chunk.

Returns:None
sync_set_metadata(coords, *args, **kwargs)[source]

Set a block’s metadata in an unknown chunk.

Returns:None
bravo.world.coords_to_chunk(f)[source]

Automatically look up the chunk for the coordinates, and convert world coordinates to chunk coordinates.

bravo.world.sync_coords_to_chunk(f)[source]

Either get a chunk for the coordinates, or raise an exception.