Path: blob/master/test/externalTests/digWaterSpeed.js
9427 views
const { Vec3 } = require('vec3')1const assert = require('assert')23module.exports = () => async (bot) => {4const groundY = bot.test.groundY56const testX = 107const testZ = 108const floorY = groundY910// --- Setup: teleport and prepare the area ---11await bot.test.becomeCreative()12await bot.test.teleport(new Vec3(testX, floorY + 2, testZ))13await bot.waitForChunksToLoad()1415// Clear the test area and place a solid floor16bot.chat(`/fill ${testX - 2} ${floorY} ${testZ - 2} ${testX + 2} ${floorY + 5} ${testZ + 2} air`)17await bot.test.wait(500)18bot.chat(`/fill ${testX - 2} ${floorY} ${testZ - 2} ${testX + 2} ${floorY} ${testZ + 2} stone`)19await bot.test.wait(500)2021// Place a dirt block for digTime testing22const digBlockPos = new Vec3(testX + 1, floorY + 1, testZ)23await bot.test.setBlock({ x: digBlockPos.x, y: digBlockPos.y, z: digBlockPos.z, blockName: 'dirt' })2425// Teleport bot to the test position26await bot.test.teleport(new Vec3(testX, floorY + 1, testZ))27await bot.test.wait(500)2829// === Test 1: No water around bot - eye-level block should not be water ===30const eyeBlock1 = bot._getBlockAtEyeLevel()31bot.test.sayEverywhere(`Test 1 (dry): eye-level block = ${eyeBlock1?.name ?? 'null'}`)32assert.notStrictEqual(eyeBlock1?.name, 'water',33'Eye-level block should not be water when area is dry')3435// === Test 2: Fill water column around bot - eye-level block should be water ===36bot.chat(`/fill ${testX} ${floorY + 1} ${testZ} ${testX} ${floorY + 4} ${testZ} water`)37await bot.test.wait(500)3839const eyeBlock2 = bot._getBlockAtEyeLevel()40bot.test.sayEverywhere(`Test 2 (submerged): eye-level block = ${eyeBlock2?.name ?? 'null'}`)41assert(['water', 'flowing_water'].includes(eyeBlock2?.name),42`Eye-level block should be water when submerged, got ${eyeBlock2?.name ?? 'null'}`)4344// === Test 3: Verify isInWater flag no longer affects digTime ===45// This is the core behavior change of this PR: digTime should check the block46// at eye level instead of using bot.entity.isInWater47// Clear water and restore dirt48bot.chat(`/fill ${testX - 1} ${floorY + 1} ${testZ - 1} ${testX + 1} ${floorY + 5} ${testZ + 1} air`)49await bot.test.wait(500)50await bot.test.setBlock({ x: digBlockPos.x, y: digBlockPos.y, z: digBlockPos.z, blockName: 'dirt' })51await bot.test.wait(300)5253await bot.test.becomeSurvival()54await bot.test.wait(500)5556const block = bot.blockAt(digBlockPos)57assert(block && block.name !== 'air', 'Expected a dirt block to measure digTime')5859// Measure baseline digTime60const baselineDigTime = bot.digTime(block)6162// Set isInWater=true without actual water blocks - should NOT change digTime63const origIsInWater = bot.entity.isInWater64bot.entity.isInWater = true65const digTimeWithFlag = bot.digTime(block)66bot.entity.isInWater = origIsInWater6768bot.test.sayEverywhere(`Test 3: baseline=${baselineDigTime}ms, isInWater=true: ${digTimeWithFlag}ms`)69assert.strictEqual(digTimeWithFlag, baselineDigTime,70`isInWater flag should not affect digTime (got ${digTimeWithFlag}ms vs baseline ${baselineDigTime}ms). The PR changes digTime to check eye-level water instead.`)7172// Cleanup73await bot.test.becomeCreative()74bot.chat(`/fill ${testX - 2} ${floorY + 1} ${testZ - 2} ${testX + 2} ${floorY + 5} ${testZ + 2} air`)75await bot.test.wait(200)7677bot.test.sayEverywhere('digWaterSpeed: all tests passed')78}798081