Patching a little error that has been forgotten#161
Patching a little error that has been forgotten#161KanekiOnMC wants to merge 1 commit intoCustomiesDevs:masterfrom
Conversation
After someone updated Customies, they forgot to create the id when the Closure is called in registerItem()
|
Developers can just use the new id system in their code https://github.com/Amblydia/Customies/wiki CustomiesItemFactory::getInstance()->registerItem(static fn() => new CustomItem(ItemTypeIds::newId()), "customies:custom_item");
class CustomItem extends Item implements ItemComponents{
use ItemComponentsTrait;
public function __construct(ItemIdentifier $identifier){
parent::__construct($identifier, "Custom item");
}
}
// or
CustomiesItemFactory::getInstance()->registerItem(static fn() => new CustomItem(), "customies:custom_item");
class CustomItem extends Item implements ItemComponents{
use ItemComponentsTrait;
public function __construct(){
parent::__construct(new ItemIdentifier(ItemTypeIds::newId()), "Custom item");
}
} |
|
I disagree with both code approaches. It would be better to store the ID value outside of the item function, like this example: $id = ItemTypeIds::newId();
CustomiesItemFactory::getInstance()->registerItem(static fn() => new CustomItem(new ItemIdentifier($id)), "customies:custom_item");The purpose of this change is to allow plugin developers to easily keep track of their own registered type IDs. This change was first implemented for custom block registration and then subsequently applied to custom items. |
|
You can still do that $id = ItemTypeIds::newId();
CustomiesItemFactory::getInstance()->registerItem(static fn() => new CustomItem($id), "customies:custom_item");
// Item Class
public function __construct(ItemIdentifier $identifier){
parent::__construct($identifier, "Custom item");
} |
|
No, I'm not criticizing this change, just commenting on the 2 solution codes you provided |
Sorry mate, they just didn't updated the wiki, so mb, I didn't think through it |
After someone updated Customies, they forgot to create the id when the Closure is called in registerItem()