The doors mod allows modders to register custom doors and trapdoors.
+`doors.registered_doors[name] = Door definition`
+ * Table of registered doors, indexed by door name
+
+`doors.registered_trapdoors[name] = Trapdoor definition`
+ * Table of registered trap doors, indexed by trap door name
+
`doors.register_door(name, def)`
* Registers new door
has the permissions needed to open this door. If omitted then no
permission checks are performed.
+`doors.door_toggle(pos, node, clicker)`
+
+ * Toggle door open or shut
+ * `pos` Position of the door
+ * `node` Node definition
+ * `clicker` Player definition for the player that clicked on the door
+
### Door definition
description = "Door description",
sound_open = sound play for open door, -- optional
sound_close = sound play for close door, -- optional
protected = false, -- If true, only placer can open the door (locked for others)
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ -- optional function containing the on_rightclick callback, defaults to a doors.door_toggle-wrapper
### Trapdoor definition
sound_open = sound play for open door, -- optional
sound_close = sound play for close door, -- optional
protected = false, -- If true, only placer can open the door (locked for others)
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ -- function containing the on_rightclick callback
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ -- function containing the on_rightclick callback
### Fence gate definition
material = "default:wood",
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(), -- optional
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ -- function containing the on_rightclick callback
Dungeon Loot API
-- our API object
doors = {}
--- private data
-local _doors = {}
-_doors.registered_doors = {}
-_doors.registered_trapdoors = {}
+doors.registered_doors = {}
+doors.registered_trapdoors = {}
local function replace_old_owner_information(pos)
local meta = minetest.get_meta(pos)
-- returns an object to a door object or nil
function doors.get(pos)
local node_name = minetest.get_node(pos).name
- if _doors.registered_doors[node_name] then
+ if doors.registered_doors[node_name] then
-- A normal upright door
return {
pos = pos,
if self:state() then
return false
end
- return _doors.door_toggle(self.pos, nil, player)
+ return doors.door_toggle(self.pos, nil, player)
end,
close = function(self, player)
if not self:state() then
return false
end
- return _doors.door_toggle(self.pos, nil, player)
+ return doors.door_toggle(self.pos, nil, player)
end,
toggle = function(self, player)
- return _doors.door_toggle(self.pos, nil, player)
+ return doors.door_toggle(self.pos, nil, player)
end,
state = function(self)
local state = minetest.get_meta(self.pos):get_int("state")
return state %2 == 1
end
}
- elseif _doors.registered_trapdoors[node_name] then
+ elseif doors.registered_trapdoors[node_name] then
-- A trapdoor
return {
pos = pos,
if self:state() then
return false
end
- return _doors.trapdoor_toggle(self.pos, nil, player)
+ return doors.trapdoor_toggle(self.pos, nil, player)
end,
close = function(self, player)
if not self:state() then
return false
end
- return _doors.trapdoor_toggle(self.pos, nil, player)
+ return doors.trapdoor_toggle(self.pos, nil, player)
end,
toggle = function(self, player)
- return _doors.trapdoor_toggle(self.pos, nil, player)
+ return doors.trapdoor_toggle(self.pos, nil, player)
end,
state = function(self)
return minetest.get_node(self.pos).name:sub(-5) == "_open"
},
}
-function _doors.door_toggle(pos, node, clicker)
+function doors.door_toggle(pos, node, clicker)
local meta = minetest.get_meta(pos)
node = node or minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
name = name,
sounds = { def.sound_close, def.sound_open },
}
-
- def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
- _doors.door_toggle(pos, node, clicker)
- return itemstack
+ if not def.on_rightclick then
+ def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ doors.door_toggle(pos, node, clicker)
+ return itemstack
+ end
end
def.after_dig_node = function(pos, node, meta, digger)
minetest.remove_node({x = pos.x, y = pos.y + 1, z = pos.z})
def.mesh = "door_b.obj"
minetest.register_node(":" .. name .. "_b", def)
- _doors.registered_doors[name .. "_a"] = true
- _doors.registered_doors[name .. "_b"] = true
+ doors.registered_doors[name .. "_a"] = true
+ doors.registered_doors[name .. "_b"] = true
end
doors.register("door_wood", {
----trapdoor----
-function _doors.trapdoor_toggle(pos, node, clicker)
+function doors.trapdoor_toggle(pos, node, clicker)
node = node or minetest.get_node(pos)
replace_old_owner_information(pos)
local name_opened = name.."_open"
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
- _doors.trapdoor_toggle(pos, node, clicker)
+ doors.trapdoor_toggle(pos, node, clicker)
return itemstack
end
minetest.register_node(name_opened, def_opened)
minetest.register_node(name_closed, def_closed)
- _doors.registered_trapdoors[name_opened] = true
- _doors.registered_trapdoors[name_closed] = true
+ doors.registered_trapdoors[name_opened] = true
+ doors.registered_trapdoors[name_closed] = true
end
doors.register_trapdoor("doors:trapdoor", {