]> git.lizzy.rs Git - minetest.git/blob - games/devtest/mods/chest/detached.lua
DevTest: Use 4dir for chests
[minetest.git] / games / devtest / mods / chest / detached.lua
1 local ALLOW_PUT_MAX = 1
2 local ALLOW_TAKE_MAX = 4
3
4 local function print_to_everything(msg)
5         minetest.log("action", "[chest] " .. msg)
6         minetest.chat_send_all(msg)
7 end
8
9 -- Create a detached inventory
10 local inv = minetest.create_detached_inventory("detached_inventory", {
11         allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
12                 print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_move")
13                 return count -- Allow all
14         end,
15         allow_put = function(inv, listname, index, stack, player)
16                 print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_put for "..stack:to_string().." (max. allowed: "..ALLOW_PUT_MAX..")")
17                 return ALLOW_PUT_MAX -- Allow to put a limited amount of items
18         end,
19         allow_take = function(inv, listname, index, stack, player)
20                 print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_take for "..stack:to_string().." (max. allowed: "..ALLOW_TAKE_MAX..")")
21                 return ALLOW_TAKE_MAX -- Allow to take a limited amount of items
22         end,
23         on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
24                 print_to_everything("Detached inventory: " .. player:get_player_name().." moved item(s)")
25         end,
26         on_put = function(inv, listname, index, stack, player)
27                 print_to_everything("Detached inventory: " .. player:get_player_name().." put "..stack:to_string())
28         end,
29         on_take = function(inv, listname, index, stack, player)
30                 print_to_everything("Detached inventory: " .. player:get_player_name().." took "..stack:to_string())
31         end,
32 })
33 inv:set_size("main", 8*3)
34
35
36 -- Add a special chest to grant access to this inventory
37 minetest.register_node("chest:detached_chest", {
38         description = "Detached Chest" .. "\n" ..
39                 "Grants access to a shared detached inventory" .."\n" ..
40                 "Max. item put count: "..ALLOW_PUT_MAX .."\n"..
41                 "Max. item take count: "..ALLOW_TAKE_MAX,
42         tiles = {"chest_detached_chest.png^[sheet:2x2:0,0", "chest_detached_chest.png^[sheet:2x2:0,0",
43                 "chest_detached_chest.png^[sheet:2x2:1,0", "chest_detached_chest.png^[sheet:2x2:1,0",
44                 "chest_detached_chest.png^[sheet:2x2:1,0", "chest_detached_chest.png^[sheet:2x2:0,1"},
45         paramtype2 = "4dir",
46         groups = {dig_immediate=2,choppy=3,meta_is_privatizable=1},
47         is_ground_content = false,
48         on_construct = function(pos)
49                 local meta = minetest.get_meta(pos)
50                 meta:set_string("formspec",
51                         "size[8,9]"..
52                         "list[detached:detached_inventory;main;0,0;8,3;0]"..
53                         "list[current_player;main;0,5;8,4;]"..
54                         "listring[]")
55                 meta:set_string("infotext", "Detached Chest")
56         end,
57 })
58