Install prismarine-viewer via npm
masterTo use the web-based viewer for Minecraft servers and bots, install the package using npm:
npm install prismarine-viewerrepository·master·Indexed 18 days ago
https://github.com/prismarinejs/prismarine-viewerA web-based visualization tool for Minecraft servers and bots (version 1.33.0). It allows developers to view worlds, bot movements, and environments in a browser. The library includes specialized modules for Mineflayer bot visualization, standalone world viewing, and headless rendering for recording video or streaming via RTMP and TCP. It features a Viewer class based on three.js for rendering, WorldView for camera and chunk management, and capabilities to draw geometric primitives like lines and boxes in the viewer.
To use the web-based viewer for Minecraft servers and bots, install the package using npm:
npm install prismarine-viewerThe exporter package provides examples for transforming world parts into screenshots and 3D models.
To use these examples:
examples/exporter directory.npm install.node screenshot.js.node 3dmodel.js.Generated 3D files can be viewed using an external glTF viewer such as https://gltf.insimo.com/.
npm install
node screenshot.js
node 3dmodel.jsIf you are running the 3D model exporter in a headless environment (a server without a display), you must use xvfb-run to provide a virtual framebuffer. Use the following command to run the 3D model generation:
xvfb-run -s "-ac -screen 0 1280x1024x24" node 3dmodel.jsTo run the standalone web client, you need to install the dependencies and then run the build and start command. This is typically used to launch a local development server or a pre-built version of the viewer for testing or demonstration purposes.
npm install
npm run build-startTo run the standalone version of the viewer, install the dependencies and then execute the build and start command. This is typically used to preview the standalone web client implementation.
npm install
npm run build-startThe standalone viewer uses a push-based model for chunk synchronization. When a client connects via Socket.io, the server immediately sends the current version, the initial position (based on the center config), and all chunks within the viewDistance radius around the center.
To force the server to re-broadcast chunks to all currently connected clients (for example, if the world state has changed significantly), call the viewer.update() method. This method iterates through the chunk grid defined by the viewDistance and center and emits the loadChunk event for each chunk to all active sockets.
You can attach a web-based viewer to a Mineflayer bot by calling the plugin entrypoint. This starts an Express server and a Socket.io instance that streams the bot's world and position to connected web clients.
Options:
viewDistance (number, default: 6): The distance from the bot at which blocks are rendered.firstPerson (boolean, default: false): If true, the viewer will include the bot's pitch in position updates.port (number, default: 3000): The port on which the web server will run.prefix (string, default: ''): A URL prefix for the socket.io path.const mineflayer = require('mineflayer')
const viewer = require('prismarine-viewer')
const bot = mineflayer.createBot({
// ... bot config
})
// Attach the viewer
viewer(bot, {
viewDistance: 10,
port: 8080,
firstPerson: true
})You can use the mineflayer module from prismarine-viewer to serve a webserver that allows you to visualize a Mineflayer bot in first or third person. This includes drawing capabilities to visualize paths or other data.
const mineflayer = require('mineflayer')
const mineflayerViewer = require('prismarine-viewer').mineflayer
const bot = mineflayer.createBot({
username: 'Bot'
})
bot.once('spawn', () => {
// Start the viewing server on port 3000
mineflayerViewer(bot, { port: 3000 })
// Example: 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)
}
})
})WorldView represents the world from a specific player or camera perspective. It manages which chunks are loaded based on a viewDistance and a central position.
Constructor:
WorldView(world, viewDistance, position = new Vec3(0, 0, 0), emitter = null)
world: A prismarine-world instance.viewDistance: Number of chunks to consider.position: The camera's position.emitter: An event emitter to connect to (can be null).Key Methods:
listenToBot(bot): Automatically listens to events from a Mineflayer bot.removeListenersFromBot(bot): Stops listening to the specified bot.init(pos): Starts emitting chunks starting from the given position.updatePosition(pos): Changes the camera position and triggers corresponding chunk load/unload events.The listen(emitter) method allows the Viewer to automatically react to world changes. The provided emitter must emit the following events:
entity(e): Updates an entity (expects a prismarine-entity).primitive(p): Updates a Three.js primitive.loadChunk({x, z, chunk}): Adds a chunk column (expects a prismarine-chunk).unloadChunk({x, z}): Removes a chunk column.blockUpdate({pos, stateId}): Updates a block at a specific position.The Viewer also listens for mouseClick({ origin, direction, button }) events from the emitter.
The mineflayer entry point serves a webserver to visualize a bot's surroundings.
Import:
const { mineflayer } = require('prismarine-viewer')Options:
| Option | Description | Default |
|---|---|---|
viewDistance | View radius in chunks | 6 |
firstPerson | Whether to use first-person view | false |
port | Port for the webserver | 3000 |
The standalone entry point serves a webserver to visualize a Minecraft world without requiring a bot.
Import:
const { standalone } = require('prismarine-viewer')Options:
| Option | Description | Default |
|---|---|---|
version | Minecraft version to use | 1.13.2 |
generator | A world generator function (x, y, z) => number | (x, y, z) => 0 |
center | A vec3 to center the view on | new Vec3(0, 0, 0) |
viewDistance | View radius in chunks | 6 |
port | Port for the webserver | 3000 |