Skip to content

Commit

Permalink
Shelves: Fix listring functionality + code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Patrick Guerrero authored and paramat committed Mar 30, 2016
1 parent 14334a1 commit 12bcfea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 69 deletions.
39 changes: 6 additions & 33 deletions mods/default/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1574,43 +1574,16 @@ minetest.register_node("default:bookshelf", {
inv:set_size("books", 8 * 2)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("books")
end,

allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local to_stack = inv:get_stack(listname, index)
if listname == "books" then
if minetest.get_item_group(stack:get_name(), "book") ~= 0
and to_stack:is_empty() then
return 1
else
return 0
end
allow_metadata_inventory_put = function(pos, listname, index, stack)
if minetest.get_item_group(stack:get_name(), "book") ~= 0 then
return stack:get_count()
end
return 0
end,

allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
local to_stack = inv:get_stack(to_list, to_index)
if to_list == "books" then
if minetest.get_item_group(stack:get_name(), "book") ~= 0
and to_stack:is_empty() then
return 1
else
return 0
end
end
end,

on_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
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 bookshelf at " .. minetest.pos_to_string(pos))
end,
Expand Down
47 changes: 11 additions & 36 deletions mods/vessels/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,29 @@ minetest.register_node("vessels:shelf", {
local meta = minetest.get_meta(pos)
meta:set_string("formspec", vessels_shelf_formspec)
local inv = meta:get_inventory()
inv:set_size("vessels", 8*2)
inv:set_size("vessels", 8 * 2)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("vessels")
end,

allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local to_stack = inv:get_stack(listname, index)
if listname == "vessels" then
if minetest.get_item_group(stack:get_name(), "vessel") ~= 0
and to_stack:is_empty() then
return 1
else
return 0
end
end
end,

allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
local to_stack = inv:get_stack(to_list, to_index)
if to_list == "vessels" then
if minetest.get_item_group(stack:get_name(), "vessel") ~= 0
and to_stack:is_empty() then
return 1
else
return 0
end
if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
return stack:get_count()
end
return 0
end,

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))
minetest.log("action", player:get_player_name() ..
" moves stuff in vessels shelf at ".. minetest.pos_to_string(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))
minetest.log("action", player:get_player_name() ..
" moves stuff to vessels shelf at ".. minetest.pos_to_string(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))
minetest.log("action", player:get_player_name() ..
" takes stuff from vessels shelf at ".. minetest.pos_to_string(pos))
end,
})

Expand Down

0 comments on commit 12bcfea

Please sign in to comment.