Skip to content

Commit 1f95aaa

Browse files
authored
Fix "flowing" liquids not being included (#105)
* Fix "flowing" liquids not being included * Fix flowing water not having a flow + Cleaned up a little logic * Resolve #105 (comment) * Resolve #105 (comment)
1 parent dd159da commit 1f95aaa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function Physics (mcData, world) {
3030
const soulsandId = blocksByName.soul_sand.id
3131
const honeyblockId = blocksByName.honey_block ? blocksByName.honey_block.id : -1 // 1.15+
3232
const webId = blocksByName.cobweb ? blocksByName.cobweb.id : blocksByName.web.id
33-
const waterId = blocksByName.water.id
34-
const lavaId = blocksByName.lava.id
33+
const waterIds = [blocksByName.water.id, blocksByName.flowing_water ? blocksByName.flowing_water.id : -1]
34+
const lavaIds = [blocksByName.lava.id, blocksByName.flowing_lava ? blocksByName.flowing_lava.id : -1]
3535
const ladderId = blocksByName.ladder.id
3636
const vineId = blocksByName.vine.id
3737
const waterLike = new Set()
@@ -475,13 +475,13 @@ function Physics (mcData, world) {
475475
}
476476
}
477477

478-
function isMaterialInBB (world, queryBB, type) {
478+
function isMaterialInBB (world, queryBB, types) {
479479
const cursor = new Vec3(0, 0, 0)
480480
for (cursor.y = Math.floor(queryBB.minY); cursor.y <= Math.floor(queryBB.maxY); cursor.y++) {
481481
for (cursor.z = Math.floor(queryBB.minZ); cursor.z <= Math.floor(queryBB.maxZ); cursor.z++) {
482482
for (cursor.x = Math.floor(queryBB.minX); cursor.x <= Math.floor(queryBB.maxX); cursor.x++) {
483483
const block = world.getBlock(cursor)
484-
if (block && block.type === type) return true
484+
if (block && types.includes(block.type)) return true
485485
}
486486
}
487487
}
@@ -496,7 +496,7 @@ function Physics (mcData, world) {
496496
if (!block) return -1
497497
if (waterLike.has(block.type)) return 0
498498
if (block.getProperties().waterlogged) return 0
499-
if (block.type !== waterId) return -1
499+
if (!waterIds.includes(block.type)) return -1
500500
const meta = block.metadata
501501
return meta >= 8 ? 0 : meta
502502
}
@@ -543,7 +543,7 @@ function Physics (mcData, world) {
543543
for (cursor.z = Math.floor(bb.minZ); cursor.z <= Math.floor(bb.maxZ); cursor.z++) {
544544
for (cursor.x = Math.floor(bb.minX); cursor.x <= Math.floor(bb.maxX); cursor.x++) {
545545
const block = world.getBlock(cursor)
546-
if (block && (block.type === waterId || waterLike.has(block.type) || block.getProperties().waterlogged)) {
546+
if (block && (waterIds.includes(block.type) || waterLike.has(block.type) || block.getProperties().waterlogged)) {
547547
const waterLevel = cursor.y + 1 - getLiquidHeightPcent(block)
548548
if (Math.ceil(bb.maxY) >= waterLevel) waterBlocks.push(block)
549549
}
@@ -579,7 +579,7 @@ function Physics (mcData, world) {
579579
const lavaBB = getPlayerBB(pos).contract(0.1, 0.4, 0.1)
580580

581581
entity.isInWater = isInWaterApplyCurrent(world, waterBB, vel)
582-
entity.isInLava = isMaterialInBB(world, lavaBB, lavaId)
582+
entity.isInLava = isMaterialInBB(world, lavaBB, lavaIds)
583583

584584
// Reset velocity component if it falls under the threshold
585585
if (Math.abs(vel.x) < physics.negligeableVelocity) vel.x = 0

0 commit comments

Comments
 (0)