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

    Represents a block in a dimension. A block represents a unique X, Y, and Z within a dimension and get/sets the state of the block at that location. This type was significantly updated in version 1.17.10.21.

    Index

    Properties

    dimension: Dimension

    Returns the dimension that the block is within.

    location: Vector3

    Coordinates of the specified block.

    This property can throw when used.

    permutation: BlockPermutation

    Additional block configuration data that describes the block.

    This property can throw when used.

    LocationInUnloadedChunkError

    LocationOutOfWorldBoundariesError

    x: number

    X coordinate of the block.

    y: number

    Y coordinate of the block.

    z: number

    Z coordinate of the block.

    Methods

    • Parameters

      • componentName: string

        Identifier of the component. If a namespace is not specified, minecraft: is assumed.

      Returns BlockComponent

      Returns the component object if it is present on the particular block.

      Gets additional configuration properties (a component) for specific capabilities of particular blocks - for example, an inventory component of a chest block.

      const getEntityInventoryComponent = block.getComponent("inventory");
      const inventoryContainer = getEntityInventoryComponent.container;

      // Custom function to add an item to the inventory
      function addItemToInventory(itemStack) {
      return inventoryContainer.addItem(itemStack);
      }

      // Custom function to move an item within the inventory
      function moveItemWithinInventory(fromSlot, toSlot) {
      inventoryContainer.moveItem(fromSlot, toSlot, inventoryContainer);
      }

      // Custom function to transfer an item from inventory to another container
      function transferItemToContainer(fromSlot, targetContainer) {
      return inventoryContainer.transferItem(fromSlot, targetContainer);
      }

      // Example usage of the custom functions
      const newItemStack = new ItemStack("apple", 10); // Assuming "apple" is a valid item
      const addedItem = addItemToInventory(newItemStack);
      if (addedItem) {
      console.log("Item added to inventory:", addedItem);
      }

      const sourceSlot = 2;
      const destinationSlot = 5;
      moveItemWithinInventory(sourceSlot, destinationSlot);

      const targetContainer = someOtherContainer; // Assuming 'someOtherContainer' is an instance of another container
      const transferredItem = transferItemToContainer(0, targetContainer);
      if (transferredItem) {
      console.log("Item transferred to another container:", transferredItem);
      }
    • Returns boolean

      True if this block object is still working and valid.

      Returns true if this reference to a block is still valid (for example, if the block is unloaded, references to that block will no longer be valid.)