Skip to content

Commit

Permalink
respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerelSchwerz committed Feb 26, 2024
1 parent 8518325 commit 85105d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ Remove the primitive with the given id from the display.

Stop the server and disconnect users.

#### bot.viewer.on('onRender', (fps) => void)

Provides an approximation of the current highest fps of any client connected to the server.

Use this event for events that should be fired at least once per render cycle.



## Tests

`npm run jestTest -- -t "1.9.4"`
2 changes: 1 addition & 1 deletion examples/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bot = mineflayer.createBot({
version: process.argv[4] ?? '1.16.5'
})

bot.once('spawn', async () => {
bot.once('spawn', () => {
mineflayerViewer(bot, { port: 3000 })

const path = [bot.entity.position.clone()]
Expand Down
32 changes: 32 additions & 0 deletions examples/render_bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const mineflayer = require('mineflayer')
const mineflayerViewer = require('prismarine-viewer').mineflayer

const bot = mineflayer.createBot({
username: 'Bot',
host: process.argv[2],
port: isNaN(parseInt(process.argv[3])) ? 25565 : parseInt(process.argv[3]),
version: process.argv[4] ?? '1.16.5'
})

bot.once('spawn', () => {
mineflayerViewer(bot, { port: 3000 })

// approximate maximum FPS of all clients connected to our viewer
bot.viewer.on('onRender', (fps) => {
// do something every frame

// random offset of bot position, +/5 in x and z, +5 in y
const pos = bot.entity.position.offset(Math.random() * 10 - 5, 5, Math.random() * 10 - 5)

bot.viewer.erase('posExample')
bot.viewer.drawBoxGrid('posExample', pos, pos.offset(1, 1, 1), 'aqua')
})

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)
}
})
})

0 comments on commit 85105d4

Please sign in to comment.