Beds: Strip colour bits from param2 in 'get look yaw'
authorparamat <paramat@users.noreply.github.com>
Thu, 28 Sep 2017 17:23:08 +0000 (18:23 +0100)
committerparamat <mat.gregory@virginmedia.com>
Thu, 28 Sep 2017 19:49:34 +0000 (20:49 +0100)
Based on code by github user 'hdak1945git'.
Fixes a crash when 'colorfacedir' param2 is used for beds.

mods/beds/functions.lua

index 78df9a1816b925c1c406b4e71b34781ed3050862..099f41feade9a50d2a96b8a8129dad75088e4858 100644 (file)
@@ -9,15 +9,18 @@ end
 -- Helper functions
 
 local function get_look_yaw(pos)
-       local n = minetest.get_node(pos)
-       if n.param2 == 1 then
-               return pi / 2, n.param2
-       elseif n.param2 == 3 then
-               return -pi / 2, n.param2
-       elseif n.param2 == 0 then
-               return pi, n.param2
+       local rotation = minetest.get_node(pos).param2
+       if rotation > 3 then
+               rotation = rotation % 4 -- Mask colorfacedir values
+       end
+       if rotation == 1 then
+               return pi / 2, rotation
+       elseif rotation == 3 then
+               return -pi / 2, rotation
+       elseif rotation == 0 then
+               return pi, rotation
        else
-               return 0, n.param2
+               return 0, rotation
        end
 end