Skip to content

Commit 7c01eeb

Browse files
authoredMar 17, 2024··
Fix 1.20.4 server resource pack error (#3320)
* Added a basic emit/catch for the add_resource_pack and remove_resource_pack packets * Fixed a typo in a variable name * Fixed a misnaming. * Changed resourcePack event to allow uuid or hash * Updated to a dictionary for active packs, also updated acceptResourcePack to allow 1.20.3 / 1.20.4 accept pack packets * Fixed errors in Lint test * Updated add_resource_pack to use UUID * Removed test print * Fixed feature checking * Sent resource pack loaded packet and now it works * Fixed coding conventions
1 parent d9e9e15 commit 7c01eeb

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed
 

‎index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export interface BotEvents {
160160
teamMemberRemoved: (team: Team) => Promise<void> | void
161161
bossBarDeleted: (bossBar: BossBar) => Promise<void> | void
162162
bossBarUpdated: (bossBar: BossBar) => Promise<void> | void
163-
resourcePack: (url: string, hash: string) => Promise<void> | void
163+
resourcePack: (url: string, hash?: string, uuid?: string) => Promise<void> | void
164164
particle: (particle: Particle) => Promise<void> | void
165165
}
166166

‎lib/plugins/resource_pack.js

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,51 @@
1+
const UUID = require('uuid-1345')
2+
13
module.exports = inject
24

35
function inject (bot) {
6+
let uuid
47
let latestHash
8+
let latestUUID
9+
let activeResourcePacks = {}
510
const TEXTURE_PACK_RESULTS = {
611
SUCCESSFULLY_LOADED: 0,
712
DECLINED: 1,
813
FAILED_DOWNLOAD: 2,
914
ACCEPTED: 3
1015
}
1116

17+
bot._client.on('add_resource_pack', (data) => { // Emits the same as resource_pack_send but sends uuid rather than hash because that's how active packs are tracked
18+
const uuid = new UUID(data.uuid)
19+
// Adding the pack to a set by uuid
20+
latestUUID = uuid
21+
activeResourcePacks[uuid] = data.url
22+
23+
bot.emit('resourcePack', data.url, uuid)
24+
})
25+
26+
bot._client.on('remove_resource_pack', (data) => { // Doesn't emit anything because it is removing rather than adding
27+
// if uuid isn't provided remove all packs
28+
if (data.uuid === undefined) {
29+
activeResourcePacks = {}
30+
} else {
31+
// Try to remove uuid from set
32+
try {
33+
delete activeResourcePacks[new UUID(data.uuid)]
34+
} catch (error) {
35+
console.error('Tried to remove UUID but it was not in the active list.')
36+
}
37+
}
38+
})
39+
1240
bot._client.on('resource_pack_send', (data) => {
13-
bot.emit('resourcePack', data.url, data.hash)
14-
latestHash = data.hash
41+
if (bot.supportFeature('resourcePackUsesUUID')) {
42+
uuid = new UUID(data.uuid)
43+
bot.emit('resourcePack', uuid, data.url)
44+
latestUUID = uuid
45+
} else {
46+
bot.emit('resourcePack', data.url, data.hash)
47+
latestHash = data.hash
48+
}
1549
})
1650

1751
function acceptResourcePack () {
@@ -24,6 +58,15 @@ function inject (bot) {
2458
result: TEXTURE_PACK_RESULTS.SUCCESSFULLY_LOADED,
2559
hash: latestHash
2660
})
61+
} else if (bot.supportFeature('resourcePackUsesUUID')) {
62+
bot._client.write('resource_pack_receive', {
63+
uuid: latestUUID,
64+
result: TEXTURE_PACK_RESULTS.ACCEPTED
65+
})
66+
bot._client.write('resource_pack_receive', {
67+
uuid: latestUUID,
68+
result: TEXTURE_PACK_RESULTS.SUCCESSFULLY_LOADED
69+
})
2770
} else {
2871
bot._client.write('resource_pack_receive', {
2972
result: TEXTURE_PACK_RESULTS.ACCEPTED
@@ -35,6 +78,12 @@ function inject (bot) {
3578
}
3679

3780
function denyResourcePack () {
81+
if (bot.supportFeature('resourcePackUsesUUID')) {
82+
bot._client.write('resource_pack_receive', {
83+
uuid: latestUUID,
84+
result: TEXTURE_PACK_RESULTS.DECLINED
85+
})
86+
}
3887
bot._client.write('resource_pack_receive', {
3988
result: TEXTURE_PACK_RESULTS.DECLINED
4089
})

0 commit comments

Comments
 (0)
Please sign in to comment.