Hey, i have a new class named CItem.php And i want to extend Item.php so i have CItem.php functions I know you can do that with player class through $event->setPlayerClass(CPlayer::class); But anyway with Items?
There's a large difference between PlayerCreationEvent and the ItemFactory class. As far as I know, when the server starts, the items are instantiated via the ItemFactory class at once, which means that every time that you use the function ItemFactory::get, or Item::get, an item that is already instantiated is being returned. In contrast, however, the Player class is not instantiated when the server starts, so, from my knowledge, you'd have to override that functions by the means of modifications. However, I do not know everything, so I may be wrong. Hope this helps
if you want to override already existing function in item.php, it's not possible because pocketmine is mostly calling all functions and constants directly from Item.php
It isn't possible and there probably will never be a way to register a custom item class but you can create a masking class using reflections. PHP: class ItemMask{ public function __construct(Item $item){ $this->item = $item; } public function setId(int $id) : void{ $property = new \ReflectionProperty(Item::class, "id"); $property->setAccessible(true); $property->setValue($this->item, $id); }}/** @var Item $item */$mask = new ItemMask($item);$mask->setId(Item::BEDROCK);var_dump($item->getId());//Item::BEDROCK P.S. Changing an item's ID may cause unexpected behaviour because you aren't changing the Item class, just the item "graphic". This is just a demonstration.
mind showing more usecases? you can say set only certain item as custom item, not all tho so you would need to reregister all item clases and inject the methods
not me i think you should go with a mask or just dont use item class but pass that as an arg to some class
I guess thats the only way then. I think they should add a method to override the class just like player class