Skip to content

Commit 7fbf25d

Browse files
committedNov 14, 2016
Do not show item overlay if slot is occupied by item (bookshelf, vessels shelf)
1 parent f8bc1e1 commit 7fbf25d

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed
 

Diff for: ‎mods/default/nodes.lua

+23-10
Original file line numberDiff line numberDiff line change
@@ -1815,16 +1815,23 @@ local bookshelf_formspec =
18151815
"listring[current_player;main]" ..
18161816
default.get_hotbar_bg(0,2.85)
18171817

1818-
-- Inventory slots overlay
1819-
local bx, by = 0, 0.3
1820-
for i = 1, 16 do
1821-
if i == 9 then
1822-
bx = 0
1823-
by = by + 1
1818+
local function get_bookshelf_formspec(inv)
1819+
local formspec = bookshelf_formspec
1820+
local invlist = inv and inv:get_list("books")
1821+
-- Inventory slots overlay
1822+
local bx, by = 0, 0.3
1823+
for i = 1, 16 do
1824+
if i == 9 then
1825+
bx = 0
1826+
by = by + 1
1827+
end
1828+
if not invlist or invlist[i]:is_empty() then
1829+
formspec = formspec ..
1830+
"image[" .. bx .. "," .. by .. ";1,1;default_bookshelf_slot.png]"
1831+
end
1832+
bx = bx + 1
18241833
end
1825-
bookshelf_formspec = bookshelf_formspec ..
1826-
"image[" .. bx .. "," .. by .. ";1,1;default_bookshelf_slot.png]"
1827-
bx = bx + 1
1834+
return formspec
18281835
end
18291836

18301837
minetest.register_node("default:bookshelf", {
@@ -1838,7 +1845,7 @@ minetest.register_node("default:bookshelf", {
18381845

18391846
on_construct = function(pos)
18401847
local meta = minetest.get_meta(pos)
1841-
meta:set_string("formspec", bookshelf_formspec)
1848+
meta:set_string("formspec", get_bookshelf_formspec(nil))
18421849
local inv = meta:get_inventory()
18431850
inv:set_size("books", 8 * 2)
18441851
end,
@@ -1855,14 +1862,20 @@ minetest.register_node("default:bookshelf", {
18551862
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
18561863
minetest.log("action", player:get_player_name() ..
18571864
" moves stuff in bookshelf at " .. minetest.pos_to_string(pos))
1865+
local meta = minetest.get_meta(pos)
1866+
meta:set_string("formspec", get_bookshelf_formspec(meta:get_inventory()))
18581867
end,
18591868
on_metadata_inventory_put = function(pos, listname, index, stack, player)
18601869
minetest.log("action", player:get_player_name() ..
18611870
" moves stuff to bookshelf at " .. minetest.pos_to_string(pos))
1871+
local meta = minetest.get_meta(pos)
1872+
meta:set_string("formspec", get_bookshelf_formspec(meta:get_inventory()))
18621873
end,
18631874
on_metadata_inventory_take = function(pos, listname, index, stack, player)
18641875
minetest.log("action", player:get_player_name() ..
18651876
" takes stuff from bookshelf at " .. minetest.pos_to_string(pos))
1877+
local meta = minetest.get_meta(pos)
1878+
meta:set_string("formspec", get_bookshelf_formspec(meta:get_inventory()))
18661879
end,
18671880
on_blast = function(pos)
18681881
local drops = {}

Diff for: ‎mods/vessels/init.lua

+23-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ local vessels_shelf_formspec =
1313
"listring[current_player;main]" ..
1414
default.get_hotbar_bg(0, 2.85)
1515

16-
-- Inventory slots overlay
17-
local vx, vy = 0, 0.3
18-
for i = 1, 16 do
19-
if i == 9 then
20-
vx = 0
21-
vy = vy + 1
16+
local function get_vessels_shelf_formspec(inv)
17+
local formspec = vessels_shelf_formspec
18+
local invlist = inv and inv:get_list("vessels")
19+
-- Inventory slots overlay
20+
local vx, vy = 0, 0.3
21+
for i = 1, 16 do
22+
if i == 9 then
23+
vx = 0
24+
vy = vy + 1
25+
end
26+
if not invlist or invlist[i]:is_empty() then
27+
formspec = formspec ..
28+
"image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
29+
end
30+
vx = vx + 1
2231
end
23-
vessels_shelf_formspec = vessels_shelf_formspec ..
24-
"image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
25-
vx = vx + 1
32+
return formspec
2633
end
2734

2835
minetest.register_node("vessels:shelf", {
@@ -36,7 +43,7 @@ minetest.register_node("vessels:shelf", {
3643

3744
on_construct = function(pos)
3845
local meta = minetest.get_meta(pos)
39-
meta:set_string("formspec", vessels_shelf_formspec)
46+
meta:set_string("formspec", get_vessels_shelf_formspec(nil))
4047
local inv = meta:get_inventory()
4148
inv:set_size("vessels", 8 * 2)
4249
end,
@@ -53,14 +60,20 @@ minetest.register_node("vessels:shelf", {
5360
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
5461
minetest.log("action", player:get_player_name() ..
5562
" moves stuff in vessels shelf at ".. minetest.pos_to_string(pos))
63+
local meta = minetest.get_meta(pos)
64+
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
5665
end,
5766
on_metadata_inventory_put = function(pos, listname, index, stack, player)
5867
minetest.log("action", player:get_player_name() ..
5968
" moves stuff to vessels shelf at ".. minetest.pos_to_string(pos))
69+
local meta = minetest.get_meta(pos)
70+
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
6071
end,
6172
on_metadata_inventory_take = function(pos, listname, index, stack, player)
6273
minetest.log("action", player:get_player_name() ..
6374
" takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
75+
local meta = minetest.get_meta(pos)
76+
meta:set_string("formspec", get_vessels_shelf_formspec(meta:get_inventory()))
6477
end,
6578
on_blast = function(pos)
6679
local drops = {}

0 commit comments

Comments
 (0)
Please sign in to comment.