Patching a little error that has been forgotten
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 hardcoded in their own item class
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.
The issue is that the resulting registered item ID could potentially be inconsistent across different threads calling ItemTypeIds::newId() if the registration sequence is not strictly synchronized (which should ideally be prevented).
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
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