const canvas = createCanvas(width, height)
nicolasvac opened this issue · 2 comments
nicolasvac commented
Code:
const mineflayer = require('mineflayer')
const mineflayerViewer = require('prismarine-viewer').headless
const bot = mineflayer.createBot({
username: 'Bot',
host: "127.0.0.1",
port: 25565
})
bot.once('spawn', () => {
// rtmp stream
const client = mineflayerViewer(bot, {output: 'rtmp://127.0.0.1:8089', frames: -1, width: 512, height: 512})
bot.setControlState('jump', true)
client.on('data', (data) => {
const key = parseInt(data.toString(), 10)
// console.log(key)
bot.clearControlStates()
if (key === 32) { // space
bot.setControlState('jump', true)
} else if (key === 81) { // left arrow
bot.entity.yaw += 0.1
} else if (key === 82) { // top arrow
bot.setControlState('forward', true)
} else if (key === 83) { // right arrow
bot.entity.yaw -= 0.1
} else if (key === 84) { // down arrow
bot.setControlState('back', true)
}
})
})
Error:
D:\BigBox\bots\prismarine-test\node_modules\prismarine-viewer\lib\headless.js:18
const canvas = createCanvas(width, height)
^
TypeError: createCanvas is not a function
at module.exports (D:\BigBox\bots\prismarine-test\node_modules\prismarine-viewer\lib\headless.js:18:18)
at EventEmitter.<anonymous> (D:\BigBox\bots\prismarine-test\index.js:12:20)
at Object.onceWrapper (node:events:509:28)
at EventEmitter.emit (node:events:402:35)
at Client.<anonymous> (D:\BigBox\bots\prismarine-test\node_modules\mineflayer\lib\plugins\health.js:13:11)
at Object.onceWrapper (node:events:510:26)
at Client.emit (node:events:402:35)
at FullPacketParser.<anonymous> (D:\BigBox\bots\prismarine-test\node_modules\minecraft-protocol\src\client.js:91:12)
at FullPacketParser.emit (node:events:390:28)
at addChunk (D:\BigBox\bots\prismarine-test\node_modules\readable-stream\lib\_stream_readable.js:298:12)
Process finished with exit code 1
dependencies:
"dependencies": {
"mineflayer": "^3.15.0",
"prismarine-viewer": "^1.22.0"
}
OBNinjaa commented
Try npm install node-canvas-webgl
IceTank commented
You need node-canvas-webgl
installed to run prismarine-viewer in headless node. But that install will fail on windows unless you have extra windows build tools installed. It is easier to install a virtual machine and install prismarine-viewer in that. Uses less space too.