mirror of
https://github.com/mt-mods/controls.git
synced 2024-11-28 01:23:43 +01:00
add _drop key, fixes https://github.com/mt-mods/controls/issues/3
This commit is contained in:
parent
74401360ce
commit
420b5842d4
38
init.lua
38
init.lua
@ -76,6 +76,44 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
end)
|
||||
|
||||
--special keys
|
||||
minetest.register_on_mods_loaded(function()
|
||||
for name, def in pairs(minetest.registered_nodes) do
|
||||
local old_node_drop = def.on_drop
|
||||
local on_drop = function(itemstack, dropper, ...)
|
||||
for _, callback in pairs(controls.registered_on_press) do
|
||||
callback(dropper, "_drop")
|
||||
end
|
||||
return old_node_drop(itemstack, dropper, unpack({...}))
|
||||
end
|
||||
minetest.override_item(name, {
|
||||
on_drop = on_drop
|
||||
})
|
||||
end
|
||||
|
||||
local old_reg_node = minetest.register_node
|
||||
function minetest.register_node(name, def)
|
||||
if def.on_drop then
|
||||
local old_node_drop = def.on_drop
|
||||
def.on_drop = function(itemstack, dropper, ...)
|
||||
for _, callback in pairs(controls.registered_on_press) do
|
||||
callback(dropper, "_drop")
|
||||
end
|
||||
return old_node_drop(itemstack, dropper, unpack({...}))
|
||||
end
|
||||
else
|
||||
def.on_drop = function(itemstack, dropper, ...)
|
||||
for _, callback in pairs(controls.registered_on_press) do
|
||||
callback(dropper, "_drop")
|
||||
end
|
||||
return minetest.item_drop(itemstack, dropper, unpack({...}))
|
||||
end
|
||||
end
|
||||
|
||||
old_reg_node(name, def)
|
||||
end
|
||||
end)
|
||||
|
||||
--tests
|
||||
if(controls.testsmode) then
|
||||
dofile(controls.modpath .. "/test.lua")
|
||||
|
11
readme.md
11
readme.md
@ -1,7 +1,5 @@
|
||||
# api
|
||||
|
||||
note: supports all keys minetest does
|
||||
|
||||
```lua
|
||||
controls.register_on_press(function(player, key)
|
||||
-- called on key down
|
||||
@ -22,4 +20,13 @@ controls.register_on_release(function(player, key, length)
|
||||
-- @key: key pressed
|
||||
-- @length: length of time key was held in seconds
|
||||
end)
|
||||
```
|
||||
|
||||
# keys
|
||||
|
||||
supports all the keys minetest does
|
||||
|
||||
special keys:
|
||||
```
|
||||
@_drop: called when a player drops an item
|
||||
```
|
Loading…
Reference in New Issue
Block a user