ReadonlydimensionReadonlyisReadonlyisReadonly BetaisReadonly BetaisReadonlylocationReadonlypermutationReadonly BetatypeReadonly BetatypeReadonlyxReadonlyyReadonlyzBetaBlock type or block permutation to check placement for.
OptionalfaceToPlaceOn: DirectionOptional specific face of this block to check placement against.
Returns true if the block type or permutation can be
placed on this block, else false.
The identifier of the component (e.g., 'minecraft:inventory'). If no namespace prefix is specified, 'minecraft:' is assumed. Available component IDs can be found as part of the BlockComponentTypes enum.
Returns the component if it exists on the block, otherwise undefined.
Gets a component (that represents additional capabilities) for a block - for example, an inventory component of a chest block.
import { ItemStack } from "@minecraft/server";
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);
}
BetaOptionalamount: numberNumber of instances of this block to place in the item stack.
OptionalwithData: booleanWhether additional data facets of the item stack are included.
An itemStack with the specified amount of items and data. Returns undefined if block type is incompatible.
Tag to check for.
Returns true if the permutation of this block has the tag,
else false.
import { world } from "@minecraft/server";
// Fetch the block
const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 });
console.log(`Block is dirt: ${block.hasTag("dirt")}`);
console.log(`Block is wood: ${block.hasTag("wood")}`);
console.log(`Block is stone: ${block.hasTag("stone")}`);
Permutation that contains a set of property states for the Block.
Sets the block in the dimension to the state of the permutation.
This function can't be called in read-only mode.
BetaIdentifier of the type of block to apply - for example, minecraft:powered_repeater.
BetaThis function can't be called in read-only mode.
BetaPermutation that contains a set of property states for the Block.
Returns true if the block permutation data was
successfully set, else false.
Tries to set the block in the dimension to the state of the permutation by first checking if the placement is valid.
This function can't be called in read-only mode.
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.