From 8417cddf71f8eeb1f4024b06541b6289bab1c74e Mon Sep 17 00:00:00 2001 From: Louis Royer <4259825-lroyer@users.noreply.gitlab.com> Date: Tue, 4 Aug 2020 16:00:00 +0200 Subject: [PATCH 1/3] Add mod.conf for homedecor_common --- homedecor_common/mod.conf | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 homedecor_common/mod.conf diff --git a/homedecor_common/mod.conf b/homedecor_common/mod.conf new file mode 100644 index 00000000..f28d0883 --- /dev/null +++ b/homedecor_common/mod.conf @@ -0,0 +1,4 @@ +name = homedecor_common +description = Homedecor mod: common +depends = default, creative +optional_depends = intllib From 7f67f4a035808473a36d1d3c94ae752a5c11cea3 Mon Sep 17 00:00:00 2001 From: Louis Royer <4259825-lroyer@users.noreply.gitlab.com> Date: Tue, 4 Aug 2020 16:00:23 +0200 Subject: [PATCH 2/3] Add on_key_use and on_skeleton_key_use api for locked nodes --- homedecor_common/inventory.lua | 98 +++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 36 deletions(-) diff --git a/homedecor_common/inventory.lua b/homedecor_common/inventory.lua index 2a49228c..01c4b277 100644 --- a/homedecor_common/inventory.lua +++ b/homedecor_common/inventory.lua @@ -84,7 +84,8 @@ function homedecor.handle_inventory(name, def, original_def) end def.can_dig = def.can_dig or default_can_dig - def.on_metadata_inventory_move = def.on_metadata_inventory_move or function(pos, from_list, from_index, to_list, to_index, count, player) + def.on_metadata_inventory_move = def.on_metadata_inventory_move or + function(pos, from_list, from_index, to_list, to_index, count, player) minetest.log("action", S("@1 moves stuff in @2 at @3", player:get_player_name(), name, minetest.pos_to_string(pos) )) @@ -114,57 +115,82 @@ function homedecor.handle_inventory(name, def, original_def) local allow_move = def.allow_metadata_inventory_move def.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local playername = player:get_player_name() - - if playername == owner or - minetest.check_player_privs(playername, "protection_bypass") then - return allow_move and - allow_move(pos, from_list, from_index, to_list, to_index, count, player) or - count + if not default.can_interact_with_node(player, pos) then + minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", + player:get_player_name(), name, + minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos) + )) + return 0 end - - minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", - playername, name, owner, minetest.pos_to_string(pos) - )) - return 0 + return allow_move and allow_move(pos, from_list, from_index, to_list, to_index, count, player) or + count end local allow_put = def.allow_metadata_inventory_put def.allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local playername = player:get_player_name() - - if playername == owner or - minetest.check_player_privs(playername, "protection_bypass") then - return allow_put and allow_put(pos, listname, index, stack, player) or - stack:get_count() + if not default.can_interact_with_node(player, pos) then + minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", + player:get_player_name(), name, + minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos) + )) + return 0 end - - minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", - playername, name, owner, minetest.pos_to_string(pos) - )) - return 0 + return allow_put and allow_put(pos, listname, index, stack, player) or + stack:get_count() end local allow_take = def.allow_metadata_inventory_take def.allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not default.can_interact_with_node(player, pos) then + minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", + player:get_player_name(), name, + minetest.get_meta(pos):get_string("owner"), minetest.pos_to_string(pos) + )) + return 0 + end + return allow_take and allow_take(pos, listname, index, stack, player) or + stack:get_count() + end + + local can_dig = def.can_dig + def.can_dig = function(pos, player) + return default.can_interact_with_node(player, pos) and (can_dig and (can_dig(pos, player) or true)) + 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 = itemstack:get_meta() + + if secret ~= key_meta:get_string("secret") then + return + end + + minetest.show_formspec( + player:get_player_name(), + name.."_locked", + minetest.get_meta(pos):get_string("formspec") + ) + end + + def.on_skeleton_key_use = function(pos, player, newsecret) local meta = minetest.get_meta(pos) local owner = meta:get_string("owner") local playername = player:get_player_name() - if playername == owner or - minetest.check_player_privs(playername, "protection_bypass") then - return allow_take and allow_take(pos, listname, index, stack, player) or - stack:get_count() + -- verify placer is owner + if owner ~= playername then + minetest.record_protection_violation(pos, playername) + return nil end - minetest.log("action", S("@1 tried to access a @2 belonging to @3 at @4", - playername, name, owner, minetest.pos_to_string(pos) - )) - return 0 + local secret = meta:get_string("key_lock_secret") + if secret == "" then + secret = newsecret + meta:set_string("key_lock_secret", secret) + end + + return secret, meta:get_string("description"), owner end end From 18744ee66d0cc7d44e230453e9b7d6464942b05a Mon Sep 17 00:00:00 2001 From: Louis Royer <4259825-lroyer@users.noreply.gitlab.com> Date: Tue, 4 Aug 2020 16:12:47 +0200 Subject: [PATCH 3/3] Fix lines length related issues in homedecor_common --- .luacheckrc | 1 + homedecor_common/expansion.lua | 6 +++++- homedecor_common/nodeboxes.lua | 3 ++- homedecor_common/registration.lua | 6 +++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 0bf1acca..0d05eedf 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,5 +1,6 @@ unused_args = false allow_defined_top = true +max_comment_line_length = 999 read_globals = { "DIR_DELIM", diff --git a/homedecor_common/expansion.lua b/homedecor_common/expansion.lua index 26efc6a8..d274b7c4 100644 --- a/homedecor_common/expansion.lua +++ b/homedecor_common/expansion.lua @@ -146,7 +146,11 @@ function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, no local forceright = placer:get_player_control()["sneak"] local fdir = minetest.dir_to_facedir(placer:get_look_dir()) - local is_right_wing = node1 == minetest.get_node({ x = pos.x + homedecor.fdir_to_left[fdir+1][1], y=pos.y, z = pos.z + homedecor.fdir_to_left[fdir+1][2] }).name + local is_right_wing = node1 == minetest.get_node( + { + x = pos.x + homedecor.fdir_to_left[fdir+1][1], + y = pos.y, + z = pos.z + homedecor.fdir_to_left[fdir+1][2] }).name if forceright or is_right_wing then node1, node2 = node1_right, node2_right end diff --git a/homedecor_common/nodeboxes.lua b/homedecor_common/nodeboxes.lua index c0a7df79..0fafe1ab 100644 --- a/homedecor_common/nodeboxes.lua +++ b/homedecor_common/nodeboxes.lua @@ -22,7 +22,8 @@ homedecor.box = { end end, bar_y = function(radius) return {-radius, -0.5, -radius, radius, 0.5, radius} end, - cuboid = function(radius_x, radius_y, radius_z) return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end, + cuboid = function(radius_x, radius_y, radius_z) + return {-radius_x, -radius_y, -radius_z, radius_x, radius_y, radius_z} end, } homedecor.nodebox = { diff --git a/homedecor_common/registration.lua b/homedecor_common/registration.lua index f2d9bff7..7068c480 100644 --- a/homedecor_common/registration.lua +++ b/homedecor_common/registration.lua @@ -70,7 +70,11 @@ function homedecor.register(name, original_def) if not fdir or fdir > 3 then return end if expand.right and expand.forward ~= "air" then - local right_pos = { x=pos.x+homedecor.fdir_to_right[fdir+1][1], y=pos.y, z=pos.z+homedecor.fdir_to_right[fdir+1][2] } + local right_pos = { + x = pos.x + homedecor.fdir_to_right[fdir+1][1], + y = pos.y, + z = pos.z + homedecor.fdir_to_right[fdir+1][2] + } local node = minetest.get_node(right_pos).name if node == expand.right or node == placeholder_node then minetest.remove_node(right_pos)