Skip to content

Commit

Permalink
better loading msg
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Feb 3, 2025
1 parent 4148913 commit 32acb55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,12 @@ export async function connect (connectOptions: ConnectOptions) {
// don't use spawn event, player can be dead
bot.once(spawnEarlier ? 'forcedMove' : 'health', async () => {
if (resourcePackState.isServerInstalling) {
showNotification('Resource pack is being installed, please wait...')
setLoadingScreenStatus('Downloading resource pack')
await new Promise<void>(resolve => {
subscribe(resourcePackState, () => {
if (!resourcePackState.isServerDownloading) {
setLoadingScreenStatus('Installing resource pack')
}
if (!resourcePackState.isServerInstalling) {
resolve()
}
Expand Down
4 changes: 4 additions & 0 deletions src/resourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { watchUnloadForCleanup } from './gameUnload'

export const resourcePackState = proxy({
resourcePackInstalled: false,
isServerDownloading: false,
isServerInstalling: false
})

Expand Down Expand Up @@ -339,13 +340,15 @@ const prepareBlockstatesAndModels = async () => {
const downloadAndUseResourcePack = async (url: string): Promise<void> => {
try {
resourcePackState.isServerInstalling = true
resourcePackState.isServerDownloading = true
console.log('Downloading server resource pack', url)
const response = await fetch(url).catch((err) => {
console.log(`Ensure server on ${url} support CORS which is not required for regular client, but is required for the web client`)
console.error(err)
showNotification('Failed to download resource pack: ' + err.message)
})
if (!response) return
resourcePackState.isServerDownloading = false
const resourcePackData = await response.arrayBuffer()
showNotification('Installing resource pack...')
await installTexturePack(resourcePackData, undefined, undefined, true).catch((err) => {
Expand All @@ -354,6 +357,7 @@ const downloadAndUseResourcePack = async (url: string): Promise<void> => {
})
} finally {
resourcePackState.isServerInstalling = false
resourcePackState.isServerDownloading = false
}
}

Expand Down

0 comments on commit 32acb55

Please sign in to comment.