presentkim / client-block-utils
Show blocks that only exist on the client, for one player or every viewer, on axolotl-pm/PocketMine-MP
Requires
- php: ^8.4
- pocketmine/pocketmine-mp: ^5.0
Requires (Dev)
- axolotl-pm/pocketmine-mp: ^5.51
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
client-block-utils
Show blocks that only exist on the client, for one player or every viewer, on axolotl-pm/PocketMine-MP
Packagist ยท Changelog ยท Report a bug ยท Request a feature
ClientBlocks::forPlayer($player)->set($pos, VanillaBlocks::GOLD())->remove($pos);
๐ฆ Installation
composer require presentkim/client-block-utils
| Requirement | Version |
|---|---|
| Server | axolotl-pm/PocketMine-MP (fork of PocketMine-MP 5) |
| PHP | 8.4 or newer |
Using it in a plugin: plugins built from presentkim-pm/plugin-template bundle Composer libraries into the phar with shaded namespaces at release, so
composer requireis all a plugin needs.
๐ Quick start
use kim\present\clientblockutils\ClientBlockLayer; use kim\present\clientblockutils\ClientBlocks; use pocketmine\block\VanillaBlocks; // onEnable() ClientBlocks::register($this); // Only this player sees a gold block; the world keeps its real block $overlay = ClientBlocks::forPlayer($player); $overlay->set($pos, VanillaBlocks::GOLD()); // Every player who sees the chunk sees a light block, without hiding the real block $lights = ClientBlocks::forWorld($world); $lights->set($pos, VanillaBlocks::LIGHT()->setLightLevel(13), ClientBlockLayer::LIQUID); // Show the real blocks again $overlay->remove($pos); $lights->clear();
๐ API reference
All classes are in kim\present\clientblockutils.
| Method | Description |
|---|---|
ClientBlocks::register(PluginBase $plugin) : void |
Registers the listener that paints overlays again. Call once from onEnable() |
ClientBlocks::forPlayer(Player $player, ?World $world = null) : ClientBlockOverlay |
An overlay only the player sees (default: the player's world) |
ClientBlocks::forWorld(World $world) : ClientBlockOverlay |
An overlay every player who sees the chunk sees |
ClientBlocks::networkId(Block $block) : int |
The network block ID UpdateBlockPacket expects |
ClientBlockOverlay::set(Vector3 $pos, Block $block, ClientBlockLayer $layer = NORMAL, ?CompoundTag $tileNbt = null) : self |
Shows a block on a layer, with optional block entity data (normal layer only) |
ClientBlockOverlay::get(Vector3 $pos, ClientBlockLayer $layer = NORMAL) : ?Block |
The block shown on the layer |
ClientBlockOverlay::remove(Vector3 $pos, ?ClientBlockLayer $layer = null) : self |
Shows the real block again (null: both layers) |
ClientBlockOverlay::clear() : void |
Removes every block |
ClientBlockOverlay::discard() : void |
Forgets every block without sending packets |
ClientBlockOverlay::getPositions() : list<Vector3>, isEmpty() : bool |
The positions shown |
๐งญ How it works
- Blocks are sent with
UpdateBlockPacket.ClientBlockLayer::NORMALreplaces the block,ClientBlockLayer::LIQUIDshows a block inside it (the server never uses that layer, so the real block stays visible). - When a viewer receives a chunk again (
PlayerPostChunkSendEvent), the overlay paints its blocks in that chunk again. A world overlay also reaches players who come into view later. - When the real block at a position changes, the world sends it at the end of the tick; the overlay paints its block again on the next tick.
- A player overlay sends nothing while the player is in another world, and paints again when the player comes back. The overlays of a player who quits are dropped.
- Without
ClientBlocks::register()overlays still work, but nothing paints them again after a chunk resend or a change of the real block. - Two overlays on the same position overwrite each other on the client: the one that sent last is shown.
๐งช Development
composer install --ignore-platform-req='ext-*' composer analyse composer test
The server's native extensions are not needed for the tests, so ext-* requirements are ignored on install.
๐ License
Distributed under the MIT License. See LICENSE for more information.