Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.34 KB

File metadata and controls

52 lines (39 loc) · 1.34 KB

BeforeExplosionEvent

Description:

Code structure

class BeforeExplosionEvent {
  "cancel": boolean;
  readonly "dimension": Dimension;
  "impactedtotalBlocks": BlockLocation[];
  readonly "source": Entity;
}
class BeforeExplosionEventSignal {
  subscribe(
    callback: (arg: BeforeExplosionEvent) => void
  ): (arg: BeforeExplosionEvent) => void;
  unsubscribe(callback: (arg: BeforeExplosionEvent) => void): void;
}

Credit: @types/mojang-minecraft/index.d.ts;

Code examples:

Subscribe to events without unsubscribing:

import { world } from "mojang-minecraft";

world.events.beforeExplosion.subscribe((data) => {
  console.log(data.cancel);
  console.log(data.dimension);
  console.log(data.impactedtotalBlocks);
  console.log(data.source);
});

Subscribe and unsubscribe events:

import { world } from "mojang-minecraft";

let beforeExplosion = world.events.beforeExplosion.subscribe(() => {});
world.events.beforeExplosion.unsubscribe(beforeExplosion);