forked from SmallJoker/simple_protection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchest.lua
More file actions
80 lines (73 loc) · 2.56 KB
/
chest.lua
File metadata and controls
80 lines (73 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local S = s_protect.gettext
-- A shared chest for simple_protection but works with other protection mods too
local function get_item_count(pos, player, count)
local name = player and player:get_player_name()
if not name or minetest.is_protected(pos, name) then
return 0
end
return count
end
local tex_mod = "^[colorize:#FF2:50"
minetest.register_node("simple_protection:chest", {
description = S("Shared Chest") .. " " .. S("(by protection)"),
tiles = {
"default_chest_top.png" .. tex_mod,
"default_chest_top.png" .. tex_mod,
"default_chest_side.png" .. tex_mod,
"default_chest_side.png" .. tex_mod,
"default_chest_side.png" .. tex_mod,
"default_chest_lock.png" .. tex_mod
},
paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(),
groups = {choppy = 2, oddly_breakable_by_hand = 2},
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Shared Chest"))
meta:set_string("formspec",
"size[8,9]" ..
default.gui_bg ..
default.gui_bg_img ..
"list[context;main;0,0.3;8,4;]" ..
"list[current_player;main;0,5;8,4;]" ..
"listring[context;main]" ..
"listring[current_player;main]"
)
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
can_dig = function(pos, player)
return minetest.get_meta(pos):get_inventory():is_empty("main")
end,
on_blast = function() end,
allow_metadata_inventory_put = function(pos, fl, fi, stack, player)
return get_item_count(pos, player, stack:get_count())
end,
allow_metadata_inventory_take = function(pos, fl, fi, stack, player)
return get_item_count(pos, player, stack:get_count())
end,
allow_metadata_inventory_move = function(pos, fl, fi, tl, ti, count, player)
return get_item_count(pos, player, count)
end,
on_metadata_inventory_put = function(pos, fl, fi, stack, player)
minetest.log("action", player:get_player_name()
.. " moves " .. stack:get_name() .. " to shared chest at "
.. minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, fl, fi, stack, player)
minetest.log("action", player:get_player_name()
.. " takes " .. stack:get_name() .. " from shared chest at "
.. minetest.pos_to_string(pos))
end,
-- on_metadata_inventory_move logging is redundant: Same chest contents
})
minetest.register_craft({
type = "shapeless",
output = "simple_protection:shared_chest",
recipe = { "simple_protection:claim", "default:chest_locked" }
})
minetest.register_craft({
type = "shapeless",
output = "simple_protection:shared_chest",
recipe = { "simple_protection:claim", "default:chest" }
})