Private
constructorReadonly
effectThis event is triggered after an event has been added to an entity.
Readonly
entityFires before an entity is removed from the world (for example, unloaded or removed after being killed.)
Readonly
explosionThis event is fired after an explosion occurs.
Readonly
itemThis event fires when an item is successfully used by a player.
Readonly
itemThis event fires when an item is used on a block by a player.
import { world, Player, BlockPermutation } from "@minecraft/server";
// Subscribe to the itemUseOn event before it happens
world.beforeEvents.itemUseOn.subscribe((event) => {
const { source, block, itemStack } = event;
if (!(source instanceof Player)) return;
source.sendMessage("You used " + itemStack.typeId + " on " + block.typeId);
// If the item is a diamond, set the block to be a diamond block
if (itemStack.typeId === "minecraft:diamond") {
block.setPermutation(
BlockPermutation.resolve("minecraft:diamond_block")
);
}
});
Readonly
playerThis event fires before a block is broken by a player.
Readonly
playerReadonly
playerFires before a player interacts with a block.
Readonly
playerFires before a player interacts with an entity.
Readonly
playerFires when a player leaves the game.
import { world } from "@minecraft/server";
world.beforeEvents.playerLeave.subscribe(({ player }) => {
world.sendMessage(
`[${new Date().toISOString()}]` + player.name + "left the server"
);
});
Readonly
weatherReadonly
worldThis event fires immediately when the script environment is initialized on a World. Not all script functionality may be available. For guaranteed access to world state, use the world initialize after event.
A set of events that fire before an actual action occurs. In most cases, you can potentially cancel or modify the impending event. Note that in before events any APIs that modify gameplay state will not function and will throw an error. (e.g., dimension.spawnEntity)