From 9b5ef79d901c10f1da5045e04e2089ddd3af5213 Mon Sep 17 00:00:00 2001 From: Rotfuchs-von-Vulpes Date: Thu, 5 May 2022 21:32:14 -0400 Subject: [PATCH] remove globalstep --- help.lua | 41 ++++------------------------------------- init.lua | 14 +++++--------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/help.lua b/help.lua index 1cbb8e8..ade4c7a 100644 --- a/help.lua +++ b/help.lua @@ -1,6 +1,7 @@ -local what_is_this_owo = {} -what_is_this_owo.players = {} -what_is_this_owo.players_set = {} +local what_is_this_owo = { + players = {}, + players_set = {} +} local function split (str, sep) if sep == nil then @@ -133,40 +134,6 @@ function what_is_this_owo.remove_player(player, name) end end -function what_is_this_owo.get_pointed_thing(player) - -- get player position - local player_pos = player:get_pos() - local eye_height = player:get_properties().eye_height - local eye_offset = player:get_eye_offset() - player_pos.y = player_pos.y + eye_height - player_pos = vector.add(player_pos, eye_offset) - - -- set liquids vision - local see_liquid = - minetest.registered_nodes[minetest.get_node(player_pos).name].drawtype ~= 'liquid' - - -- get wielded item range 5 is engine default - -- order tool/item range >> hand_range >> fallback 5 - local tool_range = player:get_wielded_item():get_definition().range or nil - local hand_range - for key, val in pairs(minetest.registered_items) do - if key == "" then - hand_range = val.range or nil - end - end - local wield_range = tool_range or hand_range or 5 - - -- determine ray end position - local look_dir = player:get_look_dir() - look_dir = vector.multiply(look_dir, wield_range) - local end_pos = vector.add(look_dir, player_pos) - - -- get pointed_thing - local ray = minetest.raycast(player_pos, end_pos, false, see_liquid) - - return ray:next() -end - function what_is_this_owo.get_node_tile(node_name) local node = minetest.registered_nodes[node_name] diff --git a/init.lua b/init.lua index a22200a..62f0daf 100644 --- a/init.lua +++ b/init.lua @@ -62,14 +62,12 @@ minetest.register_on_joinplayer(function(player) what_is_this_owo.register_player(player, player:get_player_name()) end) -minetest.register_globalstep(function() - for _, player in ipairs(what_is_this_owo.players) do +minetest.register_on_punchnode(function(pos, node, player, pointed_thing) + if what_is_this_owo.players_set[player:get_player_name()] then local meta = player:get_meta() + local node_name = node.name - local pointed_thing = what_is_this_owo.get_pointed_thing(player, meta) - - if pointed_thing then - local node_name = minetest.get_node(pointed_thing.under).name + if meta:get_string('wit:pointed_thing') ~= node_name then local form_view, item_type, node_definition = what_is_this_owo.get_node_tile(node_name, meta) if not node_definition then @@ -81,9 +79,7 @@ minetest.register_globalstep(function() local node_description = what_is_this_owo.destrange(node_definition.description) local mod_name, _ = what_is_this_owo.split_item_name(node_name) - if meta:get_string('wit:pointed_thing') ~= node_name then - what_is_this_owo.show(player, meta, form_view, node_description, node_name, item_type, mod_name) - end + what_is_this_owo.show(player, meta, form_view, node_description, node_name, item_type, mod_name) else what_is_this_owo.unshow(player, meta) end