add helper function to give item in creative

This commit is contained in:
AFCMS 2021-03-27 12:20:14 +01:00
parent 7156afcd03
commit a18a2127c5
1 changed files with 15 additions and 7 deletions

View File

@ -1,21 +1,29 @@
local has_doc = minetest.get_modpath(minetest.get_current_modname())
local function survival_give(user, itemstack)
local function survival_give(inv, itemstack)
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
end
local function creative_give(inv, itemstack)
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
end
local function give_item(user, itemstack)
local inv = user:get_inventory()
if inv then
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
--end
if minetest.is_creative_enabled(user:get_player_name()) then
creative_give(inv, itemstack)
else
survival_give(inv, itemstack)
end
end
return itemstack
end