presentkim / identifier-utils
Library that helps register custom items and entities on axolotl-pm/PocketMine-MP (PocketMine-MP 5 string identifiers)
Requires
- php: ^8.4
- pocketmine/pocketmine-mp: ^5.0
Requires (Dev)
- axolotl-pm/pocketmine-mp: ^5.51
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
identifier-utils
Register custom items and entities by string identifier on PocketMine-MP 5.
Packagist ยท Changelog ยท Report a bug ยท Request a feature
๐ Why identifier-utils?
Registering a custom item on PocketMine-MP 5 means touching four separate places. This library does it in one call.
StringToItemParser:/give myplugin:rubyand/give rubyworkGlobalItemDataHandlers: the item can be saved in worlds / inventories and sent in network item stacks- Item type dictionary : the client's item registry gets the item, with its component data
- Creative inventory : optional
๐ฆ Installation
composer require presentkim/identifier-utils
| Requirement | Version |
|---|---|
| Server | axolotl-pm/PocketMine-MP (fork of PocketMine-MP 5) |
| PHP | 8.4 or newer |
The Poggit virion for the old numeric id system is kept on the
legacy/pmmp-5.44branch (no longer maintained).
๐ Quick start
use kim\present\utils\identifier\IdentifierUtils; use pocketmine\inventory\CreativeCategory; use pocketmine\item\Item; use pocketmine\item\ItemIdentifier; // In onEnable(), before any player logs in IdentifierUtils::registerItem( "myplugin:ruby", static fn(ItemIdentifier $id) : Item => new Item($id, "Ruby"), creativeCategory: CreativeCategory::ITEMS, aliases: ["red gem"] ); IdentifierUtils::registerEntity("myplugin:ghost");
The factory receives the ItemIdentifier allocated with ItemTypeIds::newId() and must build the item with it.
A custom Item subclass works the same way. Pass components (the components compound of a custom item, with
item_properties, minecraft:icon, ...) to describe the item to the client. When omitted a minimal one is generated.
๐ API reference
| Method | Description |
|---|---|
registerItem(string, Closure, ?CompoundTag, ?CreativeCategory, array) : Item |
Register a custom item everywhere, returns the item |
registerEntity(string $stringId) : void |
Add an entity identifier to the AvailableActorIdentifiersPacket cache |
nextItemRuntimeId(?ItemTypeDictionary) : int |
A network runtime id that is not in the item type dictionary |
addToItemTypeDictionary(ItemTypeDictionary, ItemTypeEntry...) : void |
Add entries to a dictionary |
removeNamespace(string $stringId) : string |
minecraft:diamond => diamond |
Notes
- Call
registerItem()andregisterEntity()before players log in: the client receives the item registry and the actor identifiers once, while logging in. Already online players do not see later registrations. ItemTypeDictionaryisfinaland has no mutator, whileTypeConverterandItemTranslatorshare one instance.addToItemTypeDictionary()therefore calls the public constructor of that instance again with the extended entry list. No reflection is used. If the server ever makes those propertiesreadonly, this throws anErrorinstead of failing silently.
๐งช Development
composer install --ignore-platform-req='ext-*' composer test
๐ License
Distributed under the LGPL-3.0 License. See LICENSE for more information.