feat: add debugSceneChunks and debugChangedOptions global variables that available via browser console
fix: reset all options sometimes didn't work (don't mutate default options)
This commit is contained in:
parent
3b4d5e04b8
commit
df6ed989d0
4 changed files with 29 additions and 6 deletions
|
|
@ -53,11 +53,13 @@ There is world renderer playground ([link](https://mcon.vercel.app/playground.ht
|
|||
|
||||
However, there are many things that can be done in online version. You can access some global variables in the console and useful examples:
|
||||
|
||||
- `localStorage.debug = '*'` - Enables all debug messages!
|
||||
- `localStorage.debug = '*'` - Enables all debug messages! Warning: this will start all packets spam.
|
||||
|
||||
- `bot` - Mineflayer bot instance. See Mineflayer documentation for more.
|
||||
- `viewer` - Three.js viewer instance, basically does all the rendering.
|
||||
- `viewer.world.sectionObjects` - Object with all active chunk sections (geometries) in the world. Each chunk section is a Three.js mesh or group.
|
||||
- `debugSceneChunks` - The same as above, but relative to current bot position (e.g. 0,0 is the current chunk).
|
||||
- `debugChangedOptions` - See what options are changed. Don't change options here.
|
||||
- `localServer` - Only for singleplayer mode/host. Flying Squid server instance, see it's documentation for more.
|
||||
- `localServer.overworld.storageProvider.regions` - See ALL LOADED region files with all raw data.
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { dispose3 } from './dispose'
|
|||
import { toMajor } from './version.js'
|
||||
import PrismarineChatLoader from 'prismarine-chat'
|
||||
import { renderSign } from '../sign-renderer/'
|
||||
import { chunkPos } from './simpleUtils'
|
||||
|
||||
function mod (x, n) {
|
||||
return ((x % n) + n) % n
|
||||
|
|
@ -33,6 +34,7 @@ export class WorldRenderer {
|
|||
workers: any[] = []
|
||||
|
||||
texturesVersion?: string
|
||||
|
||||
constructor (public scene: THREE.Scene, numWorkers = 4) {
|
||||
// init workers
|
||||
for (let i = 0; i < numWorkers; i++) {
|
||||
|
|
@ -182,6 +184,15 @@ export class WorldRenderer {
|
|||
})
|
||||
}
|
||||
|
||||
getLoadedChunksRelative (pos: Vec3) {
|
||||
const [currentX, currentZ] = chunkPos(pos)
|
||||
return Object.fromEntries(Object.entries(this.sectionObjects).map(([key, o]) => {
|
||||
const [xRaw, yRaw, zRaw] = key.split(',').map(Number)
|
||||
const [x, z] = chunkPos({x: xRaw, z: zRaw})
|
||||
return [`${x - currentX},${z - currentZ}`, o]
|
||||
}))
|
||||
}
|
||||
|
||||
addColumn (x, z, chunk) {
|
||||
this.loadedChunks[`${x},${z}`] = true
|
||||
for (const worker of this.workers) {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,11 @@ document.body.appendChild(renderer.domElement)
|
|||
// Create viewer
|
||||
const viewer: import('prismarine-viewer/viewer/lib/viewer').Viewer = new Viewer(renderer, options.numWorkers)
|
||||
window.viewer = viewer
|
||||
Object.defineProperty(window, 'debugSceneChunks', {
|
||||
get () {
|
||||
return viewer.world.getLoadedChunksRelative(bot.entity.position)
|
||||
},
|
||||
})
|
||||
viewer.entities.entitiesOptions = {
|
||||
fontFamily: 'mojangles'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import { proxy, subscribe } from 'valtio/vanilla'
|
|||
// weird webpack configuration bug: it cant import valtio/utils in this file
|
||||
import { subscribeKey } from 'valtio/utils'
|
||||
|
||||
const mergeAny: <T>(arg1: T, arg2: any) => T = Object.assign
|
||||
|
||||
const defaultOptions = {
|
||||
renderDistance: 2,
|
||||
multiplayerRenderDistance: 2,
|
||||
|
|
@ -53,9 +51,10 @@ const defaultOptions = {
|
|||
|
||||
export type AppOptions = typeof defaultOptions
|
||||
|
||||
export const options = proxy(
|
||||
mergeAny(defaultOptions, JSON.parse(localStorage.options || '{}'))
|
||||
)
|
||||
export const options: AppOptions = proxy({
|
||||
...defaultOptions,
|
||||
...JSON.parse(localStorage.options || '{}')
|
||||
})
|
||||
|
||||
window.options = window.settings = options
|
||||
|
||||
|
|
@ -63,6 +62,12 @@ export const resetOptions = () => {
|
|||
Object.assign(options, defaultOptions)
|
||||
}
|
||||
|
||||
Object.defineProperty(window, 'debugChangedOptions', {
|
||||
get () {
|
||||
return Object.fromEntries(Object.entries(options).filter(([key, v]) => defaultOptions[key] !== v))
|
||||
},
|
||||
})
|
||||
|
||||
subscribe(options, () => {
|
||||
localStorage.options = JSON.stringify(options)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue