Actually fix facedir-rotated nodes placed using minetest.env:place_node()
authorPerttu Ahola <celeron55@gmail.com>
Sat, 21 Jul 2012 18:23:15 +0000 (21:23 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 21 Jul 2012 18:23:15 +0000 (21:23 +0300)
builtin/item.lua
games/minimal/mods/experimental/init.lua

index 756c1de6a58bf7e72ae87e0cd2ca78b8fc6e5d3a..5cd28303a7c5cfedcc25bba65993d24d71b2ae24 100644 (file)
@@ -148,11 +148,13 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
                        local dir = {x = under.x - above.x, y = under.y - above.y, z = under.z - above.z}
                        newnode.param2 = minetest.dir_to_wallmounted(dir)
                -- Calculate the direction for furnaces and chests and stuff
-               elseif def.paramtype2 == 'facedir' and placer then
-                       local playerpos = placer:getpos()
-                       local dir = {x = pos.x - playerpos.x, y = pos.y - playerpos.y, z = pos.z - playerpos.z}
-                       newnode.param2 = minetest.dir_to_facedir(dir)
-                       minetest.log("action", "facedir: " .. newnode.param2)
+               elseif def.paramtype2 == 'facedir' then
+                       local placer_pos = placer:getpos()
+                       if placer_pos then
+                               local dir = {x = pos.x - placer_pos.x, y = pos.y - placer_pos.y, z = pos.z - placer_pos.z}
+                               newnode.param2 = minetest.dir_to_facedir(dir)
+                               minetest.log("action", "facedir: " .. newnode.param2)
+                       end
                end
 
                -- Add node and update
index fb331024606a9afe06567251af5773acd39d2cb6..5661a660fad6089480de281bdccfeab1b08c33bb 100644 (file)
@@ -447,6 +447,9 @@ minetest.register_node("experimental:tester_node_1", {
        tile_images = {"wieldhand.png"},
        groups = {oddly_breakable_by_hand=2},
        sounds = default.node_sound_wood_defaults(),
+       -- This was known to cause a bug in minetest.item_place_node() when used
+       -- via minetest.env:place_node(), causing a placer with no position
+       paramtype2 = "facedir",
 
        on_construct = function(pos)
                experimental.print_to_everything("experimental:tester_node_1:on_construct("..minetest.pos_to_string(pos)..")")