Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added download and install for server resource packs #213

Closed
wants to merge 5 commits into from
Closed
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: 0 additions & 1 deletion prismarine-viewer/viewer/lib/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ export class Entities extends EventEmitter {
}

update (entity: import('prismarine-entity').Entity & { delete?; pos }, overrides) {
console.log('entity', entity)
const isPlayerModel = entity.name === 'player'
if (entity.name === 'zombie' || entity.name === 'zombie_villager' || entity.name === 'husk') {
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
Expand Down
11 changes: 8 additions & 3 deletions src/resourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,17 @@ const prepareBlockstatesAndModels = async () => {
}
}

const downloadAndUseResourcePack = async (url) => {
const downloadAndUseResourcePack = async (url: string): Promise<void> => {
console.log('downloadAndUseResourcePack', url)
const response = await fetch(url)
const resourcePackData = await response.arrayBuffer()
installTexturePack(resourcePackData)
}

export const onAppLoad = () => {
customEvents.on('gameLoaded', () => {
// todo also handle resourcePack
bot._client.on('resource_pack_send', async (packet) => {
const handleResourcePackRequest = async (packet) => {
if (options.serverResourcePacks === 'never') return
const promptMessage = 'promptMessage' in packet ? JSON.stringify(packet.promptMessage) : 'Do you want to use server resource pack?'
// TODO!
Expand All @@ -283,7 +286,9 @@ export const onAppLoad = () => {
if (!choice) return
await downloadAndUseResourcePack(packet.url)
bot.acceptResourcePack()
})
}
bot._client.on('resource_pack_send', handleResourcePackRequest)
bot._client.on('add_resource_pack' as any, handleResourcePackRequest)
})

subscribe(resourcePackState, () => {
Expand Down
Loading