]> git.lizzy.rs Git - minetest.git/blobdiff - builtin/game/item.lua
Builtin/../falling.lua: Code optimisation
[minetest.git] / builtin / game / item.lua
index c168bf09610bc40a5ed7b9adb1b9fd58a9aebfc9..26ff8225c15715361399406778ffa79d6b2174a7 100644 (file)
@@ -88,25 +88,26 @@ function core.dir_to_facedir(dir, is6d)
        end
 end
 
+-- Table of possible dirs
+local facedir_to_dir = {
+       {x= 0, y=0,  z= 1},
+       {x= 1, y=0,  z= 0},
+       {x= 0, y=0,  z=-1},
+       {x=-1, y=0,  z= 0},
+       {x= 0, y=-1, z= 0},
+       {x= 0, y=1,  z= 0},
+}
+-- Mapping from facedir value to index in facedir_to_dir.
+local facedir_to_dir_map = {
+       [0]=1, 2, 3, 4,
+       5, 2, 6, 4,
+       6, 2, 5, 4,
+       1, 5, 3, 6,
+       1, 6, 3, 5,
+       1, 4, 3, 2,
+}
 function core.facedir_to_dir(facedir)
-       --a table of possible dirs
-       return ({{x=0, y=0, z=1},
-                                       {x=1, y=0, z=0},
-                                       {x=0, y=0, z=-1},
-                                       {x=-1, y=0, z=0},
-                                       {x=0, y=-1, z=0},
-                                       {x=0, y=1, z=0}})
-
-                                       --indexed into by a table of correlating facedirs
-                                       [({[0]=1, 2, 3, 4,
-                                               5, 2, 6, 4,
-                                               6, 2, 5, 4,
-                                               1, 5, 3, 6,
-                                               1, 6, 3, 5,
-                                               1, 4, 3, 2})
-
-                                               --indexed into by the facedir in question
-                                               [facedir]]
+       return facedir_to_dir[facedir_to_dir_map[facedir]]
 end
 
 function core.dir_to_wallmounted(dir)
@@ -131,17 +132,17 @@ function core.dir_to_wallmounted(dir)
        end
 end
 
+-- table of dirs in wallmounted order
+local wallmounted_to_dir = {
+       [0] = {x = 0, y = 1, z = 0},
+       {x =  0, y = -1, z =  0},
+       {x =  1, y =  0, z =  0},
+       {x = -1, y =  0, z =  0},
+       {x =  0, y =  0, z =  1},
+       {x =  0, y =  0, z = -1},
+}
 function core.wallmounted_to_dir(wallmounted)
-       -- table of dirs in wallmounted order
-       return ({[0] = {x = 0, y = 1, z = 0},
-               {x = 0,  y = -1, z = 0},
-               {x = 1,  y = 0,  z = 0},
-               {x = -1, y = 0,  z = 0},
-               {x = 0,  y = 0,  z = 1},
-               {x = 0,  y = 0,  z = -1}})
-
-               --indexed into by the wallmounted in question
-               [wallmounted]
+       return wallmounted_to_dir[wallmounted]
 end
 
 function core.get_node_drops(nodename, toolname)
@@ -232,7 +233,8 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
                place_to = {x = under.x, y = under.y, z = under.z}
        end
 
-       if core.is_protected(place_to, placer:get_player_name()) then
+       if core.is_protected(place_to, placer:get_player_name()) and
+                       not minetest.check_player_privs(placer, "protection_bypass") then
                core.log("action", placer:get_player_name()
                                .. " tried to place " .. def.name
                                .. " at protected position "
@@ -248,7 +250,9 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
        local newnode = {name = def.name, param1 = 0, param2 = param2}
 
        -- Calculate direction for wall mounted stuff like torches and signs
-       if def.paramtype2 == 'wallmounted' and not param2 then
+       if def.place_param2 ~= nil then
+               newnode.param2 = def.place_param2
+       elseif def.paramtype2 == 'wallmounted' and not param2 then
                local dir = {
                        x = under.x - above.x,
                        y = under.y - above.y,
@@ -443,7 +447,8 @@ function core.node_dig(pos, node, digger)
                return
        end
 
-       if core.is_protected(pos, digger:get_player_name()) then
+       if core.is_protected(pos, digger:get_player_name()) and
+                       not minetest.check_player_privs(digger, "protection_bypass") then
                core.log("action", digger:get_player_name()
                                .. " tried to dig " .. node.name
                                .. " at protected position "