mirror of
https://github.com/tacigar/maidroid.git
synced 2025-01-25 15:00:22 +01:00
Add pickup_item method
This commit is contained in:
parent
b2f654ef5d
commit
f2713dc52e
@ -156,6 +156,35 @@ function maidroid.maidroid.move_main_to_wield(self, itemname)
|
||||
return false
|
||||
end
|
||||
|
||||
-- maidroid.maidroid.pickup_item pickup items placed and put it to main slot.
|
||||
function maidroid.maidroid.pickup_item(self, is_target)
|
||||
local pos = self.object:getpos()
|
||||
local radius = 1.0
|
||||
local all_objects = minetest.get_objects_inside_radius(pos, radius)
|
||||
|
||||
for _, obj in ipairs(all_objects) do
|
||||
if not obj:is_player() and obj:get_luaentity() then
|
||||
local itemstring = obj:get_luaentity().itemstring
|
||||
local cond = false
|
||||
if is_target == nil then
|
||||
cond = true
|
||||
elseif is_target(itemstring) then
|
||||
cond = true
|
||||
end
|
||||
|
||||
if cond then
|
||||
local inv = maidroid:get_inventory()
|
||||
local stack = ItemStack(itemstring)
|
||||
local leftover = inv:add_item("main", stack)
|
||||
|
||||
minetest.add_item(obj:getpos(), leftover)
|
||||
obj:get_luaentity().itemstring = ""
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
-- maidroid.manufacturing_data represents a table that contains manufacturing data.
|
||||
@ -544,6 +573,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
set_yaw_by_direction = maidroid.maidroid.set_yaw_by_direction,
|
||||
get_wield_item_stack = maidroid.maidroid.get_wield_item_stack,
|
||||
move_main_to_wield = maidroid.maidroid.move_main_to_wield,
|
||||
pickup_item = maidroid.maidroid.pickup_item,
|
||||
})
|
||||
|
||||
-- register maidroid egg.
|
||||
|
Loading…
Reference in New Issue
Block a user