Skip to content

Commit

Permalink
remove globalstep
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotfuchs-von-Vulpes committed May 6, 2022
1 parent ba7effb commit 9b5ef79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 46 deletions.
41 changes: 4 additions & 37 deletions help.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]

Expand Down
14 changes: 5 additions & 9 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9b5ef79

Please sign in to comment.