JSPM

  • Created
  • Published
  • Downloads 54
  • Score
    100M100P100Q86702F
  • License MIT

About Public repository to simplify the event logic of Mojang's Script API, for informal or professional use

Package Exports

  • simplified-mojang-api
  • simplified-mojang-api/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simplified-mojang-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🛠️ Simplified Mojang API

[!WARNING] ⚠️ WORK IN PROGRESS! ⚠️ This repository is constantly evolving and undergoing active updates, so some features or simplified methods may be missing or not yet implemented. Please keep this in mind when using it!

A simple tool that makes it easier to use the Mojang scripting API for Minecraft Bedrock, by providing pre-built and simplified classes.

What is this?

It's an informal or professional repository designed to simplify the logic of the native @minecraft/server module by integrating various pre-built classes and methods to save time and reduce code, as well as tools I've customized myself for use in any add-on.

Install:

Just run this in your terminal:

npm install simplified-mojang-api

(Make sure you also have the base @minecraft/server stuff installed!)

Build Setup:

Because this API includes physical files (a .mcstructure for fake players) and uses @minecraft/vanilla-data for typing, you must configure your bundler (like esbuild) properly.

  • Add these scripts to your Add-on's package.json:

    • Copy the physical assets, You need to move the API's structures to your behavior pack

      You need to move the API's structures to your behavior pack

    "copy:api-assets": "node -e \"const fs = require('fs'); const src = 'node_modules/simplified-mojang-api/structures'; if (fs.existsSync(src)) fs.cpSync(src, 'behaviors/YOUR_ADDON/structures', { recursive: true, force: false });\""
    • Compile with esbuild

      Exclude the native Minecraft modules, but do not exclude @minecraft/vanilla-data so it gets bundled as pure strings.

    "compile": "npm run copy:api-assets && esbuild behaviors/YOUR_ADDON/src/main.ts --bundle --format=esm --outfile=behaviors/YOUR_ADDON/scripts/main.js --target=es2020 --external:@minecraft/server --external:@minecraft/server-ui --external:@minecraft/server-gametest --external:@minecraft/server-graphics --external:@minecraft/server-net --external:@minecraft/debug-utilities --external:@minecraft/gameplay-utilities --sourcemap"

API Examples:

Fast Offhand Items

Make items jump to the offhand with a single click.

import { customEventsManager } from "simplified-mojang-api";

// Any item with these words in its ID becomes a fast-equip item
customEventsManager.fastItemsSystem(["totem", "shield", "arrow"]);

Visual Debugging (Hitboxes)

Easily show visual hitboxes for all nearby entities using the debug module. Great for testing custom mob sizes or attack ranges!

import { debugToolsSimplified } from "simplified-mojang-api";

// Shows hitboxes to the specific player within a 50 block radius
debugToolsSimplified.showHitboxes(player, 50);

// Turn them off when you're done testing
// debugToolsSimplified.stopHitboxes();

Fake Player Spawner

Instantly spawn a simulated player into the world using the gametest API. Perfect for testing multiplayer mechanics solo.

import * as mc from "@minecraft/server";
import { fakePlysSimplified } from "simplified-mojang-api";

// Spawns a fake player named "Dummy" in Survival mode
fakePlysSimplified.createFakePly("Dummy", mc.GameMode.Survival);

Contributing

Found a bug or want to wrap a new Mojang method? PRs are super welcome!

Author: HaJuegos License: MIT