CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/enchanting.js
Views: 789
1
const assert = require('assert')
2
3
module.exports = () => async (bot) => {
4
const Item = require('prismarine-item')(bot.registry)
5
6
const lapisId = bot.registry.itemsByName.lapis_lazuli ? bot.registry.itemsByName.lapis_lazuli.id : bot.registry.itemsByName.dye.id
7
const lapisData = bot.registry.itemsByName.lapis_lazuli ? 0 : 4
8
9
const enchantSlot = 2
10
11
if (bot.registry.isNewerOrEqualTo('1.13')) {
12
bot.chat(`/xp set ${bot.username} 999 levels`)
13
} else {
14
bot.chat(`/xp 999L ${bot.username}`)
15
}
16
await bot.test.setInventorySlot(36, new Item(bot.registry.itemsByName.bookshelf.id, 15))
17
await bot.test.setInventorySlot(37, new Item(bot.registry.itemsByName.enchanting_table.id, 1))
18
await bot.test.setInventorySlot(38, new Item(bot.registry.itemsByName.diamond_sword.id, 1))
19
await bot.test.setInventorySlot(39, new Item(lapisId, enchantSlot + 1, lapisData))
20
21
await bot.test.becomeSurvival()
22
23
// Place enchanting table
24
await bot.test.placeBlock(37, bot.entity.position.offset(1, 0, 0))
25
26
// Place bookshelfs
27
await bot.test.placeBlock(36, bot.entity.position.offset(3, 0, 2))
28
await bot.test.placeBlock(36, bot.entity.position.offset(3, 0, 1))
29
await bot.test.placeBlock(36, bot.entity.position.offset(3, 0, 0))
30
await bot.test.placeBlock(36, bot.entity.position.offset(3, 0, -1))
31
await bot.test.placeBlock(36, bot.entity.position.offset(3, 0, -2))
32
await bot.test.placeBlock(36, bot.entity.position.offset(2, 0, -2))
33
await bot.test.placeBlock(36, bot.entity.position.offset(1, 0, -2))
34
await bot.test.placeBlock(36, bot.entity.position.offset(0, 0, -2))
35
await bot.test.placeBlock(36, bot.entity.position.offset(-1, 0, -2))
36
await bot.test.placeBlock(36, bot.entity.position.offset(-1, 0, -1))
37
await bot.test.placeBlock(36, bot.entity.position.offset(-1, 0, 1))
38
await bot.test.placeBlock(36, bot.entity.position.offset(-1, 0, 2))
39
await bot.test.placeBlock(36, bot.entity.position.offset(0, 0, 2))
40
await bot.test.placeBlock(36, bot.entity.position.offset(1, 0, 2))
41
await bot.test.placeBlock(36, bot.entity.position.offset(2, 0, 2))
42
43
const b = bot.findBlock({ matching: bot.registry.blocksByName.enchanting_table.id })
44
const enchantingTable = await bot.openEnchantmentTable(b)
45
46
console.log('Opened enchanting table')
47
48
const lapis = enchantingTable.findInventoryItem(lapisId)
49
await enchantingTable.putLapis(lapis)
50
51
const sword = enchantingTable.findInventoryItem(bot.registry.itemsByName.diamond_sword.id)
52
53
await enchantingTable.putTargetItem(sword)
54
55
console.log('Table ready')
56
await enchantingTable.enchant(enchantSlot)
57
const result = await enchantingTable.takeTargetItem()
58
59
assert.notStrictEqual(result.nbt, undefined)
60
61
enchantingTable.close()
62
}
63
64