This commit is contained in:
wsor4035 2023-12-03 16:41:53 -05:00
parent 75544e1a6f
commit 3bd201f828
2 changed files with 47 additions and 2 deletions

@ -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")

@ -1,7 +1,5 @@
# api
note: supports all keys minetest does
```lua
controls.register_on_press(function(player, key)
-- called on key down
@ -23,3 +21,12 @@ controls.register_on_release(function(player, key, length)
-- @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
```