--[[ Eleficery --- Elemental trinkets for minetest game Copyright © 2026 bdunahu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . --]] eleficery.is_water = function(pos) return core.get_node(pos).name == "default:water_source" end eleficery.snap_to_cardinal = function(look_dir) local d = { x = look_dir.x, y = 0, z = look_dir.z } if vector.length(d) == 0 then return {x=0, y=0, z=1} end if math.abs(d.x) > math.abs(d.z) then d.z = 0 d.x = d.x > 0 and 1 or -1 else d.x = 0 d.z = d.z > 0 and 1 or -1 end return d end eleficery.get_held_dir_to_player = function(player) -- 'to_player' because this gives a position relative -- to the player's perspective local ctrl = player:get_player_control() local zero = {x=0, y=0, z=0} local look_dir = player:get_look_dir(placer) local forward = eleficery.snap_to_cardinal(look_dir) local back = vector.multiply(forward, -1) local up = {x=0, y=1, z=0} local right = vector.cross(up, forward) local left = vector.multiply(right, -1) if ctrl.up then return forward elseif ctrl.down then return back elseif ctrl.left then return left elseif ctrl.right then return right end end