Block in the world

Block

A Block represents a single block in the world. You get block references from World.block_at() or event properties.


Constructor

Block(world=None, x=None, y=None, z=None, material=None)

Create a block reference.


Class Methods

create

block = await Block.create(location, material)

Create (place) a block at a location.

block = await Block.create(player.location.add(0, -1, 0), Material.DIAMOND_BLOCK)

Attributes

x

Block X coordinate.

y

Block Y coordinate.

z

Block Z coordinate.

type

The block's material type.

location

The block's location.

world

The world this block is in.

is_solid

Whether the block is solid (not air, water, etc.).

data

The block's data state (e.g., slab halves, stair direction). Varies by block type.

light_level

Light level at this block (0–15).

biome

The biome at this block's location.

hardness

The block's hardness (mining resistance). Read-only.

blast_resistance

The block's explosion resistance. Read-only.

is_passable

Whether entities can pass through this block.

is_liquid

Whether this block is a liquid (water/lava).

drops

The block's natural drops list.


Methods

break_naturally

await block.break_naturally()

Break the block as if a player mined it (drops items).

set_type

await block.set_type(material)

Change the block's material.

await block.set_type(Material.AIR)  # Delete the block

set_data

await block.set_data(data)

Set the block's data state. You can also use property syntax: block.data = value.

get_drops

drops = await block.get_drops(tool=None)

Get the block's drops with an optional tool.


Container Properties

These work on blocks that hold inventories (chests, hoppers, dispensers, droppers, barrels, etc.).

inventory

The block's inventory, or None if the block isn't a container.

chest = world.block_at(10, 64, 20)
inv = chest.inventory
if inv:
    items = inv.contents

is_container

Whether this block has an inventory.

state_type

The tile entity type name (e.g. "Sign", "Chest", "Furnace", "Hopper").


Sign Methods

These work on sign blocks (oak sign, birch sign, etc.). Properties return None if the block isn't a sign.

sign_lines

Front side text as a list of 4 strings.

sign = world.block_at(10, 64, 20)
lines = sign.sign_lines  # ["Hello", "World", "", ""]

sign_back_lines

Back side text as a list of 4 strings.

is_sign_glowing

Whether the front sign text is glowing. None if not a sign.

set_sign_line

await block.set_sign_line(index, text)

Set a single front sign line.

set_sign_lines

await block.set_sign_lines(lines)

Set all front sign lines at once. You can also use property syntax: block.sign_lines = [...].

await sign.set_sign_lines(["Welcome", "to the", "shop!", ""])

set_sign_back_line / set_sign_back_lines

Same as front-side methods, but for the back of the sign. Property syntax: block.sign_back_lines = [...].

set_sign_glowing

await block.set_sign_glowing(glowing)

Set whether the front sign text glows. You can also use property syntax: block.is_sign_glowing = True.


Furnace Methods

These work on furnace blocks (furnace, blast furnace, smoker). Properties return None if the block isn't a furnace.

furnace_burn_time

Remaining fuel burn time in ticks.

furnace_cook_time

Current cooking progress in ticks.

furnace_cook_time_total

Total cook time needed for the current item.

set_furnace_burn_time

await block.set_furnace_burn_time(ticks)

Set remaining fuel burn time. Property syntax: block.furnace_burn_time = ticks.

set_furnace_cook_time

await block.set_furnace_cook_time(ticks)

Set cooking progress. Property syntax: block.furnace_cook_time = ticks.

furnace = world.block_at(10, 64, 20)
if furnace.state_type == "Furnace":
    print(f"Cook progress: {{furnace.furnace_cook_time}}/{{furnace.furnace_cook_time_total}}")
    inv = furnace.inventory

set_biome

await block.set_biome(biome)

Change the biome at this block's position. Property syntax: block.biome = Biome.DESERT.


Persistent Data Container (PDC)

Store custom data on blocks that persists across restarts.

get_persistent_data

data = await block.get_persistent_data()

Get all persistent data as a dictionary.

set_persistent_data

await block.set_persistent_data(key, value)

Set a persistent data key.

remove_persistent_data

await block.remove_persistent_data(key)

Remove a persistent data key.

await block.set_persistent_data("owner", player.name)
data = await block.get_persistent_data()
print(data["owner"])  # "Steve"