summaryrefslogtreecommitdiff
path: root/utils.lua
diff options
context:
space:
mode:
authorbdunahu <bdunahu@operationnull.com>2026-04-04 20:24:32 -0400
committerbdunahu <bdunahu@operationnull.com>2026-04-04 20:25:51 -0400
commit54d4122e67a2cd38770f71a90b9fe4231796d3a6 (patch)
tree141530af489b0ef3d245e1ea59383c376ce282c5 /utils.lua
initial commit: ice serpentHEADmaster
Diffstat (limited to 'utils.lua')
-rw-r--r--utils.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/utils.lua b/utils.lua
new file mode 100644
index 0000000..5242949
--- /dev/null
+++ b/utils.lua
@@ -0,0 +1,62 @@
+--[[
+Eleficery --- Elemental trinkets for minetest game
+Copyright © 2026 bdunahu <bdunahu@operationnull.com>
+
+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 <https://www.gnu.org/licenses/>.
+--]]
+
+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