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

@ -97,6 +97,9 @@ Don't be intimidated by the following text, as a minimal pack only requires `pac
- Configuration:
- `config/` - Configuration files
- `defaults.toml` - Overrides for standard content bindings, such as the player entity, default generator, etc.
- `hotbar-size` - number of hotbar slots, 10 by default (see `player.set_hotbar_size`)
- `hotbar-layout` - layout replacing the built-in hotbar, for example `"pack:hotbar"`. The root element must be `inventory`, it is bound to the player inventory. Without `position-func` the layout is placed at the bottom center of the screen
- `inventory-layout` - player inventory layout, `"core:inventory"` by default. The root element must be `inventory`
- `bindings.toml` - Keyboard/Mouse bindings
- `user-props.toml` - User properties for content definitions
- `devtools/` - Auxiliary files for internal debugging tools

View file

@ -82,6 +82,12 @@ hud.is_player_inventory_open() -> boolean
-- Sets whether to allow pausing. If false, the pause menu will not pause the game.
hud.set_allow_pause(flag: bool)
-- Returns true if the hotbar is not hidden with hud.set_hotbar_visible.
hud.is_hotbar_visible() -> bool
-- Shows or hides the hotbar. Selecting a slot with the mouse wheel and number keys keeps working.
hud.set_hotbar_visible(flag: bool)
-- Function that controls the named skeleton 'hand' (see gfx.skeletons)
hud.hand_controller: function()
```

View file

@ -142,7 +142,14 @@ Switches the player's camera. See [cameras](libcameras.md).
player.set_selected_slot(playerid: int, slotid: int)
```
Sets the selected slot index
Sets the selected slot index. The index wraps around the hotbar size.
```lua
player.get_hotbar_size(playerid: int) -> int
player.set_hotbar_size(playerid: int, size: int)
```
Hotbar size getter and setter: the number of first inventory slots selected with the mouse wheel and number keys. Default value is `hotbar-size` from `config/defaults.toml` (10). The value is not saved with the world.
```lua
player.get_selected_block(playerid: int) -> x,y,z

View file

@ -99,6 +99,9 @@ print(file.read("пак:package.json")) -- выведет содержимое p
- Конфигурация:
- `config/` - файлы конфигурации
- `defaults.toml` - переопределения стандартных привязок к контенту, такие как сущность игрока, генератор по-умолчанию и т.д.
- `hotbar-size` - число слотов хотбара, по умолчанию 10 (см. `player.set_hotbar_size`)
- `hotbar-layout` - макет, заменяющий встроенный хотбар, например `"pack:hotbar"`. Корневой элемент - `inventory`, он привязывается к инвентарю игрока. Без `position-func` макет ставится внизу по центру экрана
- `inventory-layout` - макет инвентаря игрока, по умолчанию `"core:inventory"`. Корневой элемент - `inventory`
- `bindings.toml` - привязки к клавишам / мыши
- `user-props.toml` - пользовательские свойства определений контента
- `devtools/` - вспомогательные файлы внутренних инструментов отладки

View file

@ -84,6 +84,12 @@ hud.is_player_inventory_open() -> boolean
-- Устанавливает разрешение на паузу. При значении false меню паузы не приостанавливает игру.
hud.set_allow_pause(flag: boolean)
-- Возвращает true, если хотбар не скрыт через hud.set_hotbar_visible.
hud.is_hotbar_visible() -> boolean
-- Показывает или скрывает хотбар. Выбор слота колесом мыши и цифровыми клавишами продолжает работать.
hud.set_hotbar_visible(flag: boolean)
-- Функция, управляющая именованным скелетом 'hand' (см. gfx.skeletons)
hud.hand_controller: function()
```

View file

@ -95,9 +95,15 @@ player.get_interaction_distance(playerid: int) -> number
-- Возвращает ID инвентаря и индекс выбранного слота
player.get_inventory(playerid: int) -> int, int
-- Устанавливает выбранный слот
-- Устанавливает выбранный слот (индекс берётся по модулю размера хотбара)
player.set_selected_slot(playerid: int, slotid: int)
-- Возвращает / устанавливает размер хотбара - число первых слотов инвентаря,
-- выбираемых колесом мыши и цифровыми клавишами. По умолчанию - `hotbar-size`
-- из `config/defaults.toml` (10). Не сохраняется в мире.
player.get_hotbar_size(playerid: int) -> int
player.set_hotbar_size(playerid: int, size: int)
-- Возвращает позицию выбранного блока
player.get_selected_block(playerid: int) -> x,y,z