mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 09:59:44 +00:00
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:
parent
2e2233a489
commit
aa670f3c9d
16 changed files with 188 additions and 20 deletions
|
|
@ -1,2 +1,4 @@
|
|||
generator = "core:default"
|
||||
player-entity = ""
|
||||
hotbar-size = 10
|
||||
inventory-layout = "core:inventory"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ local M = {}
|
|||
|
||||
function M.share_default_func(invid, slotid)
|
||||
local blockinv = hud.get_block_inventory()
|
||||
local playerinv = player.get_inventory(hud.get_player())
|
||||
local pid = hud.get_player()
|
||||
local playerinv = player.get_inventory(pid)
|
||||
local hotbar_size = player.get_hotbar_size(pid)
|
||||
if blockinv ~= 0 then
|
||||
if invid == blockinv then
|
||||
inventory.move(blockinv, slotid, playerinv)
|
||||
|
|
@ -11,10 +13,10 @@ function M.share_default_func(invid, slotid)
|
|||
end
|
||||
elseif rules.get("allow-content-access") then
|
||||
inventory.set(invid, slotid, 0, 0)
|
||||
elseif slotid < 10 then
|
||||
inventory.move_range(invid, slotid, invid, 10)
|
||||
elseif slotid < hotbar_size then
|
||||
inventory.move_range(invid, slotid, invid, hotbar_size)
|
||||
else
|
||||
inventory.move_range(invid, slotid, invid, 0, 9)
|
||||
inventory.move_range(invid, slotid, invid, 0, hotbar_size - 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ function on_hud_open()
|
|||
end
|
||||
local id = block.get_picking_item(block.get(x, y, z))
|
||||
local inv, cur_slot = player.get_inventory(pid)
|
||||
local slot = inventory.find_by_item(inv, id, 0, 9)
|
||||
local hotbar_size = player.get_hotbar_size(pid)
|
||||
local slot = inventory.find_by_item(inv, id, 0, hotbar_size)
|
||||
if slot then
|
||||
player.set_selected_slot(pid, slot)
|
||||
return
|
||||
|
|
@ -51,7 +52,7 @@ function on_hud_open()
|
|||
if not rules.get("allow-content-access") then
|
||||
return
|
||||
end
|
||||
slot = inventory.find_by_item(inv, 0, 0, 9)
|
||||
slot = inventory.find_by_item(inv, 0, 0, hotbar_size)
|
||||
if slot then
|
||||
cur_slot = slot
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue