Namespace: Item

Item

Static methods for the Item API.

Methods

staticItem.addCraftRecipe(id, quantity, damage, ingredients)

Add a new crafting recipe.

Name Type Description
id int

the id of the item to make

quantity int

the quantity of items to produce

damage int

the damage value of the new item

ingredients Array.<int>

the items required to complete the recipe (max 9) as an array: [id1, qty1, dmg1, id2, qty2, dmg2, ...]

Example
// make a diamond sword from 1 coal [263, 1, 0] and 3 torches [50, 3, 0]
var ingredients = [
  263, 1, 0,
  50, 3, 0
];
Item.addCraftRecipe(276, 1, 0, ingredients);

staticItem.addFurnaceRecipe(id, damage, source)

Add a new smelting recipe.

Name Type Description
id int

the id of the item to make

damage int

the damage value of the new item

source int

the source ingredient

Example
// make a diamond sword from a stick
Item.addFurnaceRecipe(276, 0, 280);

staticItem.addShapedRecipe(id, quantity, damage, keys, ingredients)

Add a new smelting recipe.

Name Type Description
id int

the id of the item to make

quantity int

the quantity of items to produce

damage int

the damage value of the new item

keys Array.<string>

the layout of the ingredient keys

ingredients Array.<(string|int)>

the ingredients

Example

Credit: Zhuowei Zhang

// make an enchantment table
var ENCHANTMENT_TABLE_ID = 240;
var currentWorkbenchX;
var currentWorkbenchY;
var currentWorkbenchZ;

// define the table block with the textures in the following order:
// bottom, top, south, north, west, east
// in this case, the side textures are the same, and the top/bottom
// textures are different.
Block.defineBlock(ENCHANTMENT_TABLE_ID, "Enchantment Table", [
  ["enchanting_table_bottom" , 0],
  ["enchanting_table_top"    , 0],
  ["enchanting_table_side"   , 0],
  ["enchanting_table_side"   , 0],
  ["enchanting_table_side"   , 0],
  ["enchanting_table_side"   , 0]
]);
Block.setShape(ENCHANTMENT_TABLE_ID, 0, 0, 0, 1, 3/4, 1);
Block.setDestroyTime(ENCHANTMENT_TABLE_ID, 1);

// add the shaped recipe to build the table
Item.addShapedRecipe(
  // the item we're making
  ENCHANTMENT_TABLE_ID, 1, 0,
  // the keys in the shape of the recipe
  [
    " b ",
    "dod",
    "ooo"
  ],
  // specify what each character represents.
  // b = book, d = diamond, o = obsidian
  [
    "b", 340, 0,
    "d", 264, 0,
    "o", 49, 0
  ]
);

staticItem.defineArmor(id, iconName, iconIndex, name, texture, damageReduce, maxDamage, type)

Define custom armor.

Name Type Description
id int

the new, unique item id (see: Item IDs)

iconName string

the name of the icon to use for this item

iconIndex int

the index of the icon to use for this item

name string

the name of the new armor item

texture string

the texture to use for this item

damageReduce int

how much damage is taken when hit

maxDamage int

the maximum amount of damage the item can sustain

type int

the type of armor this item is

Example

Credit: Zhuowei Zhang

// WOOT! Zombie armor!
Item.defineArmor(410 , "empty_armor_slot_helmet"     , 0 , "Zombie mask"  , "mob/zombie.png" , 1 , 10 , ArmorType.helmet);
Item.defineArmor(411 , "empty_armor_slot_chestplate" , 0 , "Zombie shirt" , "mob/zombie.png" , 1 , 10 , ArmorType.chestplate);
Item.defineArmor(412 , "empty_armor_slot_leggings"   , 0 , "Zombie pants" , "mob/zombie.png" , 1 , 10 , ArmorType.leggings);
Item.defineArmor(413 , "empty_armor_slot_boots"      , 0 , "Zombie shoes" , "mob/zombie.png" , 1 , 10 , ArmorType.boots);
function procCmd(cmd) {
  if (cmd == "zombiegear") {
    addItemInventory(411, 1);
    addItemInventory(412, 1);
    addItemInventory(413, 1);
    addItemInventory(414, 1);
  }
}

staticItem.getName(id, data, raw){string}

Return the name of an item.

Name Type Default Description
id int

the item id

data int null optional

additional data to describe item such as damage or sub-item

raw boolean false optional

if the returned data should be in the raw form

Returns:
Type Description
string
  • the item name
Example
// get data in raw form
clientMessage(Item.getName(263, 0, true)); // prints "item.coal.name"
// get data in normal form
clientMessage(Item.getName(263, 0, false)); // prints "Coal"
clientMessage(Item.getName(263, 1));        // prints "Charcoal" (item 263:1)

staticItem.isValidItem(id){boolean}

Determine if an item is valid.

Name Type Description
id int

the item id

Returns:
Type Description
boolean
  • true if the item is valid, false otherwise
Example
// see if coal is a valid item
if (Item.isValidItem(263)) {
  clientMessage("Yay, let's make torches!");
}

staticItem.setCategory(id, category)

Set the category for an item which will determine where it appears in the crafting table interface, as well as how it can be used (e.g., food can be eaten).

Name Type Description
id int

the id of the item to change

category int

the new category the item will be assigned to

Example
// coal can be food, right?
Item.setCategory(263, ItemCategory.FOOD);

staticItem.setHandEquipped(id, isHandEquipped)

Set an item to render as a tool.

Name Type Description
id int

the item id

isHandEquipped boolean

whether or not the item should be set as hand equipped

Example
// make custom item hand equipable
var MY_CUSTOM_ITEM_ID = 220;
Item.setHandEquipped(MY_CUSTOM_ITEM_ID, true);

staticItem.setMaxDamage(id, damage)

Set the amount of damage an item can sustain when used (i.e., the number of times it can be used before it breaks).

Name Type Description
id int

the item id

damage int

the maximum damage

Example
// who says wooden pick axes are useless?
Item.setMaxDamage(270, 10000);

staticItem.setProperties(id, properties)

Set custom propertires for an item using the same format as found in the items.json file.

Name Type Description
id int

the item ID

properties Object

an object literal describing the new properties

Example

Credit: Zhuowei Zhang

// make zombie shoes edible
Item.defineArmor(4014, "empty_armor_slot_boots", 0, "Zombie shoes", "mob/zombie.png", 1, 10, ArmorType.boots);
Item.setCategory(4014, ItemCategory.FOOD);
Player.addItemCreativeInv(4014, 1, 0);

var shoesNutrition = 4;

// anything that can be specified in items.json can be specified here
Item.setProperties(4014, {
  "use_animation": "eat",
  "use_duration": 32,
  "food": {
    "nutrition": shoesNutrition,
    "saturation_modifier": "low",
    "is_meat": false
  }
});