Viewer library provides Viewer and WorldView which together make it possible to render a minecraft world.
The viewer exposes methods to render a world to a three.js renderer.
Build the viewer.
- renderer is a WebGLRenderer instance
the currently used minecraft version
sets the minecraft version
- version is a string such as "1.16.4"
Returns false and stop there if the version is not supported
Adds a column
- x is a chunk position
- z is a chunk position
- chunk is a prismarine-chunk
Removes a column
- x is a chunk position
- z is a chunk position
Set a block at this position
- pos is a Vec3
- stateId is a number
Updates an entity
- e is a prismarine-entity
Updates a primitive
- p is a Three.js primitive
Sets the first person camera
- pos is a Vec3 (if pos is null, only yaw and pitch will be updated)
- yaw is in degrees
- pitch is in degrees
listen to an emitter and applies its modification the emitter should emit these events:
- entity(e) ; updates an entity
- primitive(p) ; updates a primitive
- loadChunk({x, z, chunk}) ; add a column
- unloadChunk({x, z}) ; removes a column
- blockUpdate({pos, stateId}) ; update a block it also listen to these events:
- mouseClick({ origin, direction, button })
Update the world. This need to be called in the animate function, just before the render.
Returns a promise that resolve once all sections marked dirty have been rendered by the worker threads. Can be used to wait for chunks to 'appear'.
WorldView represents the world from a player/camera point of view
Build a WorldView
- world is a prismarine-world
- viewDistance is the number of considered chunks
- position is the position of the camera
- emitter is the event emitter to connect (could be null to set emitter to itself or a socket)
listen to events from a mineflayer bot
stop listening to the bot event
start emitting chunks from that position
emit chunks at this position
emit unload chunk at this position
change the camera position, and emit corresponding events
Default third person controls based on three.js OrbitControls. Refer to the documentation here. Controls are applied on animation loop, so you need to call controls.update()
in your render loop.
The keyboard controls to use. You can provide an array for any of the keys that bind to an action. Defaults:
this.controlMap = {
MOVE_FORWARD: ['KeyW', 'KeyZ'],
MOVE_BACKWARD: 'KeyS',
MOVE_LEFT: ['KeyA', 'KeyQ'],
MOVE_RIGHT: 'KeyD',
MOVE_DOWN: 'ShiftLeft',
MOVE_UP: 'Space'
}
Sets the center point for rotations
How much the y axis is offset for each vertical translation (movement up and down). To control panning speed for the x/z axis, adjust .keyPanSpeed
Booleans to toggle touch interaction
Enables and disables DOM event handling. Useful if you only want to programatically adjust the controls.