summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-03-06 14:21:05 -0500
committerGitHub <noreply@github.com>2017-03-06 14:21:05 -0500
commitdd580e7684408f8cc7e6fbdd895e8972ad5362dd (patch)
treed61925b5bc935de7c31a6a5c97a9d731672638af
parent663d272870be0c0812c85d942e0245ceb150ccce (diff)
parent6b52c789634e6999f65712d355a32b282801b874 (diff)
Merge pull request #307 from Thomas--S/patch-2
Update chest definitions to current minetest_game definitions
-rw-r--r--technic_chests/register.lua45
1 files changed, 44 insertions, 1 deletions
diff --git a/technic_chests/register.lua b/technic_chests/register.lua
index 25e4cde..bf2f0e1 100644
--- a/technic_chests/register.lua
+++ b/technic_chests/register.lua
@@ -263,12 +263,55 @@ 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] = "default: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.on_key_use = function(pos, player)
+ local secret = minetest.get_meta(pos):get_string("key_lock_secret")
+ local itemstack = player:get_wielded_item()
+ local key_meta = minetest.parse_json(itemstack:get_metadata())
+
+ if secret ~= key_meta.secret then
+ return
+ end
+
+ minetest.show_formspec(
+ player:get_player_name(),
+ "default:chest_locked",
+ get_locked_chest_formspec(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