Skip to content

Commit

Permalink
Standardize dimensions for all versions (#2968)
Browse files Browse the repository at this point in the history
* Fix tieh dimension name for lower 1.18

* normalize dimension naming

* Update blocks.js

* Update api.md

* fix typo

---------

Co-authored-by: extremeheat <[email protected]>
  • Loading branch information
sefirosweb and extremeheat committed May 20, 2023
1 parent 61008fd commit 115f1e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ Whether the bot is using the item that it's holding, for example eating food or

#### bot.game.dimension

The bot's current dimension, such as `overworld`, `the_end` or `the_nether`.

#### bot.game.difficulty

#### bot.game.gameMode
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function inject (bot, { version, storageBuilder, hideErrors }) {
bitMap: packet.bitMap,
heightmaps: packet.heightmaps,
biomes: packet.biomes,
skyLightSent: bot.game.dimension === 'minecraft:overworld',
skyLightSent: bot.game.dimension === 'overworld',
groundUp: packet.groundUp,
data: packet.chunkData,
trustEdges: packet.trustEdges,
Expand Down
11 changes: 6 additions & 5 deletions lib/plugins/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const difficultyNames = ['peaceful', 'easy', 'normal', 'hard']
const gameModes = ['survival', 'creative', 'adventure', 'spectator']

const dimensionNames = {
'-1': 'minecraft:nether',
0: 'minecraft:overworld',
1: 'minecraft:end'
'-1': 'the_nether',
0: 'overworld',
1: 'the_end'
}

const parseGameMode = gameModeBits => gameModes[(gameModeBits & 0b11)] // lower two bits
Expand All @@ -29,9 +29,9 @@ function inject (bot, options) {
if (bot.supportFeature('dimensionIsAnInt')) {
bot.game.dimension = dimensionNames[packet.dimension]
} else if (bot.supportFeature('dimensionIsAString')) {
bot.game.dimension = packet.dimension
bot.game.dimension = packet.dimension.replace('minecraft:', '')
} else if (bot.supportFeature('dimensionIsAWorld')) {
bot.game.dimension = packet.worldName
bot.game.dimension = packet.worldName.replace('minecraft:', '')
} else {
throw new Error('Unsupported dimension type in login packet')
}
Expand Down Expand Up @@ -60,6 +60,7 @@ function inject (bot, options) {
bot.game.minY = 0
bot.game.height = 256
}

if (packet.difficulty) {
bot.game.difficulty = difficultyNames[packet.difficulty]
}
Expand Down

0 comments on commit 115f1e9

Please sign in to comment.