@minecraft
    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);
    },
    });
    });

    Hierarchy (View Summary)

    Index

    Properties

    block: Block

    Block instance that this component pertains to.

    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.

    typeId: string

    Identifier of the component.

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

    Methods