Readonly Betablockimport { world } from "@minecraft/server";
world.afterEvents.blockBreak.subscribe((event) => {
const { brokenBlockPermutation, player } = event;
if (brokenBlockPermutation.type.id === "minecraft:grass") {
player.sendMessage("You broke a grass block!");
}
if (brokenBlockPermutation.type.id === "minecraft:stone") {
player.sendMessage("You broke a stone block!");
}
});
Readonly BetablockReadonly BetablockReadonlybuttonReadonly Betachatimport { WeatherType, system, world } from "@minecraft/server";
const chatObjective =
world.scoreboard.getObjective("chat") ??
world.scoreboard.addObjective("chat", "chat");
world.afterEvents.chatSend.subscribe((event) => {
const { sender } = event;
const score = chatObjective.hasParticipant(sender)
? chatObjective.getScore(sender.scoreboardIdentity)
: 0;
chatObjective.setScore(sender, score + 1);
});
Readonly BetadataThis event is fired when an entity event has been triggered that will update the component definition state of an entity.
import { world, system, Entity } from "@minecraft/server";
const eventId = "minecraft:entity_spawned";
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
let [entityRaycaseHit] = player.getEntitiesFromViewDirection({
maxDistance: 150,
});
if (!entityRaycaseHit) continue;
let entity = entityRaycaseHit.entity;
if (entity?.typeId === "minecraft:sheep") {
listenTo(entity);
entity.triggerEvent(eventId);
}
}
});
function listenTo(entity: Entity) {
const callback = world.afterEvents.dataDrivenEntityTriggerEvent.subscribe(
(data) => {
world.afterEvents.dataDrivenEntityTriggerEvent.unsubscribe(
callback
);
data.getModifiers().forEach((modifier) => {
console.log(
"ComponentGroupsToAdd:",
modifier.getComponentGroupsToAdd()
);
console.log(
"ComponentGroupsToRemove:",
modifier.getComponentGroupsToRemove()
);
console.log("Triggers:", modifier.getTriggers());
});
},
{ entities: [entity], eventTypes: [eventId] }
);
}
Readonly BetaeffectReadonly BetaentityReadonly BetaentityReadonly Betaentityimport { world } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((event) => {
const location1 = event.damagingEntity.location;
const location2 = event.hitEntity.location;
const distance = Math.pow(
Math.pow(location2.x - location1.x, 2) +
Math.pow(location2.y - location1.y, 2) +
Math.pow(location2.z - location1.z, 2),
0.5
);
console.log("Distance: " + distance + " blocks");
});
Readonly Betaentityimport { world } from "@minecraft/server";
world.afterEvents.entityHitBlock.subscribe((event) => {
const location1 = event.damagingEntity.location;
const location2 = event.hitBlock.location;
const distance = Math.pow(
Math.pow(location2.x - location1.x, 2) +
Math.pow(location2.y - location1.y, 2) +
Math.pow(location2.z - location1.z, 2),
0.5
);
console.log("Distance: " + distance + " blocks");
});
Readonly BetaentityReadonly BetaentityReadonly BetaentityReadonly BetaexplosionReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonly BetaitemReadonlyleverReadonly BetamessageReadonly BetapistonReadonlyplayerReadonlyplayerReadonlyplayerReadonly BetapressureReadonly BetapressureReadonly BetaprojectileReadonly BetatargetReadonly BetatripReadonly BetaweatherReadonly Betaworld
Contains a set of events that are available across the scope of the World.