Skip to content

Commit

Permalink
also fix on the client side
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Aug 30, 2024
1 parent ed0df88 commit b53eb86
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/client/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,31 @@ module.exports = function (client, options) {
client.username = packet.username

if (mcData.supportFeature('hasConfigurationState')) {
client.write('login_acknowledged', {})
enterConfigState(onReady)
enterConfigState(onReady, () => {
client.write('login_acknowledged', {})
})
// Server can tell client to re-enter config state
client.on('start_configuration', () => enterConfigState())
} else {
client.state = states.PLAY
onReady()
}

function enterConfigState (finishCb) {
function enterConfigState (finishCb, beforeStateSwitch = () => {}) {
if (client.state === states.CONFIGURATION) return
// If we are returning to the configuration state from the play state, we ahve to acknowledge it.
if (client.state === states.PLAY) {
client.write('configuration_acknowledged', {})
}
client.state = states.CONFIGURATION
// Server should send finish_configuration on its own right after sending the client a dimension codec
// for login (that has data about world height, world gen, etc) after getting a login success from client
client.once('finish_configuration', () => {
client.write('finish_configuration', {})
client.state = states.PLAY
finishCb?.()
})
beforeStateSwitch?.()
client.state = states.CONFIGURATION
}

function onReady () {
Expand Down

0 comments on commit b53eb86

Please sign in to comment.