mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-22 22:22:25 +01:00
Doors: Allow on_rightclick to be overidden
Allow mods such as protection mods to over ride on_rightclick. Usecase is creating shared doors without the need for keys.
This commit is contained in:
parent
ec248d3cb0
commit
bae58b3806
21
game_api.txt
21
game_api.txt
@ -160,6 +160,12 @@ Doors API
|
||||
|
||||
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
|
||||
@ -195,6 +201,13 @@ The doors mod allows modders to register custom doors and trapdoors.
|
||||
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",
|
||||
@ -206,6 +219,8 @@ The doors mod allows modders to register custom doors and trapdoors.
|
||||
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
|
||||
|
||||
@ -218,6 +233,10 @@ The doors mod allows modders to register custom doors and trapdoors.
|
||||
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
|
||||
|
||||
@ -227,6 +246,8 @@ The doors mod allows modders to register custom doors and trapdoors.
|
||||
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
|
||||
|
@ -1,10 +1,8 @@
|
||||
-- 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)
|
||||
@ -18,7 +16,7 @@ end
|
||||
-- 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,
|
||||
@ -26,23 +24,23 @@ function doors.get(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,
|
||||
@ -50,16 +48,16 @@ function doors.get(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"
|
||||
@ -130,7 +128,7 @@ local transform = {
|
||||
},
|
||||
}
|
||||
|
||||
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]
|
||||
@ -373,10 +371,11 @@ function doors.register(name, def)
|
||||
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})
|
||||
@ -444,8 +443,8 @@ function doors.register(name, def)
|
||||
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", {
|
||||
@ -532,7 +531,7 @@ end
|
||||
|
||||
----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)
|
||||
@ -565,7 +564,7 @@ function doors.register_trapdoor(name, def)
|
||||
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
|
||||
|
||||
@ -668,8 +667,8 @@ function doors.register_trapdoor(name, def)
|
||||
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", {
|
||||
|
Loading…
Reference in New Issue
Block a user