Download the PHP package cosmicpe/blockdata without Composer
On this page you can find all versions of the php package cosmicpe/blockdata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package blockdata
BlockData
A PocketMine-MP virion that lets plugins set arbitrary data to blocks.
What's so special about BlockData?
- Multiple plugins can store data in the same block without overriding each other's data.
- BlockData never reads the database unless
BlockDataWorld::getBlockDataAt()
is called. So the block data isn't automatically cached when a chunk is loaded. - yeahh..
Why don't you just store data in tiles?
Storing data in tiles is not a problem as long as the number of loaded tiles can be kept moderated. When a chunk loads, the server reads all tiles from the database and caches them. If you were to store block data for each block in a chunk using tiles, that's 65536 tile instances in the RAM! To avoid this, BlockData only loads data of blocks when explicitly requested to.
Are there any drawbacks?
- Since the virion has a strict policy on caching, a fresh call to
BlockDataWorld::getBlockDataAt()
would read the database synchronously. If this worries you, BlockData is backed by LevelDB and uses the snappy compression. A call toLevelDB::get()
hardly takes a millisecond anyway. BlockData instances once created by the virion are cached until the chunk unloads. - There's an inconsistency in deleting block => deleting data. This is due to the fact that blocks can be set by several different ways but there aren't the same number of ways to directly listen for block changes.
Blocks can be changed using
World::setBlockAt()
,World::setChunk()
or even when the plugin using this virion is disabled and the plugin will never know that the block was deleted, so the BlockData in such cases will exist well after the block has been deleted. - Because BlockData doesn't autoload with chunks (unlike tiles), you can't efficiently write BlockData that's always ticking.
Developer Docs
Install with the Virion 3 standard:
The first thing your plugin will have to do to gain access to this virion's API is request a BlockDataWorldManager
instance.
BlockDataWorldManager
maps BlockDataWorld
s to pocketmine's worlds. BlockDataWorld
provides an API to get and set BlockData
.
Now lets create a BlockData class! BlockData is backed by nbt. (Honestly, might switch over to JSON but not sure if it's worth sacrificing binary-safe data storage).
And map it to a string identifier.
Wew, now all that's remaining is event handling!
Also check out BlockData-Example-Plugin.