Readonly BetablockThis event fires for each BlockLocation destroyed by an explosion. It is fired after the blocks have already been destroyed.
import { world, BlockExplodeAfterEvent } from "@minecraft/server";
world.afterEvents.blockExplode.subscribe((event: BlockExplodeAfterEvent) => {
console.log("Block:", event.block);
console.log("Dimension:", event.dimension);
console.log("Exploded Block Permutation:", event.explodedBlockPermutation);
console.log("Source:", event.source);
// set block back
event.block.setPermutation(event.explodedBlockPermutation);
});
ReadonlybuttonReadonly 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 Betaeffectimport { world } from "@minecraft/server";
const effectAddSubscription = world.afterEvents.effectAdd.subscribe(
(event) => {
console.log("Effect:", event.effect);
console.log("Effect State:", event.effectState);
console.log("Entity:", event.entity);
// Your custom handling for the effect added event
// Example: Notify players, update UI, etc.
},
{
// Optionally provide EntityEventOptions to filter entities or entity types
entities: [],
entityTypes: ["minecraft:creeper", "minecraft:player"], // Array of entity type IDs
}
);
// Later, you can unsubscribe when needed
world.afterEvents.effectAdd.unsubscribe(effectAddSubscription);
ReadonlyentityReadonlyentityimport { world } from "@minecraft/server";
const healthChangedSubscription =
world.afterEvents.entityHealthChanged.subscribe(
(event) => {
console.log("Entity:", event.entity);
console.log("Old Health:", event.oldValue);
console.log("New Health:", event.newValue);
// Your custom handling for entity health change event
// Example: Display a message, update UI, etc.
},
{
// Optionally provide EntityEventOptions to filter entities or entity types
entities: [],
entityTypes: ["minecraft:player", "minecraft:zombie"], // Array of entity type IDs
}
);
// Later, you can unsubscribe when needed
world.afterEvents.entityHealthChanged.unsubscribe(healthChangedSubscription);
Readonlyentityimport { 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");
});
Readonlyentityimport { 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");
});
ReadonlyentityReadonly Betaentity// Subscribe to the EntityLoadAfterEvent
const entityLoadSubscription = world.afterEvents.entityLoad.subscribe(
(event: EntityLoadAfterEvent) => {
// Handle the entity load event
console.log(`Entity loaded: ${event.entity.typeId}`);
}
);
// ... Later in your code, when you want to unsubscribe
world.afterEvents.entityLoad.unsubscribe(entityLoadSubscription);
Readonly BetaentityReadonly BetaentityReadonly Betaexplosion// Subscribe to the ExplosionAfterEvent
const explosionSubscription = world.afterEvents.explosion.subscribe(
(event: ExplosionAfterEvent) => {
console.log(`Explosion occurred in dimension ${event.dimension.id}`);
if (event.source) {
console.log(`Explosion source: ${event.source.typeId}`);
} else {
console.log(`Explosion source: None`);
}
const impactedBlocks = event.getImpactedBlocks();
console.log(`Impacted blocks: ${JSON.stringify(impactedBlocks)}`);
}
);
// ... Later in your code, when you want to unsubscribe
world.afterEvents.explosion.unsubscribe(explosionSubscription);
ReadonlyitemReadonly BetaitemReadonlyitemReadonlyitemReadonlyitemReadonlyitemReadonlyitemReadonlyitemReadonlyitemReadonlyleverReadonly BetamessageReadonly BetapistonReadonly BetaplayerReadonlyplayerReadonlyplayerReadonly BetaplayerReadonlyplayerReadonlypressureReadonlypressureReadonlyprojectileReadonlyprojectileReadonlytargetReadonlytripReadonly BetaweatherReadonly Betaworld
Contains a set of events that are available across the scope of the World.