Search by

presentkim / client-entity-utils

PresentKim

Entities that only exist on the clients of their viewers, and a trait that makes a custom entity look like a player, for axolotl-pm/PocketMine-MP

Package info

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

pkg:composer/presentkim/client-entity-utils

Fund package maintenance!

Patreon

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 0

3.0.0 2026-12-02 02:29 UTC

This package is auto-updated.

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


README

Packagist CI Stars License


client-entity-utils

Entities that only exist on the clients of their viewers, and a trait that makes a custom entity look like a player.

Packagist ยท Changelog ยท Report a bug ยท Request a feature

ClientEntity::human($skin, $pos)->setNameTag("Guide")->spawnTo($player);

๐ŸŒŸ Why client-entity-utils?

Models, NPCs, holograms and container entities often need nothing from the world: no ticking, no physics, no saving, and only some players should see them. Building their packets by hand means runtime IDs, metadata, player list entries, skins and equipment conversion every time.

  • ClientEntity : an entity of any type, or a player model with a skin, that the world knows nothing of. Set its metadata, equipment and position, and choose who sees it
  • HumanoidTrait : for a real Entity class of your own that must look like a player (skin, equipment, movement)
  • Tested : on PHP 8.4 / 8.5, PHPStan level 9 with strict rules

Formerly presentkim/humanoid-trait. Its 2.x versions stay on Packagist for existing plugins; from 3.0.0 the trait is kim\present\cliententityutils\HumanoidTrait.

๐Ÿ“ฆ Installation

composer require presentkim/client-entity-utils
Requirement Version
Server axolotl-pm/PocketMine-MP (fork of PocketMine-MP 5)
PHP 8.4 or newer

The Poggit virion for the original PocketMine-MP API 4 is kept on the legacy/pmmp-5.44 branch (no longer maintained).

๐Ÿš€ Quick start

A client-only entity

use kim\present\cliententityutils\ClientEntities;
use kim\present\cliententityutils\ClientEntity;
use pocketmine\item\VanillaItems;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;

// onEnable(), needed for player models
ClientEntities::register($this);

$npc = ClientEntity::human($player->getSkin(), $pos, yaw: 90.0)
    ->setNameTag("Guide")
    ->setFlag(EntityMetadataFlags::IMMOBILE)
    ->setMainHand(VanillaItems::DIAMOND_SWORD());
$npc->spawnTo($player);

$skeleton = ClientEntity::actor(EntityIds::WITHER_SKELETON, $pos)->setScale(0.75);
$skeleton->spawnTo($player);

$npc->teleport($pos->add(0, 1, 0));
$npc->despawnFromAll();

A real entity that looks like a player

The entity class must provide getName(), and set $uuid and $skinData before it is spawned.

use kim\present\cliententityutils\HumanoidTrait;
use pocketmine\entity\Entity;
use Ramsey\Uuid\Uuid;

final class NpcEntity extends Entity{
    use HumanoidTrait;

    public static function getNetworkTypeId() : string{
        return EntityIds::PLAYER;
    }

    protected function initEntity(CompoundTag $nbt) : void{
        parent::initEntity($nbt);
        $this->uuid = Uuid::uuid4();
        $this->skinData = $skinData; // a SkinData
    }

    public function getName() : string{
        return "NPC";
    }

    // getInitialSizeInfo(), getInitialDragMultiplier() and getInitialGravity() as for any Entity
}

"## ๐Ÿ“– API reference

All classes are in kim\present\cliententityutils.

ClientEntity

Method Description
ClientEntities::register(PluginBase $plugin) : void Needed before spawning a player model. Call once from onEnable()
ClientEntity::actor(string $type, Vector3 $pos, float $yaw = 0, float $pitch = 0) : self An entity of an EntityIds type
ClientEntity::human(Skin $skin, Vector3 $pos, float $yaw = 0, float $pitch = 0) : self A player model wearing the skin
setNameTag(), setScale(), setFlag(), setBoundingBox() Metadata helpers, sent to the viewers
getMetadata() : EntityMetadataCollection, sendMetadata() : void Any other metadata
setArmor(), setMainHand(), setOffHand() Equipment, sent only when it changed
teleport(Vector3 $pos, ?float $yaw = null, ?float $pitch = null) : self Moves the entity
spawnTo(Player), despawnFrom(Player), despawnFromAll(), getViewers() Viewers
createSpawnPackets(NetworkSession), createDespawnPackets(), createListRemovalPacket() The packets, to send them yourself (with a ContainerOpenPacket, for example)
getActorId() : int The ID the clients know the entity by (live_horse_renderer, links)
  • A player model gets a player list entry for its skin. The client loads the skin from it, so it is removed only ClientEntity::LIST_ENTRY_TICKS (20) ticks after the spawn: removing it in the same batch left the default skin about half the time.
  • Items and skins are converted with each viewer's own type converter. Viewers are held weakly.

HumanoidTrait

Method Description
getSkinData() : SkinData The skin shown to viewers
setSkin(SkinData $skinData) : void Change the skin and send it to all viewers
sendSkin(?array $targets = null) : void Send the skin to some players (default: all viewers)
getItemInHand() / setItemInHand(Item $item) The main hand item
getItemInOffHand() / setItemInOffHand(Item $item) The off hand item
sendEquipment(Item $item, int $windowId, int $inventorySlot = 0, ?array $targets = null) Send an equipment packet
getUniqueId() : UuidInterface The player list UUID of the entity

๐Ÿงช Development

composer install --ignore-platform-req='ext-*'
composer analyse
composer test

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.