Give a modded item in inventory


#1

Hi,
I search how we can give easily a modded item in player’s inventory. I use flan’s mod and i want to give some weapons to player.
I found that for give vanilla items players.getInventory().offer(ItemStack.of(Sponge.getGame().getRegistry().getType(ItemType.class, "stone").get(), 1));

Thank’s.


#2

For modded items its the same. Only you need to have the modded items id instead of stone


#3

Like players.getInventory().offer(ItemStack.of(Sponge.getGame().getRegistry().getType(ItemType.class, "flansmod:m16a4").get(), 1)); ?
I tested, it does’nt work


#4

What happens instead? An error? Please post the whole server log to a pastebin-like website.


#5

Sorry, I just looked at the toolbar, not in the entire inventory. That’s work thank you! How place this item in a specified position please ?


#6
inventory.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(index))).first().set(itemStack);

Or with SlotPos (untested code):

GridInventory gridInv = ((MainPlayerInventory) inventory.query(MainPlayerInventory.class)).getGrid()
gridInv.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotPos.of(x, y))).first().set(itemStack);