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

Fix gamemode test and implementation #3508

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions lib/plugins/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ function inject (bot, options) {
function handleRespawnPacketData (packet) {
bot.game.levelType = packet.levelType ?? (packet.isFlat ? 'flat' : 'default')
bot.game.hardcore = packet.isHardcore ?? Boolean(packet.gameMode & 0b100)
if (bot.registry.isOlderThan('1.10')) { // gamemode is used pre 1.10 and post 1.20 but in between it's gameMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that like a string then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapper is a enum. The enum values can be found in the protocol files inside minecraft-data for the relevant version.

The current Mcpc mcdata protocol doc gen doesn't support the mapper type. Can be fixed in future by swapping it with the protodef-yaml html gen that bedrock is currently using.

bot.game.gameMode = parseGameMode(packet.gamemode)
// Either a respawn packet or a login packet. Depending on the packet it can be "gamemode" or "gameMode"
if (bot.registry.isNewerOrEqualTo('1.20.5')) {
bot.game.gameMode = packet.gamemode || parseGameMode(packet.gameMode)
} else {
bot.game.gameMode = packet.gamemode || parseGameMode(packet.gameMode & 0b1111) // lower four bits
bot.game.gameMode = parseGameMode(packet.gamemode ?? packet.gameMode)
}
if (bot.supportFeature('segmentedRegistryCodecData')) { // 1.20.5
if (typeof packet.dimension === 'number') {
Expand Down
6 changes: 2 additions & 4 deletions test/externalTests/gamemode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ module.exports = () => {

addTest('after respawn', async (bot) => {
await bot.test.becomeCreative()

bot.chat('/kill')

await onceWithCleanup(bot, 'respawn', { timeout: 2000 })
bot.test.selfKill()
await onceWithCleanup(bot, 'respawn', { timeout: 5000 })
// Respawn packets send the gamemode. If the bot is in creative mode, it should respawn in creative mode. Tested <1.20
assert.strictEqual(bot.game.gameMode, 'creative', 'Wrong gamemode after respawn')
})
Expand Down
5 changes: 5 additions & 0 deletions test/externalTests/plugins/testCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function inject (bot) {
bot.test.placeBlock = placeBlock
bot.test.runExample = runExample
bot.test.tellAndListen = tellAndListen
bot.test.selfKill = selfKill
bot.test.wait = function (ms) {
return new Promise((resolve) => { setTimeout(resolve, ms) })
}
Expand Down Expand Up @@ -232,4 +233,8 @@ function inject (bot) {
}
return closeExample()
}

function selfKill () {
bot.chat('/kill @p')
}
}
Loading