summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-02-17 23:04:47 -0500
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-02-17 23:04:47 -0500
commit80e5429bf3da816600dd7a30e9b83a8af52bfe36 (patch)
treef37d212386c4ce869192a521117022d79fccafec
parent0aa55cc4d7b228aaa145cb0521f8b5212568c91a (diff)
downloadunifieddyes-80e5429bf3da816600dd7a30e9b83a8af52bfe36.tar
unifieddyes-80e5429bf3da816600dd7a30e9b83a8af52bfe36.tar.gz
unifieddyes-80e5429bf3da816600dd7a30e9b83a8af52bfe36.tar.bz2
unifieddyes-80e5429bf3da816600dd7a30e9b83a8af52bfe36.tar.xz
unifieddyes-80e5429bf3da816600dd7a30e9b83a8af52bfe36.zip
add helper functions for rotation correction
-rw-r--r--init.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 580218a..a45f2bf 100644
--- a/init.lua
+++ b/init.lua
@@ -93,6 +93,35 @@ local default_dyes = {
-- code borrowed from homedecor
+-- call this function to reset the rotation of a "wallmounted" object on place
+
+function unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
+ local node = minetest.get_node(pos)
+ local yaw = placer:get_look_yaw()
+ local dir = minetest.yaw_to_dir(yaw-1.5)
+ local pitch = placer:get_look_vertical()
+
+ local fdir = minetest.dir_to_wallmounted(dir)
+
+ if pitch < -(math.pi/4) then
+ fdir = 0
+ elseif pitch > math.pi/4 then
+ fdir = 1
+ end
+ minetest.swap_node(pos, { name = node.name, param2 = fdir })
+end
+
+-- use this when you have a "wallmounted" node that should never be oriented
+-- to floor or ceiling
+
+function unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
+ local node = minetest.get_node(pos)
+ local yaw = placer:get_look_yaw()
+ local dir = minetest.yaw_to_dir(yaw)
+ local fdir = minetest.dir_to_wallmounted(dir)
+ minetest.swap_node(pos, { name = node.name, param2 = fdir })
+end
+
function unifieddyes.select_node(pointed_thing)
local pos = pointed_thing.under
local node = minetest.get_node_or_nil(pos)