Skip to content

Commit 6d5d3ae

Browse files
plainprinceSimeon Kummerclaude
authored
Fix dimension type lookup for 1.19-1.20.4 on proxy/modded servers (#3822)
* Fix dimension type lookup for 1.19-1.20.4 on proxy/modded servers For versions 1.19-1.20.4, the dimension codec lookup used worldName (the world/level name) instead of the dimension TYPE name. On vanilla servers these are identical, but on proxy or modded servers they can differ (e.g. world "lobby" with dimension type "overworld"), causing the lookup to fail and leaving minY=0, height=256 as incorrect defaults. Use the correct field for the dimension type: "worldType" from login packets, "dimension" from respawn packets. Also removes a dead-code fallback that was guarded by a condition that could never be true. * Add test for dimension type lookup on proxy/modded servers (1.19-1.20.4) Verifies that the bot uses worldType (dimension type) instead of worldName (level name) for the dimension codec lookup, which fixes issues on proxy/modded servers where these values differ. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add external test for dimension data after spawn and respawn Verifies that bot.game.dimension, minY, and height are correctly populated from the dimension codec on initial spawn and after respawn. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove respawn sub-test from dimensionData external test The /kill command used in the respawn test triggers "moved too quickly" warnings that can cascade into failures in subsequent tests. The dimension data correctness after spawn is already validated, and the internal test covers the proxy/modded server lookup scenario. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Simeon Kummer <simeon@hitthecode.de> Co-authored-by: Claude <claude@anthropic.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dc5c91a commit 6d5d3ae

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

lib/plugins/game.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ function inject (bot, options) {
4747
} else if (bot.supportFeature('dimensionIsAString')) {
4848
bot.game.dimension = packet.dimension.replace('minecraft:', '')
4949
} else if (bot.supportFeature('dimensionIsAWorld')) {
50-
bot.game.dimension = packet.worldName.replace('minecraft:', '')
50+
if (bot.supportFeature('dimensionDataInCodec')) {
51+
// For 1.19+, we need the dimension TYPE name (not the world/level name) so
52+
// the codec lookup succeeds. In login packets the type is "worldType"; in
53+
// respawn packets it is "dimension". worldName is the level name which may
54+
// differ from the type on proxy/modded servers.
55+
const dimType = packet.worldType ?? packet.dimension
56+
bot.game.dimension = typeof dimType === 'string'
57+
? dimType.replace('minecraft:', '')
58+
: packet.worldName.replace('minecraft:', '')
59+
} else {
60+
bot.game.dimension = packet.worldName.replace('minecraft:', '')
61+
}
5162
} else {
5263
throw new Error('Unsupported dimension type in login packet')
5364
}
@@ -60,11 +71,6 @@ function inject (bot, options) {
6071
bot.game.height = 256
6172

6273
if (bot.supportFeature('dimensionDataInCodec')) { // 1.19+
63-
// pre 1.20.5 before we consolidated login and respawn's SpawnInfo structure into one type,
64-
// "dimension" was called "worldType" in login_packet's payload but not respawn.
65-
if (packet.worldType && !bot.game.dimension) {
66-
bot.game.dimension = packet.worldType.replace('minecraft:', '')
67-
}
6874
const dimData = bot.registry.dimensionsByName[bot.game.dimension]
6975
if (dimData) {
7076
bot.game.minY = dimData.minY
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const assert = require('assert')
2+
3+
module.exports = () => {
4+
const tests = []
5+
6+
function addTest (name, f) {
7+
tests[name] = (bot) => f(bot)
8+
}
9+
10+
addTest('overworld properties', async (bot) => {
11+
// After spawn, bot.game.dimension should be set to 'overworld'
12+
assert.ok(bot.game.dimension, 'bot.game.dimension should be set after spawn')
13+
assert.strictEqual(bot.game.dimension, 'overworld', 'Dimension should be overworld on spawn')
14+
15+
// minY and height should be populated from the dimension codec
16+
assert.strictEqual(typeof bot.game.minY, 'number', 'bot.game.minY should be a number')
17+
assert.strictEqual(typeof bot.game.height, 'number', 'bot.game.height should be a number')
18+
assert.ok(bot.game.height > 0, 'Height should be positive')
19+
20+
// Overworld in modern versions has minY=-64, height=384; older versions have minY=0, height=256
21+
if (bot.supportFeature('dimensionDataInCodec')) {
22+
assert.strictEqual(bot.game.minY, -64, 'Overworld minY should be -64 for 1.18+')
23+
assert.strictEqual(bot.game.height, 384, 'Overworld height should be 384 for 1.18+')
24+
} else {
25+
assert.ok(bot.game.minY <= 0, 'minY should be <= 0')
26+
assert.ok(bot.game.height >= 256, 'Height should be at least 256')
27+
}
28+
})
29+
30+
return tests
31+
}

test/internalTest.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,36 @@ for (const supportedVersion of mineflayer.testedVersions) {
490490
}
491491
})
492492
})
493+
494+
it('dimension type lookup uses worldType over worldName on 1.19-1.20.4', function (done) {
495+
// On proxy/modded servers the worldName (level name) may differ from
496+
// the dimension type. For versions with dimensionDataInCodec but
497+
// without segmentedRegistryCodecData (1.19-1.20.4), the bot should
498+
// prefer worldType (login) / dimension (respawn) for the codec lookup.
499+
if (!bot.supportFeature('dimensionDataInCodec') || bot.supportFeature('segmentedRegistryCodecData')) {
500+
this.skip()
501+
return
502+
}
503+
504+
const loginPacket = bot.test.generateLoginPacket()
505+
// Simulate a proxy/modded server: worldName is a custom level name
506+
// but worldType is still the real dimension type
507+
loginPacket.worldName = 'modded:custom_world'
508+
loginPacket.worldType = 'minecraft:overworld'
509+
510+
server.on('playerJoin', (client) => {
511+
client.write('login', loginPacket)
512+
bot.once('login', () => {
513+
assert.strictEqual(bot.game.dimension, 'overworld',
514+
'should use worldType for dimension, not worldName')
515+
assert.ok(bot.game.minY !== undefined,
516+
'minY should be set from codec lookup')
517+
assert.ok(bot.game.height !== undefined,
518+
'height should be set from codec lookup')
519+
done()
520+
})
521+
})
522+
})
493523
})
494524

495525
describe('entities', () => {

0 commit comments

Comments
 (0)