1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-06-28 04:40:22 +02:00

Add missing infotext to nodes (#2477)

This commit is contained in:
An0n3m0us
2019-09-14 19:30:26 +01:00
committed by sfan5
parent 888383a812
commit 1f7ea89cb6
4 changed files with 35 additions and 19 deletions

View File

@ -16,11 +16,15 @@ local vessels_shelf_formspec =
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 2.85)
local function get_vessels_shelf_formspec(inv)
local function update_vessels_shelf(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local invlist = inv:get_list("vessels")
local formspec = vessels_shelf_formspec
local invlist = inv and inv:get_list("vessels")
-- Inventory slots overlay
local vx, vy = 0, 0.3
local n_items = 0
for i = 1, 16 do
if i == 9 then
vx = 0
@ -29,10 +33,20 @@ local function get_vessels_shelf_formspec(inv)
if not invlist or invlist[i]:is_empty() then
formspec = formspec ..
"image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
else
local stack = invlist[i]
if not stack:is_empty() then
n_items = n_items + stack:get_count()
end
end
vx = vx + 1
end
return formspec
meta:set_string("formspec", formspec)
if n_items == 0 then
meta:set_string("infotext", S("Empty Vessel Shelf"))
else
meta:set_string("infotext", S("Vessel Shelf (@1 items)", n_items))
end
end
minetest.register_node("vessels:shelf", {
@ -46,7 +60,7 @@ minetest.register_node("vessels:shelf", {
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_vessels_shelf_formspec(nil))
update_vessels_shelf(pos)
local inv = meta:get_inventory()
inv:set_size("vessels", 8 * 2)
end,
@ -63,20 +77,17 @@ minetest.register_node("vessels:shelf", {
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name() ..
" moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
update_vessels_shelf(pos)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
update_vessels_shelf(pos)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
update_vessels_shelf(pos)
end,
on_blast = function(pos)
local drops = {}