mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Add an item pick up callback (2) (#7712)
Co-authored-by: SmallJoker <mk939@ymail.com> Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
This commit is contained in:
parent
977f656e09
commit
22cbc05808
8 changed files with 189 additions and 13 deletions
|
@ -349,8 +349,26 @@ function core.item_drop(itemstack, dropper, pos)
|
|||
-- environment failed
|
||||
end
|
||||
|
||||
function core.item_pickup(itemstack, picker, pointed_thing, ...)
|
||||
itemstack = ItemStack(itemstack)
|
||||
-- Invoke global on_item_pickup callbacks.
|
||||
for _, callback in ipairs(core.registered_on_item_pickups) do
|
||||
local result = callback(itemstack, picker, pointed_thing, ...)
|
||||
if result then
|
||||
return ItemStack(result)
|
||||
end
|
||||
end
|
||||
|
||||
-- Pickup item.
|
||||
local inv = picker and picker:get_inventory()
|
||||
if inv then
|
||||
return inv:add_item("main", itemstack)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
for _, callback in pairs(core.registered_on_item_eats) do
|
||||
for _, callback in ipairs(core.registered_on_item_eats) do
|
||||
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
if result then
|
||||
return result
|
||||
|
@ -589,6 +607,7 @@ core.nodedef_default = {
|
|||
-- Interaction callbacks
|
||||
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||
on_pickup = redef_wrapper(core, 'item_pickup'), -- core.item_pickup
|
||||
on_use = nil,
|
||||
can_dig = nil,
|
||||
|
||||
|
@ -641,6 +660,7 @@ core.craftitemdef_default = {
|
|||
-- Interaction callbacks
|
||||
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||
on_pickup = redef_wrapper(core, 'item_pickup'), -- core.item_pickup
|
||||
on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
|
||||
on_use = nil,
|
||||
}
|
||||
|
@ -661,6 +681,7 @@ core.tooldef_default = {
|
|||
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||
on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
|
||||
on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop
|
||||
on_pickup = redef_wrapper(core, 'item_pickup'), -- core.item_pickup
|
||||
on_use = nil,
|
||||
}
|
||||
|
||||
|
@ -677,8 +698,9 @@ core.noneitemdef_default = { -- This is used for the hand and unknown items
|
|||
tool_capabilities = nil,
|
||||
|
||||
-- Interaction callbacks
|
||||
on_place = redef_wrapper(core, 'item_place'),
|
||||
on_place = redef_wrapper(core, 'item_place'), -- core.item_place
|
||||
on_secondary_use = redef_wrapper(core, 'item_secondary_use'),
|
||||
on_pickup = redef_wrapper(core, 'item_pickup'), -- core.item_pickup
|
||||
on_drop = nil,
|
||||
on_use = nil,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue