Перейти к основному содержанию

Item

Module used to define items and their properties.

Index

Interfaces

ArmorParams

ArmorParams:

Object used in Item.createArmorItem method to specify general armor item parameters.

optionalarmor

armor?: number = 0

Armor protection.

optionaldurability

durability?: number = 1

Armor durability, the more it is, the more hits the armor will resist.

optionalisTech

isTech?: boolean = false

If true, the item will not be added to creative.

optionalknockbackResist

knockbackResist?: number = 0

Knockback resistance, that the player will have when wearing the following armor. It must be value from 0 (no knockback resistance) to 1 (full knockback resistance).

optionaltexture

texture?: string = “textures/logo.png”

Relative path to the armor model texture from the mod assets directory.

type

type: ArmorType

Armor type, should be one of the helmet, chestplate, leggings or boots.

FoodParams

FoodParams:

Object used in Item.createFoodItem method to specify general food item parameters.

optionalcategory

category?: number
@since

2.2.0b76

optionalfood

food?: number = 1 // 0.5 hunger unit

Amount of hunger restored by this food in halfs.

optionalisTech

isTech?: boolean = false

If true, the item will not be added to creative.

optionalstack

stack?: number = 64

Maximum item in stack size.

ItemLegacyPrototype

ItemLegacyPrototype:

Once upon a time, a new way of registering items, however, in current state, either does not work or is undesirable to use. *

@deprecated

optionalgetArmorFuncs

getArmorFuncs?: (item: null) => IArmorJSCallback

Type declaration

optionalgetCategory

getCategory?: (item: null) => number

Type declaration

    • (item: null): number
    • Parameters

      • item: null

      Returns number

optionalgetDefineParams

getDefineParams?: (item: null) => ItemParams | FoodParams | ArmorParams

Type declaration

optionalgetEnchant

getEnchant?: (item: null) => number

Type declaration

    • (item: null): number
    • Parameters

      • item: null

      Returns number

optionalgetMaxDamage

getMaxDamage?: (item: null) => number

Type declaration

    • (item: null): number
    • Parameters

      • item: null

      Returns number

optionalgetMaxUseDuration

getMaxUseDuration?: (item: null) => number

Type declaration

    • (item: null): number
    • Parameters

      • item: null

      Returns number

getName

getName: (item: null) => string

Type declaration

    • (item: null): string
    • Parameters

      • item: null

      Returns string

optionalgetProperties

getProperties?: (item: null) => object

Cannot be used, because of properties should be passed as string, but properties here internally depends on object.


Type declaration

    • (item: null): object
    • Parameters

      • item: null

      Returns object

getTexture

getTexture: (item: null) => TextureData

Type declaration

optionalgetToolMaterial

getToolMaterial?: (item: null) => string | ToolMaterial

Type declaration

optionalgetToolPrototype

getToolPrototype?: (item: null) => ToolParams

Type declaration

optionalgetToolTarget

getToolTarget?: (item: null) => string[]

Type declaration

    • (item: null): string[]
    • Parameters

      • item: null

      Returns string[]

optionalgetUseAnimation

getUseAnimation?: (item: null) => number

Type declaration

    • (item: null): number
    • Parameters

      • item: null

      Returns number

optionalinit

init?: () => void

Type declaration

    • (): void
    • Returns void

optionalisEnchanted

isEnchanted?: (item: null) => boolean

Type declaration

    • (item: null): boolean
    • Parameters

      • item: null

      Returns boolean

optionalisStackedByData

isStackedByData?: (item: null) => boolean

Type declaration

    • (item: null): boolean
    • Parameters

      • item: null

      Returns boolean

optionalisToolRender

isToolRender?: (item: null) => boolean

Type declaration

    • (item: null): boolean
    • Parameters

      • item: null

      Returns boolean

optionalonThrowableImpact

onThrowableImpact?: (projectile: number, item: ItemInstance, target: ProjectileHitTarget) => void

Type declaration

optionalonTick

onTick?: (item: null) => void

Unused at all.


Type declaration

    • (item: null): void
    • Parameters

      • item: null

      Returns void

optionalonUsed

onUsed?: (coords: Vector, item: ItemInstance, block: Tile) => void

Type declaration

type

type: createItem | createFoodItem | createArmorItem | createThrowableItem

ItemParams

ItemParams:

Object used in Item.createItem and Item.createThrowableItem methods to specify general item parameters.

optionalcategory

category?: number
@since

2.2.0b76

optionalisTech

isTech?: boolean = false

If true, the item will not be added to creative.

optionalstack

stack?: number = 64

Maximum item in stack size.

NativeItem

NativeItem:

Class representing item used to set it's properties.

addRepairItem

  • addRepairItem(id: number): void
  • Parameters

    • id: number

    Returns void

addRepairItems

  • addRepairItems(id: number[]): void
  • Parameters

    • id: number[]

    Returns void

setAllowedInOffhand

  • setAllowedInOffhand(allowed: boolean): void
  • Parameters

    • allowed: boolean

    Returns void

setArmorDamageable

  • setArmorDamageable(damageable: boolean): void
  • Parameters

    • damageable: boolean

    Returns void

setCreativeCategory

  • setCreativeCategory(category: number): void
  • Parameters

    • category: number

    Returns void

setEnchantType

  • setEnchantType(type: number): void
  • setEnchantType(enchant: number, value: number): void
  • Parameters

    • type: number

    Returns void

setEnchantability

  • setEnchantability(enchant: number, value: number): void
  • Parameters

    • enchant: number
    • value: number

    Returns void

setGlint

  • setGlint(glint: boolean): void
  • Parameters

    • glint: boolean

    Returns void

setHandEquipped

  • setHandEquipped(equipped: boolean): void
  • Parameters

    • equipped: boolean

    Returns void

setLiquidClip

  • setLiquidClip(clip: boolean): void
  • Parameters

    • clip: boolean

    Returns void

setMaxDamage

  • setMaxDamage(maxDamage: number): void
  • Parameters

    • maxDamage: number

    Returns void

setMaxStackSize

  • setMaxStackSize(maxStack: number): void
  • Parameters

    • maxStack: number

    Returns void

setMaxUseDuration

  • setMaxUseDuration(duration: number): void
  • Parameters

    • duration: number

    Returns void

setProperties

  • setProperties(props: string): void
  • Parameters

    • props: string

    Returns void

setStackedByData

  • setStackedByData(stacked: boolean): void
  • Parameters

    • stacked: boolean

    Returns void

setUseAnimation

  • setUseAnimation(animation: number): void
  • Parameters

    • animation: number

    Returns void

TextureData

TextureData:

Represents item texture data. For example, if /items-opaque folder contains file nugget_iron_0.png, you should pass "nugget_iron" as texture name and 0 as texture index. _N suffix can be omitted, but it is generally not recommended.

optionaldata

data?: number = 0

Texture index defined by _N texture suffix.

optionalmeta

meta?: number
@deprecated

Same as data, so data is preferred in all cases.

name

name: string

Texture name, name of the file stored in the /items-opaque asset folder without extension and _N suffixes.

Variables

consticonOverrideFunctions
internal

iconOverrideFunctions: {}

All items icon override functions object.


Type declaration

constnameOverrideFunctions
internal

nameOverrideFunctions: {}

All items name override functions object.


Type declaration

Functions

addCreativeGroup

  • addCreativeGroup(name: string, displayedName: string, ids: number[]): void
  • Creates group of creative items.


    Parameters

    • name: string

      name of group

    • displayedName: string

      name of group in game

    • ids: number[]

      array of items in group

    Returns void

addRepairItemIds

  • addRepairItemIds(id: string | number, items: number[]): void
  • Specifies what items can be used to repair this item in the anvil.


    Parameters

    • id: string | number

      string or numeric item ID

    • items: number[]

      array of numeric item IDs to be used as repair items

    Returns void

addToCreative

  • addToCreative(id: string | number, count: number, data: number, extra?: ItemExtraData): void
  • Adds item to creative inventory.


    Parameters

    • id: string | number

      string or numeric item ID

    • count: number

      amount of the item to be added, generally should be 1

    • data: number

      item data

    • optionalextra: ItemExtraData

    Returns void

createArmorItem

  • Creates armor item using specified parameters.


    Parameters

    • nameID: string

      string ID of the item; you should register it via IDRegistry.genItemID call first

    • name: string

      item name in English; add translations to the name using Translation module, all translation to the item and block names are applied automatically

    • texture: TextureData

      texture data used to create item

    • params: ArmorParams

      general armor item parameters object, the armor type there is required

    Returns NativeItem

createFoodItem

  • Creates eatable item using specified parameters.


    Parameters

    • nameID: string

      string ID of the item. You should register it via IDRegistry.genItemID call first

    • name: string

      item name in English; add translations to the name using Translation module, all translation to the item and block names are applied automatically

    • texture: TextureData

      texture data used to create item

    • optionalparams: FoodParams

      additional item parameters

    Returns NativeItem

createFuelItem

createItem

  • Creates new item using specified parameters.


    Parameters

    • nameID: string

      string ID of the item; you should register it via IDRegistry.genItemID call first

    • name: string

      item name in English; add translations to the name using Translation module, all translation to the item and block names are applied automatically

    • texture: TextureData

      texture data used to create item

    • optionalparams: ItemParams

      additional item parameters

    Returns NativeItem

createThrowableItem

  • Creates throwable item using specified parameters.


    Parameters

    • nameID: string

      string ID of the item; you should register it via IDRegistry.genItemID call first

    • name: string

      item name in English; add translations to the name using Translation module, all translation to the item and block names are applied automatically

    • texture: TextureData

      texture data used to create item

    • optionalparams: ItemParams

      additional item parameters

    Returns NativeItem

describeItem

  • describeItem(numericID: number, description: object): void
  • Applies several properties via one method call.

    @deprecated

    Consider using appropriate setters instead.


    Parameters

    • numericID: number

      numeric item ID

    • description: object

    Returns void

getArmorValue

  • getArmorValue(id: number): number
  • Natural armor points, that also is displayed above hotbar.

    @since

    2.4.0b119


    Parameters

    • id: number

      numeric item ID

    Returns number

    Natural armor half points.

getItemById

  • Gets NativeItem instance that can be used to apply some properties to the item.


    Parameters

    • id: string

      string ID of the item

    Returns NativeItem

    NativeItem instance associated with this item.

getMaxDamage

  • getMaxDamage(id: number): number

  • Parameters

    • id: number

      numeric item ID

    Returns number

    Maximum damage value for the specified item.

getMaxStack

  • getMaxStack(id: number): number
  • getMaxStack(id: number, data: number): number
  • @deprecated

    Use same function with data parameter.


    Parameters

    • id: number

      numeric item ID

    Returns number

    Maximum stack size for the specified item.

getName

  • getName(id: number, data: number): string
  • getName(id: number, data: number, encode: any): string

  • Parameters

    • id: number

      numeric item ID

    • data: number

      item data

    Returns string

    Current item name.

getNumericId

  • getNumericId(id: string | number): number

  • Parameters

    • id: string | number

      string ID of the item

    Returns number

    Item numeric ID by it's string ID or just returns it's numeric ID if input was a numeric ID.

invokeItemUseNoTarget

  • invokeItemUseNoTarget(item: ItemInstance, noModCallback: boolean): void
  • internal

    Invoke click on the block in world without target.


    Parameters

    • item: ItemInstance

      item which used on the block

    • noModCallback: boolean

      if true, mod ItemUse callback will be not executed

    Returns void

invokeItemUseOn

  • internal

    Invoke click on the block in world.


    Parameters

    • coords: ItemUseCoordinates

      coords of click on the block

    • item: ItemInstance

      item which used on the block

    • noModCallback: boolean

      if true, mod ItemUse callback will be not executed

    • entity: number

      player which clicked on the block

    Returns void

isNativeItem

  • isNativeItem(id: number): boolean

  • Parameters

    • id: number

      numeric item ID

    Returns boolean

    true if given item is vanilla item, false otherwise.

isValid

  • isValid(id: number): boolean
  • isValid(id: number, data: number): boolean
  • @since

    2.2.1b94 (not worked before)


    Parameters

    • id: number

      numeric item ID

    Returns boolean

    true, if an item with such ID exists, false otherwise.

registerDispenseFunction

  • Registers function to be called when item is dispensed from dispenser.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • func: ItemDispensedFunction

      function that is called when such an event occurs

    Returns void

registerIconOverrideFunction

  • Registers item ID as requiring item icon override and registers function to perform such an override.


    Parameters

    Returns void

registerNameOverrideFunction

  • Registers function to perform item name override.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • func: ItemNameOverrideFunction

      function that is called to override item name. Should return string to be used as new item name

    Returns void

registerNoTargetUseFunction

  • Registers function to be called when player uses item in the air (not on the block).


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • func: ItemUseNoTargetFunction

      function that is called when such an event occurs

    Returns void

registerThrowableFunction

  • Registers function that is called when throwable item with specified ID hits block or entity.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • useFunc: ProjectileHitFunction

      function that is called when such an event occurs

    Returns void

registerThrowableFunctionForID

registerUseFunction

  • registerUseFunction(nameID: string | number, useFunc: ItemUseFunction): void
  • Registers function that is called when user touches some block in the world with specified item.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • useFunc: ItemUseFunction

      function that is called when such an event occurs

    Returns void

registerUseFunctionForID

  • registerUseFunctionForID(numericID: number, useFunc: ItemUseFunction): void

registerUsingCompleteFunction

  • Registers function to be called when player completes using item that has maximum use time set with Item.setMaxUseDuration function.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • func: ItemUsingCompleteFunction

      function that is called when such an event occurs

    Returns void

registerUsingReleasedFunction

  • Registers function to be called when player doesn't complete using item that has maximum use time set with Item.setMaxUseDuration function. Vanilla bow uses this function with max use duration of 72000 ticks.


    Parameters

    • nameID: string | number

      string or numeric ID of the item

    • func: ItemUsingReleasedFunction

      function that is called when such an event occurs

    Returns void

setAllowedInOffhand

  • setAllowedInOffhand(id: string | number, allowed: boolean): void
  • Allows item to be put in offhand slot.

    @since

    2.0.4b35


    Parameters

    • id: string | number

      string or numeric item ID

    • allowed: boolean

    Returns void

setArmorDamageable

  • setArmorDamageable(damageable: boolean): void
  • Parameters

    • damageable: boolean

    Returns void

setCategory

  • setCategory(id: string | number, category: number): void
  • Sets item creative category.


    Parameters

    • id: string | number

      string or numeric item ID

    • category: number

      item category, should be one of the EItemCategory values

    Returns void

setEnchantType

  • setEnchantType(id: string | number, enchant: number, value: number): void
  • Specifies how the item can be enchanted.


    Parameters

    • id: string | number

      string or numeric item ID

    • enchant: number

      enchant type defining when enchants can or cannot be applied to this item, one of the EEnchantType

    • value: number

      quality of the enchants that are applied, the higher this value is, the better enchants you get with the same level

    Returns void

setExplodable

  • setExplodable(id: string | number, explodable: boolean): void
  • @since

    2.4.0b119


    Parameters

    • id: string | number
    • explodable: boolean

    Returns void

setFireResistant

  • setFireResistant(id: string | number, resistant: boolean): void
  • @since

    2.4.0b119


    Parameters

    • id: string | number
    • resistant: boolean

    Returns void

setGlint

  • setGlint(id: string | number, enabled: boolean): void
  • Sets item as glint (like enchanted tools or golden apple).


    Parameters

    • id: string | number

      string or numeric item ID

    • enabled: boolean

      if true, the item will be displayed as glint item

    Returns void

setLiquidClip

  • setLiquidClip(id: string | number, enabled: boolean): void
  • Allows to click with item on liquid blocks.


    Parameters

    • id: string | number

      string or numeric item ID

    • enabled: boolean

      if true, liquid blocks can be selected on click

    Returns void

setMaxDamage

  • setMaxDamage(id: string | number, maxdamage: number): void
  • Sets item maximum data value.


    Parameters

    • id: string | number

      string or numeric item ID

    • maxdamage: number

      maximum data value for the item

    Returns void

setMaxUseDuration

  • setMaxUseDuration(id: string | number, duration: number): void
  • Limits maximum use duration. This is useful to create such items as bows.


    Parameters

    • id: string | number

      string or numeric item ID

    • duration: number

      maximum use duration in ticks

    Returns void

setProperties

  • setProperties(id: string | number, props: string): void
  • Sets additional properties for the item, uses Minecraft mechanisms to set them. Full list of properties is currently unavailable.


    Parameters

    • id: string | number

      string or numeric item ID

    • props: string

      JSON string containing some of the properties

    Returns void

setPrototype

  • @deprecated

    Should not be used in new mods, consider using Item properties setters instead.


    Parameters

    Returns void

setShouldDespawn

  • setShouldDespawn(id: string | number, should: boolean): void
  • @since

    2.4.0b119


    Parameters

    • id: string | number
    • should: boolean

    Returns void

setStackedByData

  • setStackedByData(id: string | number, enabled: boolean): void
  • @deprecated

    No longer supported.


    Parameters

    • id: string | number
    • enabled: boolean

    Returns void

setToolRender

  • setToolRender(id: string | number, enabled: boolean): void
  • Specifies how the player should hold the item.


    Parameters

    • id: string | number

      string or numeric item ID

    • enabled: boolean

      if true, player holds the item as a tool, not as a simple item

    Returns void

setUseAnimation

  • setUseAnimation(id: string | number, animType: number): void
  • Sets animation type for the item.


    Parameters

    • id: string | number

      string or numeric item ID

    • animType: number

      use animation type, one of the EItemAnimation values

    Returns void