Doors: Remove unnecessary node lookups
This commit is contained in:
parent
71c7e21669
commit
594365310d
@ -16,7 +16,8 @@ _doors.registered_trapdoors = {}
|
||||
|
||||
-- returns an object to a door object or nil
|
||||
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
|
||||
return {
|
||||
pos = pos,
|
||||
@ -40,7 +41,7 @@ function doors.get(pos)
|
||||
return state %2 == 1
|
||||
end
|
||||
}
|
||||
elseif _doors.registered_trapdoors[minetest.get_node(pos).name] then
|
||||
elseif _doors.registered_trapdoors[node_name] then
|
||||
-- A trapdoor
|
||||
return {
|
||||
pos = pos,
|
||||
@ -60,8 +61,7 @@ function doors.get(pos)
|
||||
return _doors.trapdoor_toggle(self.pos, player)
|
||||
end,
|
||||
state = function(self)
|
||||
local name = minetest.get_node(pos).name
|
||||
return name:sub(-5) == "_open"
|
||||
return node_name:sub(-5) == "_open"
|
||||
end
|
||||
}
|
||||
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 def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local name = def.door.name
|
||||
|
||||
local state = meta:get_string("state")
|
||||
if state == "" then
|
||||
-- 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
|
||||
else
|
||||
state = 0
|
||||
@ -163,7 +163,7 @@ function _doors.door_toggle(pos, clicker)
|
||||
state = state + 1
|
||||
end
|
||||
|
||||
local dir = minetest.get_node(pos).param2
|
||||
local dir = node.param2
|
||||
if state % 2 == 0 then
|
||||
minetest.sound_play(def.door.sounds[1],
|
||||
{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)
|
||||
_doors.door_toggle(pos, clicker)
|
||||
_doors.door_toggle(pos, node, clicker)
|
||||
return itemstack
|
||||
end
|
||||
def.after_dig_node = function(pos, node, meta, digger)
|
||||
@ -507,7 +507,7 @@ end
|
||||
|
||||
----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
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("doors_owner")
|
||||
@ -518,7 +518,6 @@ function _doors.trapdoor_toggle(pos, clicker)
|
||||
end
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
|
||||
if string.sub(node.name, -5) == "_open" then
|
||||
@ -549,7 +548,7 @@ function doors.register_trapdoor(name, def)
|
||||
end
|
||||
|
||||
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
_doors.trapdoor_toggle(pos, clicker)
|
||||
_doors.trapdoor_toggle(pos, node, clicker)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
@ -684,7 +683,6 @@ function doors.register_fencegate(name, def)
|
||||
groups = def.groups,
|
||||
sounds = def.sounds,
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
local node = minetest.get_node(pos)
|
||||
local node_def = minetest.registered_nodes[node.name]
|
||||
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
|
||||
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
|
||||
|
Loading…
Reference in New Issue
Block a user