Skip to content

Conversation

@KanekiOnMC
Copy link

After someone updated Customies, they forgot to create the id when the Closure is called in registerItem()

After someone updated Customies, they forgot to create the id when the Closure is called in registerItem()
@HydroGames-dev
Copy link

HydroGames-dev commented Nov 16, 2025

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");
      }
 }

@DavyCraft648
Copy link
Contributor

DavyCraft648 commented Nov 16, 2025

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.

@HydroGames-dev
Copy link

HydroGames-dev commented Nov 16, 2025

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");
}

@DavyCraft648
Copy link
Contributor

No, I'm not criticizing this change, just commenting on the 2 solution codes you provided

@KanekiOnMC
Copy link
Author

KanekiOnMC commented Nov 19, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants