Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/nether.js
9427 views
1
const assert = require('assert')
2
const Vec3 = require('vec3')
3
const { once, sleep, onceWithCleanup } = require('../../lib/promise_utils')
4
5
module.exports = () => async (bot) => {
6
// Test spawn event on death
7
const Item = require('prismarine-item')(bot.registry)
8
const portalName = bot.registry.blocksByName.nether_portal ? 'nether_portal' : 'portal'
9
10
let signItem = null
11
for (const name in bot.registry.itemsByName) {
12
if (name.includes('sign') && !name.includes('hanging')) signItem = bot.registry.itemsByName[name]
13
}
14
assert.notStrictEqual(signItem, null)
15
16
const p = new Promise((resolve, reject) => {
17
bot._client.once('open_sign_entity', (packet) => {
18
console.log('Open sign', packet)
19
const sign = bot.blockAt(new Vec3(packet.location))
20
bot.updateSign(sign, '1\n2\n3\n')
21
22
setTimeout(() => {
23
// Get updated sign
24
const sign = bot.blockAt(bot.entity.position)
25
console.log('Updated sign', sign)
26
27
assert.strictEqual(sign.signText.trimEnd(), '1\n2\n3')
28
29
if (sign.blockEntity) {
30
// Check block update
31
bot.activateBlock(sign)
32
assert.notStrictEqual(sign.blockEntity, undefined)
33
}
34
35
bot.chat(`/setblock ~ ~ ~ ${portalName}`)
36
onceWithCleanup(bot, 'spawn', { timeout: 30000 }).then(resolve).catch(reject)
37
}, 500)
38
})
39
})
40
41
bot.chat(`/setblock ~ ~ ~ ${portalName}`)
42
await onceWithCleanup(bot, 'spawn', { timeout: 30000 })
43
bot.test.sayEverywhere('/tp 0 128 0')
44
45
await once(bot, 'forcedMove')
46
await bot.waitForChunksToLoad()
47
48
// Poll until the block below is loaded and non-air before placing.
49
// On slow CI, chunks may report as loaded before block data is ready.
50
let lowerBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0))
51
while (!lowerBlock || lowerBlock.name === 'air') {
52
await sleep(100)
53
lowerBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0))
54
}
55
56
await bot.lookAt(lowerBlock.position, true)
57
await bot.test.setInventorySlot(36, new Item(signItem.id, 1, 0))
58
await bot.placeBlock(lowerBlock, new Vec3(0, 1, 0))
59
await p
60
}
61
62