make hotbar size and layout configurable

Add hotbar-size, hotbar-layout and inventory-layout to config/defaults.toml,
player.get_hotbar_size / player.set_hotbar_size and
hud.is_hotbar_visible / hud.set_hotbar_visible.
This commit is contained in:
ostermine 2026-10-15 15:52:22 +03:00
parent 2e2233a489
commit aa670f3c9d
16 changed files with 188 additions and 20 deletions

View file

@ -194,6 +194,15 @@ static int l_set_allow_pause(lua::State* L) {
return 0;
}
static int l_is_hotbar_visible(lua::State* L) {
return lua::pushboolean(L, hud->isHotbarVisible());
}
static int l_set_hotbar_visible(lua::State* L) {
hud->setHotbarVisible(lua::toboolean(L, 1));
return 0;
}
static int l_reload_script(lua::State* L) {
auto packid = lua::require_string(L, 1);
if (content == nullptr) {
@ -237,6 +246,8 @@ const luaL_Reg hudlib[] = {
{"_set_content_access", wrap_hud<l_set_content_access>},
{"_set_debug_cheats", wrap_hud<l_set_debug_cheats>},
{"set_allow_pause", wrap_hud<l_set_allow_pause>},
{"is_hotbar_visible", wrap_hud<l_is_hotbar_visible>},
{"set_hotbar_visible", wrap_hud<l_set_hotbar_visible>},
{"reload_script", wrap_hud<l_reload_script>},
{"is_open", wrap_hud<l_is_open>},
{nullptr, nullptr}

View file

@ -121,7 +121,21 @@ static int l_get_inv(lua::State* L) {
static int l_set_selected_slot(lua::State* L) {
if (auto player = get_player(L, 1)) {
player->setChosenSlot(lua::tointeger(L, 2) % 10);
player->setChosenSlot(lua::tointeger(L, 2) % player->getHotbarSize());
}
return 0;
}
static int l_get_hotbar_size(lua::State* L) {
if (auto player = get_player(L, 1)) {
return lua::pushinteger(L, player->getHotbarSize());
}
return 0;
}
static int l_set_hotbar_size(lua::State* L) {
if (auto player = get_player(L, 1)) {
player->setHotbarSize(lua::tointeger(L, 2));
}
return 0;
}
@ -401,6 +415,8 @@ const luaL_Reg playerlib[] = {
{"get_interaction_distance", lua::wrap<l_get_interaction_distance>},
{"set_interaction_distance", lua::wrap<l_set_interaction_distance>},
{"set_selected_slot", lua::wrap<l_set_selected_slot>},
{"get_hotbar_size", lua::wrap<l_get_hotbar_size>},
{"set_hotbar_size", lua::wrap<l_set_hotbar_size>},
{"get_selected_block", lua::wrap<l_get_selected_block>},
{"get_selected_entity", lua::wrap<l_get_selected_entity>},
{"set_spawnpoint", lua::wrap<l_set_spawnpoint>},