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/digEverything.js
Views: 789
1
const { Vec3 } = require('vec3')
2
const assert = require('assert')
3
4
// this test takes about 20min
5
6
const excludedBlocks = [
7
// broken
8
'bed',
9
'double_stone_slab',
10
'wooden_door',
11
'iron_door',
12
'redstone_ore',
13
'lit_redstone_ore',
14
'trapdoor',
15
'double_wooden_slab',
16
'jungle_stairs',
17
'flower_pot',
18
'carrots',
19
'potatoes',
20
'skull',
21
'unpowered_comparator',
22
'standing_banner',
23
'wall_banner',
24
'daylight_detector',
25
'stone_slab2',
26
'spruce_door',
27
'birch_door',
28
'jungle_door',
29
'acacia_door',
30
'dark_oak_door',
31
32
// cannot be placed
33
'piston_extension',
34
'fire',
35
'standing_sign',
36
'reeds',
37
'powered_repeater',
38
'pumpkin_stem',
39
'melon_stem',
40
'brewing_stand',
41
'cauldron',
42
'lit_redstone_lamp',
43
'tripwire',
44
45
// cause problems
46
'mob_spawner',
47
'obsidian'
48
]
49
50
module.exports = (version) => {
51
const registry = require('prismarine-registry')(version)
52
53
const funcs = {}
54
for (const id in registry.blocks) {
55
if (registry.blocks[id] !== undefined) {
56
const block = registry.blocks[id]
57
if (block.diggable && excludedBlocks.indexOf(block.name) === -1) {
58
funcs[block.name] = (blockId => async (bot) => {
59
await digSomething(blockId, bot)
60
})(block.id)
61
}
62
}
63
}
64
65
return funcs
66
}
67
68
async function digSomething (blockId, bot) {
69
const Item = require('prismarine-item')(bot.registry)
70
71
await bot.test.setInventorySlot(36, new Item(blockId, 1, 0))
72
await bot.test.placeBlock(36, bot.entity.position.plus(new Vec3(1, 0, 0)))
73
// TODO: find a better way than this bot.test.wait(200)
74
await bot.test.wait(200)
75
await bot.test.clearInventory()
76
await bot.test.setInventorySlot(36, new Item(bot.registry.itemsByName.diamond_pickaxe.id, 1, 0))
77
await bot.test.becomeSurvival()
78
// we are bare handed
79
await bot.dig(bot.blockAt(bot.entity.position.plus(new Vec3(1, 0, 0))))
80
// make sure that block is gone
81
assert.strictEqual(bot.blockAt(bot.entity.position.plus(new Vec3(1, 0, 0))).type, 0)
82
}
83
84