Skip to content

Commit f126f56

Browse files
committed
fix: fix visual gaps between blocks of water!
1 parent 1b20845 commit f126f56

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

renderer/viewer/lib/mesher/models.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const getVec = (v: Vec3, dir: Vec3) => {
132132
return v.plus(dir)
133133
}
134134

135-
function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: Record<string, any>, isRealWater: boolean) {
135+
function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: MesherGeometryOutput, isRealWater: boolean) {
136136
const heights: number[] = []
137137
for (let z = -1; z <= 1; z++) {
138138
for (let x = -1; x <= 1; x++) {
@@ -192,13 +192,14 @@ function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, typ
192192

193193
for (const pos of corners) {
194194
const height = cornerHeights[pos[2] * 2 + pos[0]]
195-
attr.t_positions.push(
196-
(pos[0] ? 0.999 : 0.001) + (cursor.x & 15) - 8,
197-
(pos[1] ? height - 0.001 : 0.001) + (cursor.y & 15) - 8,
198-
(pos[2] ? 0.999 : 0.001) + (cursor.z & 15) - 8
195+
const OFFSET = 0.0001
196+
attr.t_positions!.push(
197+
(pos[0] ? 1 - OFFSET : OFFSET) + (cursor.x & 15) - 8,
198+
(pos[1] ? height - OFFSET : OFFSET) + (cursor.y & 15) - 8,
199+
(pos[2] ? 1 - OFFSET : OFFSET) + (cursor.z & 15) - 8
199200
)
200-
attr.t_normals.push(...dir)
201-
attr.t_uvs.push(pos[3] * su + u, pos[4] * sv * (pos[1] ? 1 : height) + v)
201+
attr.t_normals!.push(...dir)
202+
attr.t_uvs!.push(pos[3] * su + u, pos[4] * sv * (pos[1] ? 1 : height) + v)
202203

203204
let cornerLightResult = baseLight
204205
if (world.config.smoothLighting) {
@@ -223,7 +224,7 @@ function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, typ
223224
}
224225

225226
// Apply light value to tint
226-
attr.t_colors.push(tint[0] * cornerLightResult, tint[1] * cornerLightResult, tint[2] * cornerLightResult)
227+
attr.t_colors!.push(tint[0] * cornerLightResult, tint[1] * cornerLightResult, tint[2] * cornerLightResult)
227228
}
228229
}
229230
}
@@ -487,7 +488,7 @@ const isBlockWaterlogged = (block: Block) => {
487488
}
488489

489490
let unknownBlockModel: BlockModelPartsResolved
490-
export function getSectionGeometry (sx, sy, sz, world: World) {
491+
export function getSectionGeometry (sx: number, sy: number, sz: number, world: World) {
491492
let delayedRender = [] as Array<() => void>
492493

493494
const attr: MesherGeometryOutput = {

renderer/viewer/lib/worldDataEmitter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
197197
async init (pos: Vec3) {
198198
this.updateViewDistance(this.viewDistance)
199199
this.emitter.emit('chunkPosUpdate', { pos })
200-
this.emitter.emit('time', bot.time.timeOfDay)
200+
if (bot?.time?.timeOfDay) {
201+
this.emitter.emit('time', bot.time.timeOfDay)
202+
}
201203
this.emitterGotConnected()
202204
const [botX, botZ] = chunkPos(pos)
203205

src/appViewer.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { WorldDataEmitter, WorldDataEmitterWorker } from 'renderer/viewer/lib/worldDataEmitter'
2-
import { PlayerStateRenderer } from 'renderer/viewer/lib/basePlayerState'
2+
import { getInitialPlayerState, PlayerStateRenderer } from 'renderer/viewer/lib/basePlayerState'
33
import { subscribeKey } from 'valtio/utils'
44
import { defaultWorldRendererConfig, WorldRendererConfig } from 'renderer/viewer/lib/worldrendererCommon'
55
import { Vec3 } from 'vec3'
@@ -281,19 +281,31 @@ const initialMenuStart = async () => {
281281
if (appViewer.currentDisplay === 'world') {
282282
appViewer.resetBackend(true)
283283
}
284-
appViewer.startPanorama()
284+
const demo = new URLSearchParams(window.location.search).get('demo')
285+
if (!demo) {
286+
appViewer.startPanorama()
287+
return
288+
}
285289

286290
// const version = '1.18.2'
287-
// const version = '1.21.4'
288-
// await appViewer.resourcesManager.loadMcData(version)
289-
// const world = getSyncWorld(version)
290-
// world.setBlockStateId(new Vec3(0, 64, 0), loadedData.blocksByName.water.defaultState)
291-
// appViewer.resourcesManager.currentConfig = { version }
292-
// await appViewer.resourcesManager.updateAssetsData({})
293-
// appViewer.playerState = new BasePlayerState() as any
294-
// await appViewer.startWorld(world, 3)
295-
// appViewer.backend?.updateCamera(new Vec3(0, 64, 2), 0, 0)
296-
// void appViewer.worldView!.init(new Vec3(0, 64, 0))
291+
const version = '1.21.4'
292+
const { loadMinecraftData } = await import('./connect')
293+
const { getSyncWorld } = await import('../renderer/playground/shared')
294+
await loadMinecraftData(version)
295+
const world = getSyncWorld(version)
296+
world.setBlockStateId(new Vec3(0, 64, 0), loadedData.blocksByName.water.defaultState)
297+
world.setBlockStateId(new Vec3(1, 64, 0), loadedData.blocksByName.water.defaultState)
298+
world.setBlockStateId(new Vec3(1, 64, 1), loadedData.blocksByName.water.defaultState)
299+
world.setBlockStateId(new Vec3(0, 64, 1), loadedData.blocksByName.water.defaultState)
300+
world.setBlockStateId(new Vec3(-1, 64, -1), loadedData.blocksByName.water.defaultState)
301+
world.setBlockStateId(new Vec3(-1, 64, 0), loadedData.blocksByName.water.defaultState)
302+
world.setBlockStateId(new Vec3(0, 64, -1), loadedData.blocksByName.water.defaultState)
303+
appViewer.resourcesManager.currentConfig = { version }
304+
appViewer.playerState.reactive = getInitialPlayerState()
305+
await appViewer.resourcesManager.updateAssetsData({})
306+
await appViewer.startWorld(world, 3)
307+
appViewer.backend!.updateCamera(new Vec3(0, 65.7, 0), 0, -Math.PI / 2) // Y+1 and pitch = PI/2 to look down
308+
void appViewer.worldView!.init(new Vec3(0, 64, 0))
297309
}
298310
window.initialMenuStart = initialMenuStart
299311

src/reactUi.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,17 @@ const PerComponentErrorBoundary = ({ children }) => {
276276
</ErrorBoundary>)
277277
}
278278

279-
renderToDom(<App />, {
280-
strictMode: false,
281-
selector: '#react-root',
282-
})
279+
if (!new URLSearchParams(window.location.search).get('no-ui')) {
280+
renderToDom(<App />, {
281+
strictMode: false,
282+
selector: '#react-root',
283+
})
284+
}
283285

284286
disableReactProfiling()
285287
function disableReactProfiling () {
288+
if (window.reactPerfPatchApplied) return
289+
window.reactPerfPatchApplied = true
286290
//@ts-expect-error
287291
window.performance.markOrig = window.performance.mark
288292
//@ts-expect-error

0 commit comments

Comments
 (0)