Doors: Remove unnecessary node lookups

This commit is contained in:
Tim 2016-07-02 02:30:45 +02:00 committed by paramat
parent 71c7e21669
commit 594365310d

View File

@ -16,7 +16,8 @@ _doors.registered_trapdoors = {}
-- returns an object to a door object or nil -- returns an object to a door object or nil
function doors.get(pos) function doors.get(pos)
if _doors.registered_doors[minetest.get_node(pos).name] then local node_name = minetest.get_node(pos).name
if _doors.registered_doors[node_name] then
-- A normal upright door -- A normal upright door
return { return {
pos = pos, pos = pos,
@ -40,7 +41,7 @@ function doors.get(pos)
return state %2 == 1 return state %2 == 1
end end
} }
elseif _doors.registered_trapdoors[minetest.get_node(pos).name] then elseif _doors.registered_trapdoors[node_name] then
-- A trapdoor -- A trapdoor
return { return {
pos = pos, pos = pos,
@ -60,8 +61,7 @@ function doors.get(pos)
return _doors.trapdoor_toggle(self.pos, player) return _doors.trapdoor_toggle(self.pos, player)
end, end,
state = function(self) state = function(self)
local name = minetest.get_node(pos).name return node_name:sub(-5) == "_open"
return name:sub(-5) == "_open"
end end
} }
else else
@ -129,15 +129,15 @@ local transform = {
}, },
} }
function _doors.door_toggle(pos, clicker) function _doors.door_toggle(pos, node, clicker)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local def = minetest.registered_nodes[minetest.get_node(pos).name] local def = minetest.registered_nodes[node.name]
local name = def.door.name local name = def.door.name
local state = meta:get_string("state") local state = meta:get_string("state")
if state == "" then if state == "" then
-- fix up lvm-placed right-hinged doors, default closed -- fix up lvm-placed right-hinged doors, default closed
if minetest.get_node(pos).name:sub(-2) == "_b" then if node.name:sub(-2) == "_b" then
state = 2 state = 2
else else
state = 0 state = 0
@ -163,7 +163,7 @@ function _doors.door_toggle(pos, clicker)
state = state + 1 state = state + 1
end end
local dir = minetest.get_node(pos).param2 local dir = node.param2
if state % 2 == 0 then if state % 2 == 0 then
minetest.sound_play(def.door.sounds[1], minetest.sound_play(def.door.sounds[1],
{pos = pos, gain = 0.3, max_hear_distance = 10}) {pos = pos, gain = 0.3, max_hear_distance = 10})
@ -374,7 +374,7 @@ function doors.register(name, def)
} }
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
_doors.door_toggle(pos, clicker) _doors.door_toggle(pos, node, clicker)
return itemstack return itemstack
end end
def.after_dig_node = function(pos, node, meta, digger) def.after_dig_node = function(pos, node, meta, digger)
@ -507,7 +507,7 @@ end
----trapdoor---- ----trapdoor----
function _doors.trapdoor_toggle(pos, clicker) function _doors.trapdoor_toggle(pos, node, clicker)
if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("doors_owner") local owner = meta:get_string("doors_owner")
@ -518,7 +518,6 @@ function _doors.trapdoor_toggle(pos, clicker)
end end
end end
local node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if string.sub(node.name, -5) == "_open" then if string.sub(node.name, -5) == "_open" then
@ -549,7 +548,7 @@ function doors.register_trapdoor(name, def)
end end
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
_doors.trapdoor_toggle(pos, clicker) _doors.trapdoor_toggle(pos, node, clicker)
return itemstack return itemstack
end end
@ -684,7 +683,6 @@ function doors.register_fencegate(name, def)
groups = def.groups, groups = def.groups,
sounds = def.sounds, sounds = def.sounds,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local node = minetest.get_node(pos)
local node_def = minetest.registered_nodes[node.name] local node_def = minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2}) minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3, minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,