Skip to content

Commit bf79086

Browse files
committed
fix: finally fix plants rendering in underwater and near water!
1 parent a977d09 commit bf79086

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: renderer/viewer/lib/mesher/models.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Vec3 } from 'vec3'
22
import worldBlockProvider, { WorldBlockProvider } from 'mc-assets/dist/worldBlockProvider'
33
import legacyJson from '../../../../src/preflatMap.json'
44
import { BlockType } from '../../../playground/shared'
5-
import { World, BlockModelPartsResolved, WorldBlock as Block } from './world'
5+
import { World, BlockModelPartsResolved, WorldBlock as Block, WorldBlock } from './world'
66
import { BlockElement, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon'
77
import { INVISIBLE_BLOCKS } from './worldConstants'
88
import { MesherGeometryOutput, HighestBlockInfo } from './shared'
@@ -103,7 +103,8 @@ function tintToGl (tint) {
103103
return [r / 255, g / 255, b / 255]
104104
}
105105

106-
function getLiquidRenderHeight (world, block, type, pos) {
106+
function getLiquidRenderHeight (world: World, block: WorldBlock | null, type: number, pos: Vec3, isRealWater: boolean) {
107+
if (!isRealWater || (block && isBlockWaterlogged(block))) return 8 / 9
107108
if (!block || block.type !== type) return 1 / 9
108109
if (block.metadata === 0) { // source block
109110
const blockAbove = world.getBlock(pos.offset(0, 1, 0))
@@ -124,12 +125,12 @@ const isCube = (block: Block) => {
124125
}))
125126
}
126127

127-
function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: Record<string, any>) {
128+
function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: Record<string, any>, isRealWater: boolean) {
128129
const heights: number[] = []
129130
for (let z = -1; z <= 1; z++) {
130131
for (let x = -1; x <= 1; x++) {
131132
const pos = cursor.offset(x, 0, z)
132-
heights.push(getLiquidRenderHeight(world, world.getBlock(pos), type, pos))
133+
heights.push(getLiquidRenderHeight(world, world.getBlock(pos), type, pos, isRealWater))
133134
}
134135
}
135136
const cornerHeights = [
@@ -147,9 +148,8 @@ function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, typ
147148
const neighborPos = cursor.offset(...dir as [number, number, number])
148149
const neighbor = world.getBlock(neighborPos)
149150
if (!neighbor) continue
150-
if (neighbor.type === type) continue
151-
const isGlass = neighbor.name.includes('glass')
152-
if ((isCube(neighbor) && !isUp) || neighbor.material === 'plant' || neighbor.getProperties().waterlogged) continue
151+
if (neighbor.type === type || (water && (neighbor.name === 'water' || isBlockWaterlogged(neighbor)))) continue
152+
if (isCube(neighbor) && !isUp) continue
153153

154154
let tint = [1, 1, 1]
155155
if (water) {
@@ -539,11 +539,11 @@ export function getSectionGeometry (sx, sy, sz, world: World) {
539539
const pos = cursor.clone()
540540
// eslint-disable-next-line @typescript-eslint/no-loop-func
541541
delayedRender.push(() => {
542-
renderLiquid(world, pos, blockProvider.getTextureInfo('water_still'), block.type, biome, true, attr)
542+
renderLiquid(world, pos, blockProvider.getTextureInfo('water_still'), block.type, biome, true, attr, !isWaterlogged)
543543
})
544544
attr.blocksCount++
545545
} else if (block.name === 'lava') {
546-
renderLiquid(world, cursor, blockProvider.getTextureInfo('lava_still'), block.type, biome, false, attr)
546+
renderLiquid(world, cursor, blockProvider.getTextureInfo('lava_still'), block.type, biome, false, attr, false)
547547
attr.blocksCount++
548548
}
549549
if (block.name !== 'water' && block.name !== 'lava' && !INVISIBLE_BLOCKS.has(block.name)) {

0 commit comments

Comments
 (0)