mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Allow nil
puncher in object:punch
(#14319)
This commit is contained in:
parent
fc0ac64277
commit
72cb4e9bea
11 changed files with 89 additions and 36 deletions
|
@ -76,3 +76,26 @@ minetest.register_entity("callbacks:callback_step", {
|
|||
message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Callback punch with nil puncher
|
||||
minetest.register_entity("callbacks:callback_puncher", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = { "callbacks_callback_entity.png" },
|
||||
infotext = "Callback entity for nil puncher test.",
|
||||
},
|
||||
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if puncher then
|
||||
puncher:punch(nil, time_from_last_punch, tool_capabilities, dir)
|
||||
self.object:punch(nil, time_from_last_punch, tool_capabilities, dir)
|
||||
else
|
||||
message(
|
||||
"Callback entity: on_punch with nil puncher "..
|
||||
"pos="..spos(self).."; "..
|
||||
"time_from_last_punch="..time_from_last_punch.."; "..
|
||||
"tool_capabilities="..dump(tool_capabilities).."; "..
|
||||
"dir="..dump(dir).."; damage="..damage)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
dofile(minetest.get_modpath("callbacks").."/items.lua")
|
||||
dofile(minetest.get_modpath("callbacks").."/nodes.lua")
|
||||
dofile(minetest.get_modpath("callbacks").."/entities.lua")
|
||||
dofile(minetest.get_modpath("callbacks").."/players.lua")
|
||||
|
|
11
games/devtest/mods/callbacks/players.lua
Normal file
11
games/devtest/mods/callbacks/players.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
local message = function(msg)
|
||||
minetest.log("action", "[callbacks] "..msg)
|
||||
minetest.chat_send_all(msg)
|
||||
end
|
||||
|
||||
core.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||
if not hitter then
|
||||
message("Player "..player:get_player_name().." punched without hitter.")
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue