PrivateconstructorOptionalhudElements: HudElement[]This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
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;
// Display a message on the player's action bar indicating the type of block they placed
player.onScreenDisplay.setActionBar(`You placed ${block.typeId}`);
});
OptionalhudElements: HudElement[]This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Optionaloptions: TitleDisplayOptionsThis function can't be called in read-only mode.
This function can't be called in early-execution mode.
import { world } from "@minecraft/server";
// Function to convert seconds to ticks (1 second = 20 ticks in Minecraft)
let secsToTicks = (/** @type {number} */ secs) => secs * 20;
// 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;
// Define display options for the title message
let displayOptions = {
fadeInDuration: secsToTicks(0.5), // Duration for the title to fade in
fadeOutDuration: secsToTicks(1), // Duration for the title to fade out
stayDuration: secsToTicks(1.5), // Duration for the title to stay on screen
subtitle: player.name, // Subtitle showing the player's name
};
// Set the title message to display when a block is placed
player.onScreenDisplay.setTitle(`You placed \n ${block.typeId}`, displayOptions);
});
This function can't be called in read-only mode.
This function can't be called in early-execution mode.
Remarks
Write Privilege
This function can't be called in read-only mode.
Throws
This function can throw errors.
InvalidEntityError
World Ready
This function can't be called in early-execution mode.