PHPackages                             cosmicpe/blockdata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cosmicpe/blockdata

ActiveLibrary

cosmicpe/blockdata
==================

0.0.3(2y ago)302173[1 PRs](https://github.com/Cosmoverse/BlockData/pulls)PHP

Since Aug 26Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Cosmoverse/BlockData)[ Packagist](https://packagist.org/packages/cosmicpe/blockdata)[ RSS](/packages/cosmicpe-blockdata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

BlockData
=========

[](#blockdata)

A PocketMine-MP virion that lets plugins set arbitrary data to blocks.

### What's so special about BlockData?

[](#whats-so-special-about-blockdata)

1. Multiple plugins can store data in the same block without overriding each other's data.
2. BlockData never reads the database unless `BlockDataWorld::getBlockDataAt()` is called. So the block data isn't automatically cached when a chunk is loaded.
3. yeahh..

### Why don't you just store data in tiles?

[](#why-dont-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?

[](#are-there-any-drawbacks)

1. 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](http://google.github.io/snappy/) compression. A call to `LevelDB::get()` hardly takes a millisecond anyway. BlockData instances once created by the virion are cached until the chunk unloads.
2. There's an inconsistency in deleting block =&gt; 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.
3. Because BlockData doesn't autoload with chunks (unlike tiles), you can't efficiently write BlockData that's always ticking.

### Developer Docs

[](#developer-docs)

Install with the Virion 3 standard:

```
$ composer require cosmicpe/blockdata
```

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`.

```
final class MyPlugin extends PluginBase{

	/** @var BlockDataWorldManager */
	private $manager;

	protected function onEnable() : void{
		$this->manager = BlockDataWorldManager::create($this);
	}
}
```

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).

```
class BlockHistoryData extends BlockData{ // stores when block was placed and by whom.

	public static function nbtDeserialize(CompoundTag $nbt) : BlockData{
		return new BlockHistoryData($nbt->getString("placer"), $nbt->getLong("timestamp"));
	}

	/** @var string */
	private $placer;

	/** @var int */
	private $timestamp;

	public function __construct(string $placer, ?int $timestamp = null){
		$this->placer = $placer;
		$this->timestamp = $timestamp ?? time();
	}

	public function getPlacer() : string{
		return $this->placer;
	}

	public function getTimestamp() : int{
		return $this->timestamp;
	}

	public function nbtSerialize() : CompoundTag{
		return CompoundTag::create()
			->setString("placer", $this->placer)
			->setLong("timestamp", $this->timestamp);
	}
}
```

And map it to a string identifier.

```
const BLOCK_HISTORY_DATA = "blockhistory";
BlockDataFactory::register(self::BLOCK_HISTORY_DATA, BlockHistoryData::class);
```

Wew, now all that's remaining is event handling!

```
public function onBlockPlace(BlockPlaceEvent $event) : void{
	$block = $event->getBlock();
	$pos = $block->getPos();
	$data = new BlockHistoryData($event->getPlayer()->getName());
	$this->manager->getWorld($pos->getWorld())->setBlockDataAt($pos->x, $pos->y, $pos->z, $data);
}

public function onPlayerInteract(PlayerInteractEvent $event) : void{
	if($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK && $event->getItem()->getId() === ItemIds::STICK){
		$block = $event->getBlock();
		$pos = $block->getPos();

		$data = $this->manager->get($pos->getWorld())->getBlockDataAt($pos->x, $pos->y, $pos->z);
		if($data instanceof BlockHistoryData){
			$event->getPlayer()->sendMessage(TextFormat::LIGHT_PURPLE . "This block was placed by " . TextFormat::WHITE . $data->getPlacer() . TextFormat::LIGHT_PURPLE . " on " . TextFormat::WHITE . gmdate("d-m-Y H:i:s", $data->getTimestamp()));
		}
	}
}
```

Also check out [BlockData-Example-Plugin](https://github.com/Cosmoverse/BlockData-Example-Plugin).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

3

Last Release

979d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/247134f60bf8c5c7c8a2f06b0ecea431a052614283aac5093b57bde51039e34a?d=identicon)[muqsit](/maintainers/muqsit)

---

Top Contributors

[![Muqsit](https://avatars.githubusercontent.com/u/15074389?v=4)](https://github.com/Muqsit "Muqsit (15 commits)")[![unickorn](https://avatars.githubusercontent.com/u/29836508?v=4)](https://github.com/unickorn "unickorn (5 commits)")[![Endermanbugzjfc](https://avatars.githubusercontent.com/u/53002741?v=4)](https://github.com/Endermanbugzjfc "Endermanbugzjfc (2 commits)")[![JavierLeon9966](https://avatars.githubusercontent.com/u/58715544?v=4)](https://github.com/JavierLeon9966 "JavierLeon9966 (1 commits)")[![poggit-bot](https://avatars.githubusercontent.com/u/22427965?v=4)](https://github.com/poggit-bot "poggit-bot (1 commits)")[![RoyalMCPE](https://avatars.githubusercontent.com/u/20691625?v=4)](https://github.com/RoyalMCPE "RoyalMCPE (1 commits)")

---

Tags

pmmppocketmine-mpvirion

### Embed Badge

![Health badge](/badges/cosmicpe-blockdata/health.svg)

```
[![Health](https://phpackages.com/badges/cosmicpe-blockdata/health.svg)](https://phpackages.com/packages/cosmicpe-blockdata)
```

###  Alternatives

[muqsit/invmenu

A PocketMine-MP virion to create and manage virtual inventories!

2234.2k1](/packages/muqsit-invmenu)[sof3/libasynql

1427.8k3](/packages/sof3-libasynql)[muqsit/simple-packet-handler

Handle specific data packets (virion for PMMP API 4.0.0)

426.1k3](/packages/muqsit-simple-packet-handler)[dktapps/pmforms

Form API library for PocketMine-MP plugins

522.3k1](/packages/dktapps-pmforms)[sof3/infoapi

321.2k1](/packages/sof3-infoapi)[muqsit/asynciterator

A virion that simplifies writing tasks that traverse iterators

182.9k](/packages/muqsit-asynciterator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
