diff --git a/prismarine-viewer/viewer/lib/entities.js b/prismarine-viewer/viewer/lib/entities.js index 87df3299..a3c797b8 100644 --- a/prismarine-viewer/viewer/lib/entities.js +++ b/prismarine-viewer/viewer/lib/entities.js @@ -80,6 +80,7 @@ export class Entities extends EventEmitter { this.debugMode = 'none' this.onSkinUpdate = () => { } this.clock = new THREE.Clock() + this.visible = true } clear () { @@ -102,6 +103,13 @@ export class Entities extends EventEmitter { } } + setVisible(visible, /** @type {THREE.Object3D?} */entity = null) { + this.visible = visible + for (const mesh of entity ? [entity] : Object.values(this.entities)) { + mesh.visible = visible + } + } + render () { const dt = this.clock.getDelta() for (const entityId of Object.keys(this.entities)) { @@ -284,6 +292,7 @@ export class Entities extends EventEmitter { this.updatePlayerSkin(entity.id, '', stevePng) } this.setDebugMode(this.debugMode, group) + this.setVisible(this.visible, group) } // this can be undefined in case where packet entity_destroy was sent twice (so it was already deleted) diff --git a/src/optionsStorage.ts b/src/optionsStorage.ts index 27d9c50a..f579bc49 100644 --- a/src/optionsStorage.ts +++ b/src/optionsStorage.ts @@ -53,6 +53,7 @@ const defaultOptions = { askGuestName: true, /** Actually might be useful */ showCursorBlockInSpectator: false, + renderEntities: true, // advanced bot options autoRespawn: false, diff --git a/src/watchOptions.ts b/src/watchOptions.ts index 706cf40f..9b22fdfe 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -29,4 +29,8 @@ export const watchOptionsAfterViewerInit = () => { viewer.composer = undefined } }) + + watchValue(options, o => { + viewer.entities.setVisible(o.renderEntities) + }) }