1

I'm creating a behavior pack and I need to detect the ID of a block placed by a player. The player_placed_block event doesn't give me an ID with the event data, it only gives me a three-dimensional coordinate of where the block was placed, and which player placed it:

Player placed block documentation.

There's also a getBlock method, which would work great with the coordinates I get back from the player_plaed_block event; however, it requires a ticking area:

Get block documentation.

The problem with getBlock is that I can't find anything in the documentation for getting the ticking area of the player, and the only thing I could find on the web was a ticket for code that didn't work, and seemed to require the tickingarea command to be ran in game first, which defeats the purpose of my script.


Is there a way to not only know the position and player, but also the type of block placed?

2 Answers 2

1

I assume this is from the community-ran bedrock(dawt)dev website? I recommend checking their Wiki / Guides which is also updated by the community.

0

As of @minecraft/server version 1.9.0-beta, the dimension.getBlock() method no longer requires a ticking area. However, as playerPlaceBlock extends BlockEvent, you can now access the block directly instead of via its coordinates.

Working Example:

import { world } from "@minecraft/server"

world.afterEvents.playerPlaceBlock.subscribe(event => {
    console.warn(event.block.typeId);
});

References (Linked): The Microsoft Learn documentation, which I have found to be generally reliable and up-to-date.

1
  • This requires functionality that has not yet been added to the latest stable version (1.8.0), so it will require enabling the 'Beta APIs' toggle under "Experiments." Mar 11 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .