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

    类 BlockPermutation

    Contains the combination of type BlockType and properties (also sometimes called block state) which describe a block (but does not belong to a specific Block).

    import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from "@minecraft/server";
    import { MinecraftBlockTypes } from "@minecraft/vanilla-data";

    function addTranslatedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
    const players = world.getPlayers();

    const dim = players[0].dimension;

    const signBlock = dim.getBlock(targetLocation);

    if (!signBlock) {
    log("Could not find a block at specified location.");
    return -1;
    }
    const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });

    signBlock.setPermutation(signPerm);

    const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent;

    signComponent?.setText({ translate: "item.skull.player.name", with: [players[0].name] });
    }
    索引

    属性

    type: BlockType

    The BlockType that the permutation has.

    方法

    • 参数

      • liquidType: Water

        The type of liquid this function should be called for.

      返回 boolean

      Whether this block is removed when touched by liquid.

      Returns whether this block is removed when touched by liquid.

      This function can throw errors.

    • 参数

      • liquidType: Water

        The type of liquid this function should be called for.

      返回 boolean

      Whether this block can have a liquid placed over it.

      Returns whether this block can have a liquid placed over it, i.e. be waterlogged.

      This function can throw errors.

    • 返回 Record<string, string | number | boolean>

      Returns the list of all of the block states that the permutation has.

      Returns all available block states associated with this block.

    • 参数

      • 可选amount: number

        Number of instances of this block to place in the prototype item stack. Defaults to: 1

      返回 ItemStack

      Retrieves a prototype item stack based on this block permutation that can be used with item Container/ContainerSlot APIs.

    • 参数

      • tag: string

      返回 boolean

      Returns true if the permutation has the tag, else false.

      Checks to see if the permutation has a specific tag.

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

      function checkBlockTags(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
      // Fetch the block
      const block = targetLocation.dimension.getBlock(targetLocation);

      // check that the block is loaded
      if (block) {
      log(`Block is dirt: ${block.hasTag("dirt")}`);
      log(`Block is wood: ${block.hasTag("wood")}`);
      log(`Block is stone: ${block.hasTag("stone")}`);
      }
      }
    • 参数

      • liquidType: Water

        The type of liquid this function should be called for.

      返回 boolean

      Whether this block stops liquid from flowing.

      Returns whether this block stops liquid from flowing.

      This function can throw errors.

    • 参数

      • liquidType: Water

        The type of liquid this function should be called for.

      返回 boolean

      Whether this block is removed and spawns its item when touched by liquid.

      Returns whether this block is removed and spawns its item when touched by liquid.

      This function can throw errors.

    • 类型参数

      参数

      • blockName: T

        Identifier of the block to check.

      • 可选states: BlockStateArg<T>

      返回 BlockPermutation

      Given a type identifier and an optional set of properties, will return a BlockPermutation object that is usable in other block APIs (e.g., block.setPermutation)

      This function can throw errors.

      import { BlockPermutation, DimensionLocation } from "@minecraft/server";
      import { Vector3Utils } from "@minecraft/math";
      import { MinecraftBlockTypes } from "@minecraft/vanilla-data";

      function addBlockColorCube(targetLocation: DimensionLocation) {
      const allWoolBlocks: string[] = [
      MinecraftBlockTypes.WhiteWool,
      MinecraftBlockTypes.OrangeWool,
      MinecraftBlockTypes.MagentaWool,
      MinecraftBlockTypes.LightBlueWool,
      MinecraftBlockTypes.YellowWool,
      MinecraftBlockTypes.LimeWool,
      MinecraftBlockTypes.PinkWool,
      MinecraftBlockTypes.GrayWool,
      MinecraftBlockTypes.LightGrayWool,
      MinecraftBlockTypes.CyanWool,
      MinecraftBlockTypes.PurpleWool,
      MinecraftBlockTypes.BlueWool,
      MinecraftBlockTypes.BrownWool,
      MinecraftBlockTypes.GreenWool,
      MinecraftBlockTypes.RedWool,
      MinecraftBlockTypes.BlackWool,
      ];

      const cubeDim = 7;

      let colorIndex = 0;

      for (let x = 0; x <= cubeDim; x++) {
      for (let y = 0; y <= cubeDim; y++) {
      for (let z = 0; z <= cubeDim; z++) {
      colorIndex++;
      targetLocation.dimension
      .getBlock(Vector3Utils.add(targetLocation, { x, y, z }))
      ?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length]));
      }
      }
      }
      }