Readonly
Beta
chatimport { WeatherType, system, world } from "@minecraft/server";
world.beforeEvents.chatSend.subscribe((event) => {
const { message, sender } = event;
const { dimension } = sender;
if (message === "!weather clear") {
event.cancel = true;
system.run(() => {
dimension.setWeather(WeatherType.Clear);
});
}
});
Readonly
effectReadonly
entityReadonly
explosionReadonly
itemReadonly
itemimport { 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
playerReadonly
playerReadonly
Beta
playerReadonly
Beta
playerReadonly
playerReadonly
Beta
playerReadonly
weatherReadonly
Beta
world
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)