Allows the entity to be leashed. Defines the conditions and events for when an entity is leashed.

Example

entityLeashable.js

import { world } from "@minecraft/server";

const entity = world.getEntity("-10000000000");
const leashHolderEntity = world.getEntity("-10000000000");
const leashable = entity.getComponent("leashable");
leashable.softDistance;
leashable.leashTo(leashHolderEntity); // Assuming you have an 'leashHolderEntity' instance
leashable.unleash();
leashable.isValid();

Hierarchy

Constructors

Properties

canBeStolen: boolean

Remarks

Returns true if another entity can 'steal' the leashed entity by attaching their own leash to it.

Throws

This property can throw when used.

entity: Entity

Remarks

The entity that owns this component. The entity will be undefined if it has been removed.

hardDistance: number

Remarks

Distance in blocks at which the leash stiffens, restricting movement.

Throws

This property can throw when used.

isLeashed: boolean

Remarks

Returns true if the entity is leashed.

Throws

This property can throw when used.

leashHolder?: Entity

Remarks

Entity that is holding the leash.

Throws

This property can throw when used.

leashHolderEntityId?: string

Remarks

Identifier of entity that is holding the leash.

Throws

This property can throw when used.

maxDistance: number

Remarks

Distance in blocks at which the leash breaks.

Throws

This property can throw when used.

softDistance: number

Remarks

Distance in blocks at which the 'spring' effect starts acting to keep this entity close to the entity that leashed it.

Throws

This property can throw when used.

typeId: string

Remarks

Identifier of the component.

componentId: "minecraft:leashable" = 'minecraft:leashable'

Methods

  • Returns boolean

    Whether the component is valid.

    Remarks

    Returns whether the component is valid. A component is considered valid if its owner is valid, in addition to any addition to any additional validation required by the component.

  • Parameters

    • leashHolder: Entity

      The entity to leash this entity to.

    Returns void

    Remarks

    Leashes this entity to another entity.

    This function can't be called in read-only mode.

    Throws

    Throws if the entity to leash to is over the max distance, and if the player is dead or in spectator mode.

  • Returns void

    Remarks

    Unleashes this entity if it is leashed to another entity.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.