From 175724d53c7ada7dde9eeca6d4119999d1c03ba0 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sun, 29 Jan 2017 03:45:58 -0500 Subject: [PATCH] add a function to correct for broken placement rotation for wallmounted nodes (engine or _game bug), and put it to use. --- homedecor/init.lua | 18 ++++++++++++++++++ homedecor/lighting.lua | 3 +++ homedecor/window_treatments.lua | 16 ++-------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/homedecor/init.lua b/homedecor/init.lua index 090e2b66..fa70ab15 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -65,6 +65,24 @@ function homedecor.find_ceiling(itemstack, placer, pointed_thing) return isceiling, pos end +-- call this function to reset the rotation of a "wallmounted" object on place + +function homedecor.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 + screwdriver = screwdriver or {} homedecor.plain_wood = { name = "homedecor_generic_wood_plain.png", color = 0xffa76820 } diff --git a/homedecor/lighting.lua b/homedecor/lighting.lua index f9f5d21d..c198225b 100644 --- a/homedecor/lighting.lua +++ b/homedecor/lighting.lua @@ -41,6 +41,7 @@ minetest.register_node("homedecor:glowlight_half", { groups = { snappy = 3 }, light_source = default.LIGHT_MAX, sounds = default.node_sound_glass_defaults(), + after_place_node = homedecor.fix_rotation, after_dig_node = unifieddyes.after_dig_node, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) unifieddyes.on_rightclick(pos, node, clicker, @@ -72,6 +73,7 @@ minetest.register_node("homedecor:glowlight_quarter", { groups = { snappy = 3 }, light_source = default.LIGHT_MAX-1, sounds = default.node_sound_glass_defaults(), + after_place_node = homedecor.fix_rotation, after_dig_node = unifieddyes.after_dig_node, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) unifieddyes.on_rightclick(pos, node, clicker, @@ -103,6 +105,7 @@ minetest.register_node("homedecor:glowlight_small_cube", { groups = { snappy = 3 }, light_source = default.LIGHT_MAX-1, sounds = default.node_sound_glass_defaults(), + after_place_node = homedecor.fix_rotation, after_dig_node = unifieddyes.after_dig_node, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) unifieddyes.on_rightclick(pos, node, clicker, diff --git a/homedecor/window_treatments.lua b/homedecor/window_treatments.lua index 8401ef69..6725695e 100644 --- a/homedecor/window_treatments.lua +++ b/homedecor/window_treatments.lua @@ -114,13 +114,7 @@ minetest.register_node("homedecor:curtain_closed", { palette = "unifieddyes_palette_colorwallmounted.png", selection_box = { type = "wallmounted" }, after_dig_node = unifieddyes.after_dig_node, - after_place_node = function(pos, placer, itemstack, pointed_thing) - local yaw = placer:get_look_yaw() - local dir = minetest.yaw_to_dir(yaw-1.5) - local fdir = minetest.dir_to_wallmounted(dir) - name = minetest.get_node(pos).name - minetest.swap_node(pos, { name = name, param2 = fdir }) - end, + after_place_node = homedecor.fix_rotation, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local itemname = itemstack:get_name() if string.find(itemname, "dye:") or string.find(itemname, "unifieddyes:") then @@ -151,13 +145,7 @@ minetest.register_node("homedecor:curtain_open", { palette = "unifieddyes_palette_colorwallmounted.png", selection_box = { type = "wallmounted" }, after_dig_node = unifieddyes.after_dig_node, - after_place_node = function(pos, placer, itemstack, pointed_thing) - local yaw = placer:get_look_yaw() - local dir = minetest.yaw_to_dir(yaw-1.5) - local fdir = minetest.dir_to_wallmounted(dir) - name = minetest.get_node(pos).name - minetest.swap_node(pos, { name = name, param2 = fdir }) - end, + after_place_node = homedecor.fix_rotation, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local itemname = itemstack:get_name() if string.find(itemname, "dye:") or string.find(itemname, "unifieddyes:") then