PrivateconstructorReadonlyeffectReadonlyentityThis property can be read in early-execution mode.
ReadonlyentityThis property can be read in early-execution mode.
ReadonlyentityThis property can be read in early-execution mode.
ReadonlyentityThis property can be read in early-execution mode.
import { world } from "@minecraft/server";
// Subscribe to entityRemove event
world.beforeEvents.entityRemove.subscribe((data) => {
world.sendMessage("Entity Removed: " + data.removedEntity.typeId);
// Spawn lightning when an entity is removed.
data.removedEntity.runCommand("summon lightning_bolt ~ ~10 ~");
});
ReadonlyexplosionThis property can be read in early-execution mode.
ReadonlyitemThis property can be read in early-execution mode.
ReadonlyplayerThis property can be read in early-execution mode.
ReadonlyplayerThis property can be read in early-execution mode.
import { world } from "@minecraft/server";
// Disable the ability of any players without admin tag from changing gamemode.
world.beforeEvents.playerGameModeChange.subscribe((event) => {
if (!event.player.hasTag("admin")) {
event.cancel = true;
event.player.sendMessage("You can't change gamemode!");
}
});
ReadonlyplayerThis property can be read in early-execution mode.
import { system, world } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Subscribe to playerInteractWithBlock event to detect if a player interacts with a block
world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
// Check if player interacts with a crafter whilst holding diamonds
if (
event.block.typeId === "minecraft:crafter" &&
event.itemStack &&
event.itemStack.typeId === "minecraft:diamond"
) {
// Cancel interaction
event.cancel = true;
// Use system.run to queue for later in the current tick to bypass read-only state
system.run(() => {
// Show the player a message form
new MessageFormData().title("Crafter").body("This is a crafter!").button1("Close").show(event.player);
});
}
});
// Please note that playerInteractWithBlock does not fire when player interacts with air.
ReadonlyplayerThis property can be read in early-execution mode.
import { system, world } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Subscribe to playerInteractWithEntity event to detect if a player interacts with a block
world.beforeEvents.playerInteractWithEntity.subscribe((event) => {
// Check if player interacts with a villager whilst holding diamonds
if (event.target.typeId === "minecraft:villager" || event.target.typeId === "minecraft:villager_v2") {
// Cancel interaction
event.cancel = true;
// Use system.run to queue for later in the current tick to bypass read-only state
system.run(() => {
// Show the player a message form
new MessageFormData().title("villager").body("This is a villager!").button1("Close").show(event.player);
});
}
});
ReadonlyplayerThis property can be read in early-execution mode.
ReadonlyweatherThis property can be read in early-execution mode.
Remarks
This property can be read in early-execution mode.
Example: cancelEffect.js