Skip to content

Commit

Permalink
fix: don't reset the world in mesher after resourece pack textures up…
Browse files Browse the repository at this point in the history
…date
  • Loading branch information
zardoy committed Oct 30, 2024
1 parent 5791626 commit 7d0c364
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions prismarine-viewer/viewer/lib/mesher/mesher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ const handleMessage = data => {
}

if (data.config) {
if (data.type === 'mesherData' && allDataReady) {
world = undefined as any // reset models
if (data.type === 'mesherData' && world) {
// reset models
world.blockCache = {}
world.erroredBlockModel = undefined
}

world ??= new World(data.config.version)
Expand Down
2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/lib/mesher/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class World {
blockCache = {}
biomeCache: { [id: number]: mcData.Biome }
preflat: boolean
erroredBlockModel: BlockModelPartsResolved
erroredBlockModel?: BlockModelPartsResolved

constructor (version) {
this.Chunk = Chunks(version) as any
Expand Down
2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/lib/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Viewer {
}

setBlockStateId (pos: Vec3, stateId: number) {
if (!this.world.loadedChunks[`${Math.floor(pos.x / 16)},${Math.floor(pos.z / 16)}`]) {
if (!this.world.loadedChunks[`${Math.floor(pos.x / 16) * 16},${Math.floor(pos.z / 16) * 16}`]) {
console.warn('[should be unreachable] setBlockStateId called for unloaded chunk', pos)
}
this.world.setBlockStateId(pos, stateId)
Expand Down
12 changes: 7 additions & 5 deletions src/resourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,17 @@ export const onAppLoad = () => {
const forced = 'forced' in packet ? packet.forced : false
const choice = options.serverResourcePacks === 'always'
? true
: await showOptionsModal(promptMessage, ['Download & Install'], {
: await showOptionsModal(promptMessage, ['Download & Install (recommended)', 'Pretend Installed (not recommended)'], {
cancel: !forced
})
if (!choice) return
bot.acceptResourcePack()
await downloadAndUseResourcePack(packet.url).catch((err) => {
console.error(err)
showNotification('Failed to download resource pack: ' + err.message)
})
if (choice === 'Download & Install (recommended)') {
await downloadAndUseResourcePack(packet.url).catch((err) => {
console.error(err)
showNotification('Failed to download resource pack: ' + err.message)
})
}
}
bot._client.on('resource_pack_send', handleResourcePackRequest)
bot._client.on('add_resource_pack' as any, handleResourcePackRequest)
Expand Down

0 comments on commit 7d0c364

Please sign in to comment.