Web based viewer for servers and bots
This repository has been archived on 2023-06-07. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Leon Bowie 8de81dd316
Merge pull request #1 from AwesomestCode/master
Fix some bugs
2020-12-12 10:46:04 +13:00
.github/workflows Release 1.7.0 2020-12-03 01:23:13 +01:00
examples Fix some bugs 2020-12-11 14:04:53 -05:00
lib basic movement 2020-12-03 18:25:39 +13:00
public Fixed canvas CSS 2020-07-31 01:25:20 -07:00
src Fix some bugs 2020-12-11 14:04:53 -05:00
test 60s instead of 30s to give it time to render in viewer test 2020-07-17 01:40:32 +02:00
.DS_Store Fix some bugs 2020-12-11 14:04:53 -05:00
.gitignore Use more worker threads to generate meshs 2020-09-05 01:28:39 +02:00
.gitpod.dockerfile add testing using minecraft wrap 2020-07-16 23:30:56 +00:00
.gitpod.yml configure puppeteer and gitpod 2020-07-16 23:30:56 +00:00
.npmrc add npmrc that disable package-lock.json creation 2020-10-25 15:34:33 +00:00
HISTORY.md Release 1.7.0 2020-12-03 01:14:46 +01:00
LICENSE First commit 2020-06-10 23:18:20 +02:00
index.js Proof of concept headless renderer 2020-12-01 17:42:32 +01:00
jest-puppeteer.config.js configure puppeteer and gitpod 2020-07-16 23:30:56 +00:00
jest.config.js configure puppeteer and gitpod 2020-07-16 23:30:56 +00:00
package.json Release 1.7.1 2020-12-03 01:25:30 +01:00
readme.md Update API 2020-12-03 01:14:46 +01:00

readme.md

prismarine-viewer

Web based viewer for servers and bots

NPM version Build Status Discord Gitter Irc Issue Hunt

Try it on gitpod

viewer

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:

  • First person bot example
  • Record view as video file example
  • Streaming video to a python script example
  • Visualize a world, without a bot example

API

prismarine-viewer

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:

  • viewDistance view radius, in chunks, default: 6
  • firstPerson is the view first person ? default: false
  • port the port for the webserver, default: 3000

example

standalone

Serve a webserver allowing to visualize a world.

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

Options:

  • version the version to use, default: 1.13.2
  • generator a world generator function, default: (x, y, z) => 0
  • center a vec3 to center the view on, default: new Vec3(0, 0, 0)
  • viewDistance view radius, in chunks, default: 6
  • port the port for the webserver, default: 3000

example

headless

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

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

Options:

  • viewDistance view radius, in chunks, default: 6
  • output the output file or a host:port address to stream to, default: output.mp4
  • frames number of frames to record, -1 for infinite, default: 200
  • width the width of a frame, default: 512
  • height the height of a frame, default: 512

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.

Tests

node_modules/.bin/jest --verbose --runInBand --forceExit -t "1.16.1"