Beta
Readonly
Beta
dimensionReadonly
Beta
isimport { world, system, BlockPermutation } from "@minecraft/server";
// bridge egg
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
if (entity.typeId === "minecraft:egg") {
const id = system.runInterval(() => {
const block = entity.dimension.getBlock(entity.location).below();
if (block.isAir)
block.setPermutation(
BlockPermutation.resolve("minecraft:wool")
);
else system.clearRun(id);
});
}
});
Readonly
Beta
isReadonly
Beta
isReturns true if this block is solid and impassible - (e.g., a cobblestone block and a diamond block are solid, while a ladder block and a fence block are not).
// Script by WavePlayz
import { world } from "@minecraft/server";
// Subscribe to the event that triggers when a player places a block
world.afterEvents.playerPlaceBlock.subscribe((eventData) => {
// Destructure the block object from the event data
const { block } = eventData;
// Check if the placed block is solid
if (block.isSolid) {
// Get the coordinates of the block's location
let { x, y, z } = block.location;
// Create a string of the coordinates in the format "x, y, z"
let coordinates = [x, y, z].join(", ");
// Send a message to the world indicating the location of the placed solid block
world.sendMessage(
"You placed a solid block at location: " + coordinates
);
}
});
Readonly
Beta
isReadonly
Beta
locationReadonly
Beta
permutationReadonly
Beta
typeReadonly
Beta
typeReadonly
Beta
xReadonly
Beta
yReadonly
Beta
zBeta
Optional
steps: numberNumber of steps below to step before returning.
Returns the Block below this block (negative in the Y direction).
// Script by WavePlayz
import { world } from "@minecraft/server";
// Subscribe to the event that triggers when a player places a block
world.afterEvents.playerPlaceBlock.subscribe((eventData) => {
// Extract the player and block objects from the event data
const { player, block } = eventData;
// Get the block that is directly below the block that was just placed
const blockBelowThePlacedBlock = block.below(1);
// Get the type of the block that is below the placed block
const blockBelowThePlacedBlockType = blockBelowThePlacedBlock.type;
// Set the type of the newly placed block to be the same as the block below it
block.setType(blockBelowThePlacedBlockType);
});
Beta
Block type or block permutation to check placement for.
Optional
faceToPlaceOn: 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
.
Beta
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 { BlockPermutation, ItemStack, world } from "@minecraft/server";
// Chest Block at (0, 0, 0)
const block = world.getDimension("overworld").getBlock({ x: 0, y: 0, z: 0 });
block.setPermutation(BlockPermutation.resolve("minecraft:chest"));
const inventory = block.getComponent("inventory").container;
inventory.addItem(new ItemStack("minecraft:cobblestone", 64));
import {
BlockPermutation,
ItemStack,
SignSide,
world,
} from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";
// Chest Block at (0, 0, 0)
const block = world.getDimension("overworld").getBlock({ x: 0, y: 0, z: 0 });
block.setPermutation(
BlockPermutation.resolve(MinecraftBlockTypes.BirchHangingSign)
);
const sign = block.getComponent("minecraft:sign");
sign.setText("back", SignSide.Back);
sign.setText("front", SignSide.Front);
import { BlockPermutation, ItemStack, world } from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";
// Chest Block at (0, 0, 0)
const block = world.getDimension("overworld").getBlock({ x: 0, y: 0, z: 0 });
block.setPermutation(
BlockPermutation.resolve(MinecraftBlockTypes.DarkoakStandingSign)
);
const sign = block.getComponent("minecraft:sign");
sign.setText("lol");
import { BlockPermutation, ItemStack, world } from "@minecraft/server";
import { MinecraftBlockTypes } from "@minecraft/vanilla-data";
// Chest Block at (0, 0, 0)
const block = world.getDimension("overworld").getBlock({ x: 0, y: 0, z: 0 });
block.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Piston));
const piston = block.getComponent("piston");
console.warn(piston.state, JSON.stringify(piston.getAttachedBlocksLocations()));
Beta
Optional
amount: numberNumber of instances of this block to place in the item stack.
Optional
withData: 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.
Beta
Returns undefined if redstone power is not applicable to this block.
// Script by WavePlayz
import { world } from "@minecraft/server";
// Function to check if a given block is powered by redstone
function isBlockPowered(block) {
// Get the redstone power level of the block
// The 'getRedstonePower' method returns a number representing the power level
// If the power level is greater than 0, it means the block is powered
return block.getRedstonePower() > 0;
}
Beta
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")}`);
Beta
Block type identifier to match this API against.
Optional
states: Record<string, string | number | boolean>Optional set of block states to test this block against.
Returns true if the block matches the specified criteria.
// Script by WavePlayz
import { world } from "@minecraft/server";
// Function to check if a given block is red wool
function isRedWool(block) {
// Define the type id of block we are checking for
let typeId = "wool";
// Define the block state we are looking for
// In this case, we want the color to be red
let states = { color: "red" };
// Check if the block matches the specified type and states
// The 'matches' method returns true if the block is of the specified type and has the specified states
return block.matches(typeId, states);
}
Beta
The offset vector. For example, an offset of 0, 1, 0 will return the block above the current block.
Block at the specified offset, or undefined if that block could not be retrieved (for example, the block and its relative chunk is not loaded yet.)
Beta
Permutation that contains a set of property states for the Block.
Beta
Identifier of the type of block to apply - for example, minecraft:powered_repeater.
// Script by WavePlayz
import { world, BlockTypes } from "@minecraft/server";
// Get all available block types in the game
const blockTypes = BlockTypes.getAll();
// Function to get a random block type from the list of block types
const getRandomBlockType = () =>
blockTypes[Math.floor(blockTypes.length * Math.random())];
// Subscribe to the event that triggers when a player places a block
world.afterEvents.playerPlaceBlock.subscribe((eventData) => {
// Destructure the player and block objects from the event data
const { player, block } = eventData;
// Get a random block type
const randomBlockType = getRandomBlockType();
// Send a message to the player indicating the type of block they placed
player.sendMessage("You placed the " + randomBlockType.id + " block, xD");
// Change the type of the placed block to the random block type
block.setType(randomBlockType);
});
Beta
Permutation that contains a set of property states for the Block.
Returns true
if the block permutation data was
successfully set, else false
.
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.
Example: createWall.ts