neoforged / NeoForge

Neo Modding API for Minecraft, based on Forge
https://projects.neoforged.net/neoforged/neoforge
Other
1.2k stars 177 forks source link

Add asItemStack variants to DeferredItem #490

Closed Tslat closed 8 months ago

Tslat commented 9 months ago

Pretty quick and easy

ItemStack's constructors has both ItemLike and Holder<? extends Item> signatures, meaning that passing a DeferredItem into an ItemStack errors at compiletime as javac can't work out which constructor to use.

To rectify this, I propose adding two new methods to DeferredItem and DeferredBlock:

/**
 * Creates a new {@link ItemStack} with a default size of 1 from this {@link Item}
 */
public ItemStack asItemStack() {
    return asItemStack(1);
}

/**
 * Creates a new {@link ItemStack} with the given size from this {@link Item}
 * 
 * @param count The size of the stack to create
 */
public ItemStack asItemStack(int count) {
    return new ItemStack(asItem(), count);
}
PlatinPython commented 9 months ago

I would prefer if those methods used Item#getDefaultInstance. My particular case is that I always have some NBT data that should attached.