From ad63d3d6913887e6388f6eb7ddf12f94ab3c11d0 Mon Sep 17 00:00:00 2001 From: Zemtzov7 <72821250+zmv7@users.noreply.github.com> Date: Wed, 11 Oct 2023 23:03:15 +0500 Subject: [PATCH] Refuse take/put in wifi chest if there is no more_chest:wifi node near (#30) Exception: creative players --- models/wifi.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/models/wifi.lua b/models/wifi.lua index 506bac9..9851ba6 100644 --- a/models/wifi.lua +++ b/models/wifi.lua @@ -87,3 +87,20 @@ minetest.register_on_joinplayer(function(player) local inv = player:get_inventory() inv:set_size("more_chests:wifi", 8*4) end) + +minetest.register_allow_player_inventory_action(function(player, action, inventory, inventory_info) + if (inventory_info.to_list == "more_chests:wifi" or inventory_info.from_list == "more_chests:wifi") + and not minetest.is_creative_enabled(player:get_player_name()) then + local pos = player:get_pos() + pos.y = pos.y + player:get_properties().eye_height + + local def = player:get_wielded_item():get_definition() + local range = def and def.range or 4 + -- Additional tolerance to reach the node corner diagonally + -- Also allows minor eye offsets to be used + local chest = minetest.find_node_near(pos, range + 1, "more_chests:wifi") + if not chest then + return 0 + end + end +end)