Skip to content

MinecraftJS/LunarBukkitAPI

Repository files navigation

LunarBukkitAPI

GitHub Workflow Status GitHub npm (scoped)

Defines the Lunar Client Bukkit protocol

Documentation

Installation

Install the package:

$ npm install @minecraft-js/lunarbukkitapi

And then import it in your JavaScript/TypeScript file

const LunarClient = require('@minecraft-js/lunarbukkitapi'); // CommonJS

import * as LunarClient from '@minecraft-js/lunarbukkitapi'; // ES6

High level API

This library comes with a high level API for a player which means you can easily set cooldowns, set waypoints without even touching any packets!

For now since there's no MinecraftJS client/server library you need to set your own packet sending/receiving handling.

At the time of writing, the biggest client/server library is PrismarineJS and here is a simple example with that library

// PrismarineJS
const mc = require('minecraft-protocol');
const server = mc.createServer({ ... });

server.on('login', (client) => {
  ...

  let playerChannel = '';
  const lunarPlayer = new LunarClient.LunarClientPlayer({
    customHandling: {
      registerPluginChannel(channel) {
        playerChannel = channel;

        // PrismarineJS way of sending packets
        client.write('custom_payload', {
          channel: 'REGISTER',
          data: Buffer.from(channel + '\0')
        });
      },

      sendPacket(buffer) {
        // PrismarineJS way of sending packets
        client.write('custom_payload', {
          channel: playerChannel,
          data: buffer
        })
      }
    }
  });

  // Sending a cooldown
  // with id of `pearl`
  // for 15s and an ender
  // pearl as item (368)
  lunarPlayer.addCooldown('pearl', 15000, 368);
});

Benchmarks

Packet used in the benchmark: CooldownPacket

Computer specs: Ryzen 5 3600 - 16GB at 2100MHz

Reading x 836,146 ops/sec ±0.28% (97 runs sampled)
Writing x 432,880 ops/sec ±1.23% (95 runs sampled)

Run this command to run the benchmarks on your machine

$ npm run benchmark