Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/digWaterSpeed.js
9427 views
1
const { Vec3 } = require('vec3')
2
const assert = require('assert')
3
4
module.exports = () => async (bot) => {
5
const groundY = bot.test.groundY
6
7
const testX = 10
8
const testZ = 10
9
const floorY = groundY
10
11
// --- Setup: teleport and prepare the area ---
12
await bot.test.becomeCreative()
13
await bot.test.teleport(new Vec3(testX, floorY + 2, testZ))
14
await bot.waitForChunksToLoad()
15
16
// Clear the test area and place a solid floor
17
bot.chat(`/fill ${testX - 2} ${floorY} ${testZ - 2} ${testX + 2} ${floorY + 5} ${testZ + 2} air`)
18
await bot.test.wait(500)
19
bot.chat(`/fill ${testX - 2} ${floorY} ${testZ - 2} ${testX + 2} ${floorY} ${testZ + 2} stone`)
20
await bot.test.wait(500)
21
22
// Place a dirt block for digTime testing
23
const digBlockPos = new Vec3(testX + 1, floorY + 1, testZ)
24
await bot.test.setBlock({ x: digBlockPos.x, y: digBlockPos.y, z: digBlockPos.z, blockName: 'dirt' })
25
26
// Teleport bot to the test position
27
await bot.test.teleport(new Vec3(testX, floorY + 1, testZ))
28
await bot.test.wait(500)
29
30
// === Test 1: No water around bot - eye-level block should not be water ===
31
const eyeBlock1 = bot._getBlockAtEyeLevel()
32
bot.test.sayEverywhere(`Test 1 (dry): eye-level block = ${eyeBlock1?.name ?? 'null'}`)
33
assert.notStrictEqual(eyeBlock1?.name, 'water',
34
'Eye-level block should not be water when area is dry')
35
36
// === Test 2: Fill water column around bot - eye-level block should be water ===
37
bot.chat(`/fill ${testX} ${floorY + 1} ${testZ} ${testX} ${floorY + 4} ${testZ} water`)
38
await bot.test.wait(500)
39
40
const eyeBlock2 = bot._getBlockAtEyeLevel()
41
bot.test.sayEverywhere(`Test 2 (submerged): eye-level block = ${eyeBlock2?.name ?? 'null'}`)
42
assert(['water', 'flowing_water'].includes(eyeBlock2?.name),
43
`Eye-level block should be water when submerged, got ${eyeBlock2?.name ?? 'null'}`)
44
45
// === Test 3: Verify isInWater flag no longer affects digTime ===
46
// This is the core behavior change of this PR: digTime should check the block
47
// at eye level instead of using bot.entity.isInWater
48
// Clear water and restore dirt
49
bot.chat(`/fill ${testX - 1} ${floorY + 1} ${testZ - 1} ${testX + 1} ${floorY + 5} ${testZ + 1} air`)
50
await bot.test.wait(500)
51
await bot.test.setBlock({ x: digBlockPos.x, y: digBlockPos.y, z: digBlockPos.z, blockName: 'dirt' })
52
await bot.test.wait(300)
53
54
await bot.test.becomeSurvival()
55
await bot.test.wait(500)
56
57
const block = bot.blockAt(digBlockPos)
58
assert(block && block.name !== 'air', 'Expected a dirt block to measure digTime')
59
60
// Measure baseline digTime
61
const baselineDigTime = bot.digTime(block)
62
63
// Set isInWater=true without actual water blocks - should NOT change digTime
64
const origIsInWater = bot.entity.isInWater
65
bot.entity.isInWater = true
66
const digTimeWithFlag = bot.digTime(block)
67
bot.entity.isInWater = origIsInWater
68
69
bot.test.sayEverywhere(`Test 3: baseline=${baselineDigTime}ms, isInWater=true: ${digTimeWithFlag}ms`)
70
assert.strictEqual(digTimeWithFlag, baselineDigTime,
71
`isInWater flag should not affect digTime (got ${digTimeWithFlag}ms vs baseline ${baselineDigTime}ms). The PR changes digTime to check eye-level water instead.`)
72
73
// Cleanup
74
await bot.test.becomeCreative()
75
bot.chat(`/fill ${testX - 2} ${floorY + 1} ${testZ - 2} ${testX + 2} ${floorY + 5} ${testZ + 2} air`)
76
await bot.test.wait(200)
77
78
bot.test.sayEverywhere('digWaterSpeed: all tests passed')
79
}
80
81