Remove lots of redundant code in kerova
[minetest_hades/hades_revisited.git] / mods / kerova / init.lua
blobeb3ecf90618ec15d1e7ffa0a5d880dba561902d9
1 --[[
2 Kerova Mod
3 By AndromedaKerova (AKA; RommieKerova, Rommie, Andromeda) (rommiekerova@gmail.com)
4 License: WTFPL
5 Version: 1.2 - is a reduced version only with colored chests.. code deleted by Glunggi :D
6 --]]
8 local chest_formspec = default.chest_formspec
9 local get_locked_chest_formspec = default.get_locked_chest_formspec
11 local function has_locked_chest_privilege(meta, player)
12 if player:get_player_name() ~= meta:get_string("owner") then
13 return false
14 end
15 return true
16 end
18 local chests = {
19 { "white", "White Chest", "White Locked Chest" },
20 { "grey", "Grey Chest", "Grey Locked Chest" },
21 { "dark_grey", "Dark Grey Chest", "Dark Grey Locked Chest" },
22 { "black", "Black Chest", "Black Locked Chest" },
23 { "blue", "Blue Chest", "Blue Locked Chest" },
24 { "cyan", "Cyan Chest", "Cyan Locked Chest" },
25 { "dark_green", "Dark Green Chest", "Dark Green Locked Chest" },
26 { "green", "Green Chest", "Green Locked Chest" },
27 { "magenta", "Magenta Chest", "Magenta Locked Chest" },
28 { "orange", "Orange Chest", "Orange Locked Chest" },
29 { "pink", "Pink Chest", "Pink Locked Chest" },
30 { "red", "Red Chest", "Red Locked Chest" },
31 { "violet", "Violet Chest", "Violet Locked Chest" },
32 { "yellow", "Yellow Chest", "Yellow Locked Chest" },
36 for c=1, #chests do
38 local sub = chests[c][1]
39 local desc_unlocked = chests[c][2]
40 local desc_locked = chests[c][3]
42 minetest.register_node("kerova:chest_"..sub, {
43 description = desc_unlocked,
44 tiles = {"kerova_chest_top_"..sub..".png", "kerova_chest_top_"..sub..".png", "kerova_chest_"..sub..".png",
45 "kerova_chest_"..sub..".png", "kerova_chest_"..sub..".png", "kerova_chest_front_"..sub..".png"},
46 paramtype2 = "facedir",
47 groups = {choppy=2,oddly_breakable_by_hand=2, chest=1},
48 legacy_facedir_simple = true,
49 sounds = default.node_sound_wood_defaults(),
50 on_construct = function(pos)
51 local meta = minetest.get_meta(pos)
52 meta:set_string("formspec", chest_formspec)
53 meta:set_string("infotext", desc_unlocked)
54 local inv = meta:get_inventory()
55 inv:set_size("main", 8*4)
56 end,
57 can_dig = function(pos,player)
58 local meta = minetest.get_meta(pos);
59 local inv = meta:get_inventory()
60 return inv:is_empty("main")
61 end,
62 on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
63 minetest.log("action", player:get_player_name()..
64 " moves stuff in chest at "..minetest.pos_to_string(pos))
65 end,
66 on_metadata_inventory_put = function(pos, listname, index, stack, player)
67 minetest.log("action", player:get_player_name()..
68 " moves stuff to chest at "..minetest.pos_to_string(pos))
69 end,
70 on_metadata_inventory_take = function(pos, listname, index, stack, player)
71 minetest.log("action", player:get_player_name()..
72 " takes stuff from chest at "..minetest.pos_to_string(pos))
73 end,
75 minetest.register_node("kerova:chest_"..sub.."_locked", {
76 description = desc_locked,
77 tiles = {"kerova_chest_top_"..sub..".png", "kerova_chest_top_"..sub..".png", "kerova_chest_"..sub..".png",
78 "kerova_chest_"..sub..".png", "kerova_chest_"..sub..".png", "kerova_chest_lock_"..sub..".png"},
79 paramtype2 = "facedir",
80 groups = {choppy=2,oddly_breakable_by_hand=2, locked_chest=1},
81 legacy_facedir_simple = true,
82 is_ground_content = false,
83 sounds = default.node_sound_wood_defaults(),
85 after_place_node = function(pos, placer)
86 local meta = minetest.get_meta(pos)
87 meta:set_string("owner", placer:get_player_name() or "")
88 meta:set_string("infotext", desc_locked .." (owned by "..
89 meta:get_string("owner")..")")
90 end,
91 on_construct = function(pos)
92 local meta = minetest.get_meta(pos)
93 meta:set_string("infotext", desc_locked)
94 meta:set_string("owner", "")
95 local inv = meta:get_inventory()
96 inv:set_size("main", 8*4)
97 end,
98 can_dig = function(pos,player)
99 local meta = minetest.get_meta(pos);
100 local inv = meta:get_inventory()
101 return inv:is_empty("main") and has_locked_chest_privilege(meta, player)
102 end,
103 allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
104 local meta = minetest.get_meta(pos)
105 if not has_locked_chest_privilege(meta, player) then
106 return 0
108 return count
109 end,
110 allow_metadata_inventory_put = function(pos, listname, index, stack, player)
111 local meta = minetest.get_meta(pos)
112 if not has_locked_chest_privilege(meta, player) then
113 return 0
115 return stack:get_count()
116 end,
117 allow_metadata_inventory_take = function(pos, listname, index, stack, player)
118 local meta = minetest.get_meta(pos)
119 if not has_locked_chest_privilege(meta, player) then
120 return 0
122 return stack:get_count()
123 end,
124 on_metadata_inventory_put = function(pos, listname, index, stack, player)
125 minetest.log("action", player:get_player_name()..
126 " moves stuff to locked chest at "..minetest.pos_to_string(pos))
127 end,
128 on_metadata_inventory_take = function(pos, listname, index, stack, player)
129 minetest.log("action", player:get_player_name()..
130 " takes stuff from locked chest at "..minetest.pos_to_string(pos))
131 end,
132 on_rightclick = function(pos, node, clicker)
133 local meta = minetest.get_meta(pos)
134 if has_locked_chest_privilege(meta, clicker) then
135 minetest.show_formspec(
136 clicker:get_player_name(),
137 "default:chest_locked",
138 get_locked_chest_formspec(pos)
141 end,
144 minetest.register_craft({
145 output = "kerova:chest_"..sub,
146 recipe = {
147 {"dye:"..sub},
148 {"group:chest"},
151 minetest.register_craft({
152 output = "kerova:chest_"..sub.."_locked",
153 recipe = {
154 {"dye:"..sub},
155 {"group:locked_chest"},