@ascentbv/ts-common - v1.0.123
    Preparing search index...

    Class BlockUtilAbstract

    Index

    Constructors

    Methods

    • Safely fetches a block at the given location.

      Parameters

      Returns Block | undefined

      The Block if available; otherwise undefined on error or if the block is not loaded.

      const block = BlockUtil.getBlockSafe(player.dimension, player.location);
      if (block) DevUtil.logAll("Debug", block.typeId);
      • Internally calls dimension.getBlock. Any exceptions are caught and logged via DevUtil.
      • If location is a Vec3, its .unwrap() is used.
    • Returns the block adjacent to the given block in a specific direction.

      Parameters

      Returns Block | undefined

      The neighbor block if available; otherwise undefined.

      const above = BlockUtil.getAdjacentBlock(block, Direction.Up);
      
      • Uses getBlockSafe under the hood to avoid throwing on unloaded chunks.
      • Non-cardinal directions (if ever added) will return undefined.
    • Checks if a block at the given location is currently loaded and valid.

      Parameters

      Returns boolean

      true if the block exists and block.isValid is truthy; otherwise false.

      if (BlockUtil.isBlockLoaded(pos, player.dimension)) {
      // safe to read or modify
      }
      • Wraps dimension.getBlock in a try/catch and profiles via DebugTimerUtil.
    • Finds the highest air (or optionally water) block at X/Z by scanning from maxY down to minY.

      Parameters

      Returns Readonly<{ x: number; y: number; z: number }> | null

      A BlockPos where the highest matching block is found, or null if none in range.

      const spawn = BlockUtil.getHighestAirBlock(player.dimension, player.location, { maxY: 320 });
      if (spawn) player.teleport(spawn);
      • Default range is minY = 0 to maxY = 320.
      • If includeWater is true, "minecraft:water" and "minecraft:flowing_water" are treated as air.
      • Performance scales with (maxY - minY); constrain the range when possible.
    • Builds a bitmask of cardinal neighbors (N/E/S/W) whose type matches typeId.

      Parameters

      • block: Block

        The center Block.

      • typeId: string

        A block type ID to compare against (e.g., "minecraft:stone").

      Returns NeighborMask

      A NeighborMask bitmask (combine with &/|).

      const mask = BlockUtil.getNeighborBlockType(block, "minecraft:oak_fence");
      if (BlockUtil.hasNeighbor(mask, Direction.North)) {
      // connected north
      }
      • Uses DebugTimerUtil profiling.
      • Only cardinal directions are considered. Diagonals are not included.
    • Converts a block position into a canonical key string "x,y,z".

      Parameters

      Returns `${number},${number},${number}`

    • Converts a block position into a canonical key string "x,y,z".

      Parameters

      • location: { x: number; y: number; z: number }

      Returns string

    • Parses a canonical key string "x,y,z" back into a block position object.

      Parameters

      • locKey: `${number},${number},${number}`

      Returns BlockPos

    • Parses a canonical key string "x,y,z" back into a block position object.

      Parameters

      • locKey: string

      Returns { x: number; y: number; z: number }