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

ToolAPI

Module used to manage block and tools material and create tools with all required properties.

Index

Interfaces

BlockData

BlockData:

Object used to store all of the ToolAPI block data.

readonlyisNative

isNative: boolean

Specifies whether the block was added as vanilla item or as a custom block. true, if the block is vanilla, false if the block is custom. Should not generally be changed.

level

level: number

Digging level of the block. If digging level of tool is higher then block's one, the block is dropped.

material

material: BlockMaterial

Material data used for this block.

BlockMaterial

BlockMaterial:

Object used to describe block material.

multiplier

multiplier: number

Multiplier used to calculate block breaking speed.

name

name: string

Block material name.

EnchantData

EnchantData:

Object containing some of the enchants that are used to calculate block destroy time.

all

all: {}
@since

2.2.1b106


Type declaration

  • [id number]: number

efficiency

efficiency: number

Specifies the level of Efficiency enchantment, or 0 if the item doesn't have this enchant.

experience

experience: number

Specifies the amount of additional experience that is dropped when player breaks block with specified item.

fortune

fortune: number

Specifies the level of Fortune enchantment, or 0 if the item doesn't have this enchant.

silk

silk: boolean

If true, the item has Silk Touch enchantment.

unbreaking

unbreaking: number

Specifies the level of Unbreaking enchantment, or 0 if the item doesn't have this enchant.

ToolMaterial

ToolMaterial:

Object used to describe tool material type.

optionaldamage

damage?: number

Additional damage for the instruments, this value is added to the base tool damage. If damage is not integer, it is rounded to the higher integer with the chance of the fractional part, e.g. if the value is 3.3, the damage will be 4 with the chance of 30%.

optionaldurability

durability?: number

Durability of the tool, 33 is a default value for golden tools and 1562 is a default value for diamond tools.

optionalefficiency

efficiency?: number

Divider used to calculate block breaking speed. 2 is a default value for wooden instruments and 12 is a default value for golden instruments.

optionallevel

level?: number

Block breaking level, 1 is wooden instruments, 4 is diamond instruments. If block's breaking level is less or equal to the tool's level, block will be dropped when broken.

ToolParams

ToolParams:

Object containing additional parameters and functions used by Core Engine to work with the tool.

optionalblockMaterials

blockMaterials?: {}

List of block material names that can be broken by this instrument. Defined by ToolAPI.registerTool,


Type declaration

  • [key string]: boolean

optionalbrokenId

brokenId?: number = 0

Numeric ID of the item that replaces tool item when it's broken. By default the tool disappears.

optionalcalcDestroyTime

calcDestroyTime?: (tool: ItemInstance, coords: ItemUseCoordinates, block: Tile, timeData: { base: number; devider: number; modifier: number }, defaultTime: number, enchantData?: EnchantData) => number

Function used to recalculate block destroy time based on some custom logic.


Type declaration

    • Parameters

      • tool: ItemInstance

        Tool item.

      • coords: ItemUseCoordinates

        Coordinates where the block is being broken.

      • block: Tile

        Block that is being broken.

      • timeData: { base: number; devider: number; modifier: number }

        Some time properties that can be used to calculate destroy time for the tool and block.

        • base: number

          Base destroy time of the block.

        • devider: number

          Tool material devider.

        • modifier: number

          Divider applied due to efficiency enchantment.

      • defaultTime: number

        Default block destroy time, calculated as base / divider / modifier.

      • optionalenchantData: EnchantData

        Tool's enchant data.

      Returns number

optionaldamage

damage?: number = 0 // 4 in case of sword starting with 2.4.0b122o1

Base damage of the instrument, is added to the material damage to calculate the tool's final damage.

optionalisNative
internal

isNative?: boolean

If true, the tool is vanilla Minecraft tool. Generally used within Core Engine code and should not be used within mods until you really know what you're doing.

optionalisWeapon

isWeapon?: boolean

If true, breaking blocks with this tool makes it break 2x faster, otherwise attacking mobs breaks tool 2x faster.

optionalmodifyEnchant

modifyEnchant?: (enchantData: EnchantData, item: ItemInstance, coords?: ItemUseCoordinates, block?: Tile) => void

Function that is used to change enchant data object before all the calculations. Can be used to add some enchantment properties, such as silk touch, efficiency, unbreaking or fortune.


Type declaration

optionalonAttack

onAttack?: (item: ItemInstance, victim: number, attacker: number) => boolean

Function that is called when players attacks some entity with the tool.

@returns

true if default damage should not be applied to the instrument, false otherwise.


Type declaration

    • (item: ItemInstance, victim: number, attacker: number): boolean
    • Parameters

      • item: ItemInstance

        Tool item.

      • victim: number

        Unique numeric ID of the entity that is attacked.

      • attacker: number

        Entity UID of the player that attacked victim.

      Returns boolean

optionalonBroke

onBroke?: (item: ItemInstance) => boolean

Function that is called when the instrument is broken.

@returns

true if default breaking behavior (replacing by brokenId item) should not be applied.


Type declaration

optionalonDestroy

onDestroy?: (item: ItemInstance, coords: ItemUseCoordinates, block: Tile, player: number) => boolean

Function that is called when the block is destroyed.

@returns

true if default damage should not be applied to the instrument, false otherwise.


Type declaration

optionalonMineBlock

onMineBlock?: (coords: ItemUseCoordinates, carried: ItemInstance, fullTile: Tile, blockSource: BlockSource, player: number) => void

Function that is called when the block that has a destroy function is destroyed.


Type declaration

optionaltoolMaterial

toolMaterial?: ToolMaterial

Properties of the tool material. Defined by ToolAPI.registerTool,

Functions

addBlockMaterial

  • addBlockMaterial(name: string, breakingMultiplier: number): void
  • Creates new material with specified breaking speed multiplier. Some of the materials are already registered:

    stone - used for pickaxes

    wood - used for axes

    dirt - used for shovels

    plant - used for all plants (no vanilla tool supports this material)

    fibre - used for swords (to break web)

    cobweb - currently not used

    unbreaking - used for unbreaking blocks, liquids, end portal, etc.


    Parameters

    • name: string

      new (or existing) material name

    • breakingMultiplier: number

      multiplier used to calculate block breaking speed. 1 is a default value for dirt and 3 is a default value for stone

    Returns void

addToolMaterial

  • Creates new tool material with specified parameters. Some of the tool materials are already registered:

    wood - used for wooden instruments

    stone - used for stone instruments

    iron - used for iron instruments

    golden - used for golden instruments

    diamond - used for diamond instruments


    Parameters

    • name: string

      new (or existing) material name

    • material: ToolMaterial

      parameters describing material properties

    Returns void

dropExpOrbs

  • dropExpOrbs(x: number, y: number, z: number, value: number): void
  • Spawns experience orbs on the specified coordinate.


    Parameters

    • x: number
    • y: number
    • z: number
    • value: number

      amount of experience to spawn

    Returns void

dropOreExp

  • dropOreExp(coords: Vector, minVal: number, maxVal: number, modifier: number): void
  • Spawns random amount of experience on the specified block coordinates.


    Parameters

    • coords: Vector

      block coordinates

    • minVal: number

      minimum amount of orbs to be spawned

    • maxVal: number

      maximum amount of orbs to be spawned

    • modifier: number

      additional experiences, usually passed from ToolAPI.EnchantData.experience field

    Returns void

fortuneDropModifier

  • Applies fortune drop modifier to the drop array.


    Parameters

    • drop: ItemInstanceArray[]

      drop array containing number of the arrays

    • level: number

      enchantment level

    Returns ItemInstanceArray[]

getBlockData

  • getBlockData(blockID: number): BlockData | undefined

  • Parameters

    • blockID: number

      numeric tile ID

    Returns BlockData | undefined

    Object containing ToolAPI block data or undefined if no block data was specified for this block.

getBlockDestroyLevel

  • getBlockDestroyLevel(blockID: number): number

  • Parameters

    • blockID: number

      numeric tile ID

    Returns number

    Destroy level of the block with specified ID or 0, if no block data was specified for this block.

getBlockMaterial


  • Parameters

    • blockID: number

      numeric tile ID

    Returns Nullable<BlockMaterial>

    Object containing block material information or null, if no block data was specified for this block.

getBlockMaterialName

  • getBlockMaterialName(blockID: number): Nullable<string>
  • Parameters

    • blockID: number

      numeric tile ID

    Returns Nullable<string>

getCarriedToolData

  • getCarriedToolData(): any

  • Returns any

    Carried tool information stored in slightly modified ToolAPI.ToolParams object or null if no tool data was specified.

getCarriedToolLevel

  • getCarriedToolLevel(): number

  • Returns number

    Carried tool's breaking level or 0 if no tool data was provided.

getDestroyTimeViaTool

  • Calculates destroy time for the block that is being broken with specified tool at the specified coords. Used mostly by Core Engine to apply break. time


    Parameters

    • fullBlock: Tile
    • toolItem: ItemInstance
    • coords: ItemUseCoordinates
    • optionalignoreNative: boolean

      if block and item are native items, and this parameter is set to true, all the calculations will still be performed

    Returns number

getEnchantExtraData


  • Parameters

    • optionalextra: ItemExtraData

      item extra instance, if not specified, method uses carried item's extra

    Returns EnchantData

    Enchant data object, containing enchants used for blocks destroy speed calculations.

getToolData

getToolLevel

  • getToolLevel(itemID: number): number

  • Parameters

    • itemID: number

      numeric item ID

    Returns number

    Tool's breaking level or 0 if no tool data was provided.

getToolLevelViaBlock

  • getToolLevelViaBlock(itemID: number, blockID: number): number

  • Parameters

    • itemID: number

      numeric item ID

    • blockID: number

      numeric tile ID

    Returns number

    Digging level if specified tool can mine specified block, 0 if data for the tool or for the block was not specified or if specified tool cannot mine specified block.

refresh

  • refresh(): void
  • @deprecated

    Backwards compatibility.


    Returns void

registerBlockDiggingLevel

  • registerBlockDiggingLevel(uid: number, level: number): void
  • Sets digging level for block. If digging level of tool is higher then block's one, the block is dropped.


    Parameters

    • uid: number

      numeric tile ID

    • level: number

      block's digging level

    Returns void

registerBlockMaterial

  • registerBlockMaterial(uid: number, materialName: string, level?: number, isNative?: boolean): void
  • Registers material and digging level for the specified block.


    Parameters

    • uid: number

      numeric tile ID

    • materialName: string

      material name

    • optionallevel: number

      block's digging level

    • optionalisNative: boolean

      used to mark vanilla blocks data. Generally used within Core Engine code and should not be used within mods until you really know what you're doing

    Returns void

registerBlockMaterialAsArray

  • registerBlockMaterialAsArray(materialName: string, UIDs: number[], isNative: boolean): void
  • Registers material and digging level for the specified blocks.


    Parameters

    • materialName: string

      material name

    • UIDs: number[]

      an array of numeric tiles IDs

    • isNative: boolean

      used to mark vanilla blocks data. Generally used within Core Engine code and should not be used within mods until you really know what you're doing

    Returns void

registerSword

  • Registers item as a sword.


    Parameters

    • id: number

      numeric item ID

    • toolMaterial: string | ToolMaterial

      registered tool material name or tool material object used to register the sword

    • optionalparams: ToolParams

      additional tool parameters

    Returns void

registerTool

  • registerTool(id: number, toolMaterial: string | ToolMaterial, blockMaterials: string[], params?: ToolParams): void
  • Registers item as a tool.


    Parameters

    • id: number

      numeric item ID

    • toolMaterial: string | ToolMaterial

      registered tool material name or tool material object used to register the tool

    • blockMaterials: string[]

      block material names that can be broken by this instrument. For example, you can use ["stone"] for the pickaxes

    • optionalparams: ToolParams

      additional tool parameters

    Returns void

resetEngine

  • resetEngine(): void
  • internal

    Returns void