Search by

presentkim / client-block-utils

PresentKim

Show blocks that only exist on the client, for one player or every viewer, on axolotl-pm/PocketMine-MP

Package info

github.com/presentkim-pm/client-block-utils

pkg:composer/presentkim/client-block-utils

Statistics

Installs: 8

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-12-02 02:29 UTC

This package is auto-updated.

Last update: 2026-12-02 02:37:17 UTC


README

Packagist CI Stars License


Logo

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 require is 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::NORMAL replaces the block, ClientBlockLayer::LIQUID shows 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.