PrismarineJS / prismarine-viewer

Web based viewer for servers and bots
https://prismarinejs.github.io/prismarine-viewer/
MIT License
248 stars 69 forks source link

prismarine-viewer

Web based viewer for servers and bots

NPM version Build Status Discord Gitter Irc Issue Hunt

Try it on gitpod

viewer

Supports versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2, 1.16.1, 1.16.4, 1.17.1, 1.18.1, 1.19, 1.20.1.

Install

npm install prismarine-viewer

Example

const mineflayer = require('mineflayer')
const mineflayerViewer = require('prismarine-viewer').mineflayer

const bot = mineflayer.createBot({
  username: 'Bot'
})

bot.once('spawn', () => {
  mineflayerViewer(bot, { port: 3000 }) // Start the viewing server on port 3000

  // Draw the path followed by the bot
  const path = [bot.entity.position.clone()]
  bot.on('move', () => {
    if (path[path.length - 1].distanceTo(bot.entity.position) > 1) {
      path.push(bot.entity.position.clone())
      bot.viewer.drawLine('path', path)
    }
  })
})

More examples:

Projects using prismarine-viewer

API

prismarine-viewer

viewer

The core rendering library. It provides Viewer and WorldView which together make it possible to render a minecraft world. Check its API

mineflayer

Serve a webserver allowing to visualize the bot surrounding, in first or third person. Comes with drawing functionnalities.

const { mineflayer } = require('prismarine-viewer')

Options:

example

standalone

Serve a webserver allowing to visualize a world.

const { standalone } = require('prismarine-viewer')

Options:

example

headless

Render the bot view and stream it to a file or over TCP.

const { headless } = require('prismarine-viewer')

Options:

example

Drawing (mineflayer mode)

All drawing function have a unique id that can be used to replace or erase the primitive.

bot.viewer.drawLine (id, points, color=0xff0000)

Draw a line passing through all the points.

bot.viewer.erase (id)

Remove the primitive with the given id from the display.

bot.viewer.close ()

Stop the server and disconnect users.

Tests

npm run jestTest -- -t "1.9.4"