A set of utilities and functions for common gameplay operations. Major pieces are covered below.
nextEvent() is a function which takes a Minecraft event signal and wraps a promise around the next event being raised. The function returns an EventPromise object which is a promise type. When the event is raised, the promise will resolve with the event data, and unsubscribe from the event's signal. The EventPromise type also adds a cancel() function which will unsubscribe from the event's signal, and fulfill the promise with undefined.
const event = await nextEvent(world.afterEvents.buttonPush);
await nextEvent(world.afterEvents.leverAction).then(
(event) => {
// do something with the event
}).finally(() => {
// something else to do
});
const creeperDeathEvent = await nextEvent(world.afterEvents.entityDie, { entityTypes: ['minecraft:creeper'] });
@minecraft/gameplay-utilities is published to NPM and follows standard semver semantics. To use it in your project,
@minecraft/gameplay-utilities from NPM by doing npm install @minecraft/gameplay-utilities within your scripts pack. By using @minecraft/gameplay-utilities, you will need to do some sort of bundling to merge the library into your packs code. We recommend using esbuild for simplicity.This is an external Minecraft library published to NPM. It is not part of Minecraft's native modules.
There are two ways to use this library:
Download a standalone file available to download from https://jaylydev.github.io/scriptapi-docs/meta/cdn-links.html for quick, small-scale projects.
Installing it through npm, with advanced build configurations and bundling with esbuild.
Installation:
npm i @minecraft/gameplay-utilities@1.1.0