Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,4 @@ Only during development:

- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [DEMO](https://www.classicube.net/server/play/?warned=true)
- [https://m.eaglercraft.com/](EaglerCraft) - Eaglercraft runnable on mobile (real Minecraft in the browser)
- [js-minecraft](https://github.com/LabyStudio/js-minecraft) - An insanely well done clone from the graphical side that inspired many features here
32 changes: 32 additions & 0 deletions renderer/viewer/lib/worldDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Vec3 } from 'vec3'
import { BotEvents } from 'mineflayer'
import { proxy } from 'valtio'
import TypedEmitter from 'typed-emitter'
import { Biome } from 'minecraft-data'
import { delayedIterator } from '../../playground/shared'
import { chunkPos } from './simpleUtils'

Expand All @@ -28,6 +29,8 @@ export type WorldDataEmitterEvents = {
updateLight: (data: { pos: Vec3 }) => void
onWorldSwitch: () => void
end: () => void
biomeUpdate: (data: { biome: Biome }) => void
biomeReset: () => void
}

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

lastBiomeId: number | null = null

udpateBiome (pos: Vec3) {
try {
const biomeId = this.world.getBiome(pos)
if (biomeId !== this.lastBiomeId) {
this.lastBiomeId = biomeId
const biomeData = loadedData.biomes[biomeId]
if (biomeData) {
this.emitter.emit('biomeUpdate', {
biome: biomeData
})
} else {
// unknown biome
this.emitter.emit('biomeReset')
}
}
} catch (e) {
console.error('error updating biome', e)
}
}
Comment on lines +366 to +386
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Undefined identifier ‘loadedData’; biome lookup will throw. Also fix method name typo.

loadedData is not defined; use the bot registry (already used elsewhere in this file) for biome metadata. Rename udpateBiomeupdateBiome.

-lastBiomeId: number | null = null
-
-udpateBiome (pos: Vec3) {
+lastBiomeId: number | null = null
+
+updateBiome (pos: Vec3) {
   try {
-    const biomeId = this.world.getBiome(pos)
+    const biomeId = this.world.getBiome(pos)
     if (biomeId !== this.lastBiomeId) {
       this.lastBiomeId = biomeId
-      const biomeData = loadedData.biomes[biomeId]
+      const biomeData =
+        // mineflayer registry varies by version
+        (bot as any)?.registry?.biomes?.[biomeId] ??
+        (bot as any)?.registry?.biomesById?.[biomeId]
       if (biomeData) {
         this.emitter.emit('biomeUpdate', {
           biome: biomeData
         })
       } else {
         // unknown biome
         this.emitter.emit('biomeReset')
       }
     }
   } catch (e) {
     console.error('error updating biome', e)
   }
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In renderer/viewer/lib/worldDataEmitter.ts around lines 366 to 386, the method
name is misspelled and it references an undefined identifier: rename udpateBiome
to updateBiome and replace the undefined loadedData lookup with the existing bot
registry biome metadata used elsewhere in this file (e.g. use this.botRegistry
or the local botRegistry variable to fetch biomes) so biomeId maps to
registry.biomes[biomeId]; preserve the existing lastBiomeId change and emitter
calls, and keep the try/catch and null/undefined check for missing biome data to
emit 'biomeReset'.


lastPosCheck: Vec3 | null = null
async updatePosition (pos: Vec3, force = false) {
if (!this.allowPositionUpdate) return
const posFloored = pos.floored()
if (!force && this.lastPosCheck && this.lastPosCheck.equals(posFloored)) return
this.lastPosCheck = posFloored

this.udpateBiome(pos)

const [lastX, lastZ] = chunkPos(this.lastPos)
const [botX, botZ] = chunkPos(pos)
if (lastX !== botX || lastZ !== botZ || force) {
Expand Down
64 changes: 43 additions & 21 deletions renderer/viewer/lib/worldrendererCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,44 @@ const toMajorVersion = version => {
export const worldCleanup = buildCleanupDecorator('resetWorld')

export const defaultWorldRendererConfig = {
// Debug settings
showChunkBorders: false,
enableDebugOverlay: false,

// Performance settings
mesherWorkers: 4,
isPlayground: false,
renderEars: true,
skinTexturesProxy: undefined as string | undefined,
// game renderer setting actually
showHand: false,
viewBobbing: false,
extraBlockRenderers: true,
clipWorldBelowY: undefined as number | undefined,
addChunksBatchWaitTime: 200,
_experimentalSmoothChunkLoading: true,
_renderByChunks: false,

// Rendering engine settings
dayCycle: true,
smoothLighting: true,
enableLighting: true,
starfield: true,
addChunksBatchWaitTime: 200,
vrSupport: true,
vrPageGameRendering: true,
renderEntities: true,
extraBlockRenderers: true,
foreground: true,
fov: 75,
fetchPlayerSkins: true,
volume: 1,

// Camera visual related settings
showHand: false,
viewBobbing: false,
renderEars: true,
highlightBlockColor: 'blue',
foreground: true,
enableDebugOverlay: false,
_experimentalSmoothChunkLoading: true,
_renderByChunks: false,
volume: 1

// Player models
fetchPlayerSkins: true,
skinTexturesProxy: undefined as string | undefined,

// VR settings
vrSupport: true,
vrPageGameRendering: true,

// World settings
clipWorldBelowY: undefined as number | undefined,
isPlayground: false
}

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

timeUpdated? (newTime: number): void

biomeUpdated? (biome: any): void

biomeReset? (): void

updateViewerPosition (pos: Vec3) {
this.viewerChunkPosition = pos
for (const [key, value] of Object.entries(this.loadedChunks)) {
Expand Down Expand Up @@ -817,12 +834,9 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
})

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

if (timeOfDay < 0 || timeOfDay > 24_000) {
throw new Error('Invalid time of day. It should be between 0 and 24000.')
}

this.timeOfTheDay = timeOfDay

// if (this.worldRendererConfig.skyLight === skyLight) return
Expand All @@ -831,6 +845,14 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
// (this).rerenderAllChunks?.()
// }
})

worldEmitter.on('biomeUpdate', ({ biome }) => {
this.biomeUpdated?.(biome)
})

worldEmitter.on('biomeReset', () => {
this.biomeReset?.()
})
}

setBlockStateIdInner (pos: Vec3, stateId: number | undefined, needAoRecalculation = true) {
Expand Down
Loading