Skip to content

Commit

Permalink
Add core.protocol_versions for modder convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Feb 8, 2025
1 parent 4f0ea4a commit 953bb87
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/game/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local gamepath = scriptpath .. "game".. DIR_DELIM
local builtin_shared = {}

dofile(gamepath .. "constants.lua")
dofile(gamepath .. "protocol_versions.lua")
assert(loadfile(commonpath .. "item_s.lua"))(builtin_shared)
assert(loadfile(gamepath .. "item.lua"))(builtin_shared)
assert(loadfile(commonpath .. "register.lua"))(builtin_shared)
Expand Down
16 changes: 16 additions & 0 deletions builtin/game/protocol_versions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- c.f. https://content.luanti.org/api/minetest_versions/
-- see also src/network/networkprotocol.cpp
core.protocol_versions = {
["5.0"] = 37,
["5.1"] = 38,
["5.2"] = 39,
["5.3"] = 39,
["5.4"] = 39,
["5.5"] = 40,
["5.6"] = 41,
["5.7"] = 42,
["5.8"] = 43,
["5.9"] = 44,
["5.10"] = 46,
["5.11"] = 47,
}
8 changes: 8 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5721,6 +5721,7 @@ Utilities
-- or inconsistent in engine forks. You must not use this for checking
-- feature availability of clients. Instead, do use the fields
-- `protocol_version` and `formspec_version` where it matters.
-- You can use `core.protocol_versions` to map Luanti versions to protocol versions.
-- This version string may only be used for analysis purposes.
version_string = "0.4.9-git", -- full version string

Expand All @@ -5734,6 +5735,13 @@ Utilities
}
```

* `core.protocol_versions`:
* Table mapping minor Luanti 5.x versions to
corresponding protocol versions for modder convenience.
* For example, to check whether a client has at least the feature set
of Luanti 5.8 or newer, you could do:
`core.get_player_information(player_name).protocol_version >= core.protocol_versions["5.8"]`
* Available since 5.11
* `core.get_player_window_information(player_name)`:

```lua
Expand Down
1 change: 1 addition & 0 deletions src/network/networkprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
[scheduled bump for 5.11.0]
*/

// Note: Also update builtin/game/protocol_versions.lua when bumping
const u16 LATEST_PROTOCOL_VERSION = 47;

// See also formspec [Version History] in doc/lua_api.md
Expand Down

0 comments on commit 953bb87

Please sign in to comment.