@minecraft
    正在准备搜索索引...

    类 BlockDynamicPropertiesComponent实验性

    Represents the dynamic properties of a block in the world. Only available with block entities. Up to 1KB per content pack, per block entity in their dynamic properties storage.

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

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

    层级 (查看层级一览)

    索引

    属性

    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'

    方法

    • 世界修改

      参数

      • key: string
      • 可选value: string | number | boolean | Vector3

      返回 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. Storage size usage is counted towards the 1KBytes limit per content pack.