Skip to main content

Item and Ingredient

When making recipes you can specify items in many ways, the most common is just to use 'namspace:id', like 'minecraft:diamond', however you can also use Item#of and Ingredient#of for advanced additions, such as NBT or count.

Note that Item and Ingredient are not the same! They may work similarly but there are differences. Item can only ever represent a single item type whereas Ingredient can represent multiple item types (and multiple instances of the same item type with different properties such as NBT data). For most cases Ingredient should be preferred over Item.

Item/ItemWrapper

Its Java class name is ItemWrapper but it is bound to Item in JS.

Name

Return Type Info
of(ItemStackJS in) ItemStackJS

Returns an ItemStackJS based on what was input. 

Note that this relies mostly on Rhinos type wrapping to function, see paragraph below about ItemStackJS#of for more info

of(ItemStackJS in, int count) ItemStackJS

See above. count will override any other count set from the first parameter.

of(ItemStackJS in, CompoundTag tag) ItemStackJS

See above. nbt is merged, with the input nbt taking priority over existing nbt.

of(ItemStackJS in, int count, CompoundTag nbt) ItemStackJS

Combines the functionality of the above two.

withNBT(ItemStackJS in, CompoundTag nbt) ItemStackJS

Same as the corresponding #of.

withChance(ItemStackJS in, double chance) ItemStackJS

Same as #of, chance will override currently set chance.

getList() ListJS

Returns a list of ItemStackJS, one per registered item.

getTypeList() ListJS

Returns a list of String, one per registered item.

getEmpty() ItemStackJS

Returns ItemSTackJS.EMPTY

clearListCache() void

Clears the caches used for #getList and #getTypeList 

fireworks(Map<String, Object> properties) FireworkJS

Returns a FireworkJS based on the input map of propeties. See FireworkJS#of on the FireworkJS page for more information <TODO: Make and link FireworkJS page>

getItem(ResourceLocation id) Item

Returns the instance of the Item class associated with the item id passed in.

@Nullable findGroup(String id) CreativeModTab

Returns the Creative tab associated with the id passed in, returns null if none found.

exists(ResourceLocation id) boolean

Returns if the item id passed in exists or not.

isItem(@Nullable Object o) boolean

Just does an instanceof ItemStackJS check on the object passed in.

Item#of relies on Rhinos type wrapping to function, which calls ItemStackJS#of. This tries its best to turn the input into an ItemStackJS. If no match is found ItemStackJS.EMPTY is returned. Valid inputs:

  • null/ItemStack.EMPTY/Items.EMPTY/ItemStackJS.EMPTY - will return ItemStackJS.EMPTY
  • ItemStackJS will return the same object passed in.
  • FluidStackJS - will return a new DummyFluidItemStackJS 
  • IngredientJS - will return the first item in the Ingredient
  • ItemStack - Will return a new ItemStackJS wrapping the ItemStack passed in
  • ResourceLocation  - Will lookup this ResourceLocation in the item registry and return it if found. If not found will return ItemStackJS.EMPTY, and throw an error if RecipeJS.itemErrors is true
  • ItemLike - Will return a new ItemStackJS of the input
  • JsonObject - Will return an item based on properties in the Json. item will be used as the item id, or tag if item does not exist. count, chance and nbt all set their respective properties
  • RegEx - Will return a new ItemStackJS of the first item id that matches this regex.
  • String (CharSequence) - Will parse it and return a new ItemStackJS based on the input item id. Prefix with nx  to change the count (where n is any number between 1 and 64). Put # before the item id to parse it as a tag instead. Put @ before the item id to parse it as a modid instead. Prefix with % to parse it as a creative menu tab group. Surround in / to parse as a RegEx. NOTE: will only be the first item in any of the groups mentioned above!
  • Map/JS Object - Uses the same rules as a JsonObject.

 

Remember that Item and Ingredient are not equivalent!