This commit is contained in:
wsor4035 2023-12-03 16:27:40 -05:00
parent 74401360ce
commit 420b5842d4
2 changed files with 47 additions and 2 deletions

@ -76,6 +76,44 @@ minetest.register_globalstep(function(dtime)
end end
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 --tests
if(controls.testsmode) then if(controls.testsmode) then
dofile(controls.modpath .. "/test.lua") dofile(controls.modpath .. "/test.lua")

@ -1,7 +1,5 @@
# api # api
note: supports all keys minetest does
```lua ```lua
controls.register_on_press(function(player, key) controls.register_on_press(function(player, key)
-- called on key down -- called on key down
@ -22,4 +20,13 @@ controls.register_on_release(function(player, key, length)
-- @key: key pressed -- @key: key pressed
-- @length: length of time key was held in seconds -- @length: length of time key was held in seconds
end) end)
```
# keys
supports all the keys minetest does
special keys:
```
@_drop: called when a player drops an item
``` ```