[Solved] Custom Itemstack - Using mod's items as itemstacks

I’ve been scanning through the Sponge API trying to find methods that allows me to make Itemstacks from item id names. I know I heard from somewhere that sponge will not depend on item ID numbers anymore. By any chance, is there any methods to allow us to make custom itemstacks from item id names? Thanks!

Okay. Disregard this. I just figured it out… Sorry -.-

I’ll mark this as solved - would you mind posting your solution, for future readers?

Yeah I can do that!

game.getRegistry().getItemBuilder().itemType(game.getRegistry().getType(ItemType.class, itemIDName).get()).build()

game = Sponge.getGame()

itemIDName <- Item ID name


It’s always good to post your solution for others who may have the same issue!


For reference, is itemName something along the lines of “minecraft:grass” or “mod-name:mod-item”? Does this allow referencing mod items as well? I feel like you wouldn’t be able to. Just a question.

Thanks for the solution!

1 Like

Based on the mod’s registration of it; though typically, its forgemodid:moditemid. IDs prefixed with “minecraft:” belong to the base game.

1 Like

So this DOES extend to the Forge API item database? Just clarifying this. It could be cool to have plugins that use items as “game start’s” or menu’s utilize some custom item’s handled by forge. Just a thought :smile:

In theory, yes.

1 Like

I’m just curious because we’re using a Sponge ItemType class, right? So where is the connection to Forge? Just the string? I’m going to search through the docs.

Personally, i think that would be a fantastic idea.

The forge implementation of Sponge is a coremod. Its able to access anything forge allows it to; the connection is moreso to the mod, not necessarily forge. Upon finding the item based on the ID you give it, implementation will probably build a new ItemType class based on that item to give to you.


Oh okay, thanks for the info!