Skip to content

Commit b2e3684

Browse files
feat: brand new default skybox with fog, better daycycle and colors (zardoy#425)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 7043bf4 commit b2e3684

File tree

8 files changed

+372
-74
lines changed

8 files changed

+372
-74
lines changed

README.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,4 @@ Only during development:
233233

234234
- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [DEMO](https://www.classicube.net/server/play/?warned=true)
235235
- [https://m.eaglercraft.com/](EaglerCraft) - Eaglercraft runnable on mobile (real Minecraft in the browser)
236+
- [js-minecraft](https://github.com/LabyStudio/js-minecraft) - An insanely well done clone from the graphical side that inspired many features here

renderer/viewer/lib/worldDataEmitter.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Vec3 } from 'vec3'
77
import { BotEvents } from 'mineflayer'
88
import { proxy } from 'valtio'
99
import TypedEmitter from 'typed-emitter'
10+
import { Biome } from 'minecraft-data'
1011
import { delayedIterator } from '../../playground/shared'
1112
import { chunkPos } from './simpleUtils'
1213

@@ -28,6 +29,8 @@ export type WorldDataEmitterEvents = {
2829
updateLight: (data: { pos: Vec3 }) => void
2930
onWorldSwitch: () => void
3031
end: () => void
32+
biomeUpdate: (data: { biome: Biome }) => void
33+
biomeReset: () => void
3134
}
3235

3336
export class WorldDataEmitterWorker extends (EventEmitter as new () => TypedEmitter<WorldDataEmitterEvents>) {
@@ -360,8 +363,37 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
360363
delete this.debugChunksInfo[`${pos.x},${pos.z}`]
361364
}
362365

366+
lastBiomeId: number | null = null
367+
368+
udpateBiome (pos: Vec3) {
369+
try {
370+
const biomeId = this.world.getBiome(pos)
371+
if (biomeId !== this.lastBiomeId) {
372+
this.lastBiomeId = biomeId
373+
const biomeData = loadedData.biomes[biomeId]
374+
if (biomeData) {
375+
this.emitter.emit('biomeUpdate', {
376+
biome: biomeData
377+
})
378+
} else {
379+
// unknown biome
380+
this.emitter.emit('biomeReset')
381+
}
382+
}
383+
} catch (e) {
384+
console.error('error updating biome', e)
385+
}
386+
}
387+
388+
lastPosCheck: Vec3 | null = null
363389
async updatePosition (pos: Vec3, force = false) {
364390
if (!this.allowPositionUpdate) return
391+
const posFloored = pos.floored()
392+
if (!force && this.lastPosCheck && this.lastPosCheck.equals(posFloored)) return
393+
this.lastPosCheck = posFloored
394+
395+
this.udpateBiome(pos)
396+
365397
const [lastX, lastZ] = chunkPos(this.lastPos)
366398
const [botX, botZ] = chunkPos(pos)
367399
if (lastX !== botX || lastZ !== botZ || force) {

renderer/viewer/lib/worldrendererCommon.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,44 @@ const toMajorVersion = version => {
3232
export const worldCleanup = buildCleanupDecorator('resetWorld')
3333

3434
export const defaultWorldRendererConfig = {
35+
// Debug settings
3536
showChunkBorders: false,
37+
enableDebugOverlay: false,
38+
39+
// Performance settings
3640
mesherWorkers: 4,
37-
isPlayground: false,
38-
renderEars: true,
39-
skinTexturesProxy: undefined as string | undefined,
40-
// game renderer setting actually
41-
showHand: false,
42-
viewBobbing: false,
43-
extraBlockRenderers: true,
44-
clipWorldBelowY: undefined as number | undefined,
41+
addChunksBatchWaitTime: 200,
42+
_experimentalSmoothChunkLoading: true,
43+
_renderByChunks: false,
44+
45+
// Rendering engine settings
46+
dayCycle: true,
4547
smoothLighting: true,
4648
enableLighting: true,
4749
starfield: true,
48-
addChunksBatchWaitTime: 200,
49-
vrSupport: true,
50-
vrPageGameRendering: true,
5150
renderEntities: true,
51+
extraBlockRenderers: true,
52+
foreground: true,
5253
fov: 75,
53-
fetchPlayerSkins: true,
54+
volume: 1,
55+
56+
// Camera visual related settings
57+
showHand: false,
58+
viewBobbing: false,
59+
renderEars: true,
5460
highlightBlockColor: 'blue',
55-
foreground: true,
56-
enableDebugOverlay: false,
57-
_experimentalSmoothChunkLoading: true,
58-
_renderByChunks: false,
59-
volume: 1
61+
62+
// Player models
63+
fetchPlayerSkins: true,
64+
skinTexturesProxy: undefined as string | undefined,
65+
66+
// VR settings
67+
vrSupport: true,
68+
vrPageGameRendering: true,
69+
70+
// World settings
71+
clipWorldBelowY: undefined as number | undefined,
72+
isPlayground: false
6073
}
6174

6275
export type WorldRendererConfig = typeof defaultWorldRendererConfig
@@ -496,6 +509,10 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
496509

497510
timeUpdated? (newTime: number): void
498511

512+
biomeUpdated? (biome: any): void
513+
514+
biomeReset? (): void
515+
499516
updateViewerPosition (pos: Vec3) {
500517
this.viewerChunkPosition = pos
501518
for (const [key, value] of Object.entries(this.loadedChunks)) {
@@ -817,12 +834,9 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
817834
})
818835

819836
worldEmitter.on('time', (timeOfDay) => {
837+
if (!this.worldRendererConfig.dayCycle) return
820838
this.timeUpdated?.(timeOfDay)
821839

822-
if (timeOfDay < 0 || timeOfDay > 24_000) {
823-
throw new Error('Invalid time of day. It should be between 0 and 24000.')
824-
}
825-
826840
this.timeOfTheDay = timeOfDay
827841

828842
// if (this.worldRendererConfig.skyLight === skyLight) return
@@ -831,6 +845,14 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
831845
// (this).rerenderAllChunks?.()
832846
// }
833847
})
848+
849+
worldEmitter.on('biomeUpdate', ({ biome }) => {
850+
this.biomeUpdated?.(biome)
851+
})
852+
853+
worldEmitter.on('biomeReset', () => {
854+
this.biomeReset?.()
855+
})
834856
}
835857

836858
setBlockStateIdInner (pos: Vec3, stateId: number | undefined, needAoRecalculation = true) {

0 commit comments

Comments
 (0)