Skip to content

Replace deprecated event.source with event.player #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: wiki
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/scripting/placement-prevention.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ After we have added the module, we will add the preventative measure for block p

```js
world.beforeEvents.playerPlaceBlock.subscribe((event) => {
const player = event.source;
const player = event.player;
if (event.permutationBeingPlaced.type.id === "minecraft:bedrock") {
event.cancel = true;
system.run(() => {
Expand All @@ -107,7 +107,7 @@ world.beforeEvents.playerPlaceBlock.subscribe((event) => {

This is the main function to execute our code. `world.beforeEvents.playerPlaceBlock.subscribe()` will run before any block is placed.

- `const player = event.source;` defines the variable `player` as whatever the source of the event is (the one who is placing the block). `const` is used over `var` or `let` to say that the source _cannot_ be changed, and is constant.
- `const player = event.player;` defines the variable `player` as whatever the source of the event is (the one who is placing the block). `const` is used over `var` or `let` to say that the source _cannot_ be changed, and is constant.
- The `if()` statement requires the criteria to evaluate to true in order for the code within the brackets to run.
- `event.permutationBeingPlaced.type.id === 'minecraft:bedrock'` verifies that the block being placed is 'minecraft:bedrock'.
- `event.block.typeId != "minecraft:frame" && event.block.typeId != "minecraft:glow_frame"` checks that the block being targeted is not an item frame, so that the block whose placement is being canceled can still be placed in item frames.
Expand Down