summaryrefslogtreecommitdiff
path: root/technic_chests
diff options
context:
space:
mode:
Diffstat (limited to 'technic_chests')
-rw-r--r--technic_chests/common.lua23
-rw-r--r--technic_chests/register.lua35
2 files changed, 41 insertions, 17 deletions
diff --git a/technic_chests/common.lua b/technic_chests/common.lua
index 47054f5..32b34eb 100644
--- a/technic_chests/common.lua
+++ b/technic_chests/common.lua
@@ -26,12 +26,7 @@ technic.chests.can_dig = function(pos, player)
end
local function inv_change(pos, count, player)
- local meta = minetest.get_meta(pos)
- if not has_locked_chest_privilege(meta, player) then
- minetest.log("action", player:get_player_name()..
- " tried to access a locked chest belonging to "..
- meta:get_string("owner").." at "..
- minetest.pos_to_string(pos))
+ if not default.can_interact_with_node(player, pos) then
return 0
end
return count
@@ -54,18 +49,14 @@ function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_inde
end
function technic.chests.on_inv_put(pos, listname, index, stack, player)
- minetest.log("action", player:get_player_name()..
- " puts stuff in to chest at "
- ..minetest.pos_to_string(pos))
+ minetest.log("action", player:get_player_name() ..
+ " moves " .. stack:get_name() ..
+ " to chest at " .. minetest.pos_to_string(pos))
end
function technic.chests.on_inv_take(pos, listname, index, stack, player)
- minetest.log("action", player:get_player_name()..
- " takes stuff from chest at "
- ..minetest.pos_to_string(pos))
-end
-
-function has_locked_chest_privilege(meta, player)
- return player:get_player_name() == meta:get_string("owner")
+ minetest.log("action", player:get_player_name() ..
+ " takes " .. stack:get_name() ..
+ " from chest at " .. minetest.pos_to_string(pos))
end
diff --git a/technic_chests/register.lua b/technic_chests/register.lua
index 25e4cde..6a5b8db 100644
--- a/technic_chests/register.lua
+++ b/technic_chests/register.lua
@@ -263,12 +263,45 @@ function technic.chests:definition(name, data)
on_receive_fields = get_receive_fields(name, data),
on_metadata_inventory_move = self.on_inv_move,
on_metadata_inventory_put = self.on_inv_put,
- on_metadata_inventory_take = self.on_inv_take,
+ on_metadata_inventory_take = self.on_inv_take,
+ on_blast = function(pos)
+ local drops = {}
+ default.get_inventory_drops(pos, "main", drops)
+ drops[#drops+1] = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest"
+ minetest.remove_node(pos)
+ return drops
+ end,
}
if data.locked then
def.allow_metadata_inventory_move = self.inv_move
def.allow_metadata_inventory_put = self.inv_put
def.allow_metadata_inventory_take = self.inv_take
+ def.on_blast = function() end
+ def.can_dig = function(pos,player)
+ local meta = minetest.get_meta(pos);
+ local inv = meta:get_inventory()
+ return inv:is_empty("main") and default.can_interact_with_node(player, pos)
+ end
+ def.on_skeleton_key_use = function(pos, player, newsecret)
+ local meta = minetest.get_meta(pos)
+ local owner = meta:get_string("owner")
+ local name = player:get_player_name()
+
+ -- verify placer is owner of lockable chest
+ if owner ~= name then
+ minetest.record_protection_violation(pos, name)
+ minetest.chat_send_player(name, "You do not own this chest.")
+ return nil
+ end
+
+ local secret = meta:get_string("key_lock_secret")
+ if secret == "" then
+ secret = newsecret
+ meta:set_string("key_lock_secret", secret)
+ end
+
+ return secret, "a locked chest", owner
+ end
end
return def
end