Interface ToolParams

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

interface ToolParams {
    blockMaterials?: {
        [key: string]: boolean;
    };
    brokenId?: number;
    calcDestroyTime?: ((tool: ItemInstance, coords: ItemUseCoordinates, block: Tile, timeData: {
        base: number;
        devider: number;
        modifier: number;
    }, defaultTime: number, enchantData?: EnchantData) => number);
    damage?: number;
    isNative?: boolean;
    isWeapon?: boolean;
    modifyEnchant?: ((enchantData: EnchantData, item: ItemInstance, coords?: ItemUseCoordinates, block?: Tile) => void);
    onAttack?: ((item: ItemInstance, victim: number, attacker: number) => boolean);
    onBroke?: ((item: ItemInstance) => boolean);
    onDestroy?: ((item: ItemInstance, coords: ItemUseCoordinates, block: Tile, player: number) => boolean);
    onMineBlock?: ((coords: ItemUseCoordinates, carried: ItemInstance, fullTile: Tile, blockSource: BlockSource, player: number) => void);
    toolMaterial?: ToolMaterial;
}

Hierarchy (view full)

Properties

blockMaterials?: {
    [key: string]: boolean;
}

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

brokenId?: number

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

0
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

    • (tool, coords, block, timeData, defaultTime, enchantData?): number
    • 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

damage?: number

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

0
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.

isWeapon?: boolean

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

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

    • (enchantData, item, coords?, block?): void
    • Parameters

      • enchantData: EnchantData

        Tool's enchant data.

      • item: ItemInstance

        Tool item.

      • Optionalcoords: ItemUseCoordinates

        Coordinates where the block is being broken. Passed only if the block is destroyed.

      • Optionalblock: Tile

        Destroyed block data. Passed only if the block is destroyed.

      Returns void

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

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

Type declaration

    • (item, victim, attacker): 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

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

onBroke?: ((item: ItemInstance) => boolean)

Function that is called when the instrument is broken.

Type declaration

    • (item): boolean
    • Parameters

      Returns boolean

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

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

Function that is called when the block is destroyed.

Type declaration

    • (item, coords, block, player): boolean
    • Parameters

      • item: ItemInstance

        Tool item.

      • coords: ItemUseCoordinates

        Coordinates where the block is destroyed.

      • block: Tile

        Block that is destroyed.

      • player: number

        Entity UID of the player that destroyed the block.

      Returns boolean

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

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

    • (coords, carried, fullTile, blockSource, player): void
    • Parameters

      • coords: ItemUseCoordinates

        Coordinates where the block is destroyed.

      • carried: ItemInstance

        An item in player's hand.

      • fullTile: Tile

        Block that was destroyed.

      • blockSource: BlockSource

        BlockSource object of the world where the block was destroyed.

      • player: number

        Entity UID of the player that destroyed the block.

      Returns void

toolMaterial?: ToolMaterial

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

Copyright © 2024 Nernar. Copyright © 2020 #mineprogramming. Built with ❤ and TypeDoc.