Script API - v1.26.30.28
    Preparing search index...

    Class BlockDynamicPropertiesComponentBeta

    Represents the dynamic properties of a block in the world. Only available with block entities. Up to 1KBytes of data can be stored per block entity in their dynamic properties storage.

    import { system } from '@minecraft/server-wrapper';

    system.beforeEvents.startup.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('scripting_demo_pack:block_entity_onPlayerInteract', {
    onPlayerInteract: e => {
    if (e.player === undefined) {
    return;
    }

    const dynamicProperties = e.block.getComponent('minecraft:dynamic_properties');
    if (!dynamicProperties) {
    return;
    }

    const lastInteractorValue = dynamicProperties.get('last_interactor');
    const lastVisitor = typeof lastInteractorValue === 'string' ? lastInteractorValue : 'unknown';
    const lastTick = Number(dynamicProperties.get('last_interact_tick') ?? system.currentTick);
    const ticksAgo = Math.max(0, system.currentTick - lastTick);

    if (lastVisitor === e.player.name) {
    e.player.sendMessage("do you remember that player? I 'member, it was here " + String(ticksAgo) + ' ticks ago!');
    } else {
    e.player.sendMessage("oh, I don't remember that player");
    }

    dynamicProperties.set('last_interactor', e.player.name);
    dynamicProperties.set('last_interact_tick', system.currentTick);
    },
    });
    });
    export class BlockDynamicPropertiesComponent extends BlockComponent {
    private constructor();
    static readonly componentId = 'minecraft:dynamic_properties';
    get(key: string): boolean | number | string | Vector3 | undefined;
    set(key: string, value?: boolean | number | string | Vector3): void;
    totalByteCount(): number;
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    block: Block

    Block instance that this component pertains to.

    This property can't be read in early-execution mode.

    isValid: boolean

    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.

    This property can't be read in early-execution mode.

    typeId: string

    Identifier of the component.

    This property can't be read in early-execution mode.

    componentId: "minecraft:dynamic_properties" = 'minecraft:dynamic_properties'

    Methods

    • Parameters

      • key: string
      • Optionalvalue: string | number | boolean | Vector3

      Returns void

      Sets a dynamic property with the provided key and value. Keys are unique to each content pack and cannot be used to set dynamic properties for other content packs. Values can be either a Number, a String or a Vector3. Setting a property with an undefined value will remove it from the storage.

      This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.