From a18a2127c559af7fb52258305c9e4110d0d8ca4d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 27 Mar 2021 12:20:14 +0100 Subject: [PATCH] add helper function to give item in creative --- mods/ITEMS/mcl_cauldrons/api.lua | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_cauldrons/api.lua b/mods/ITEMS/mcl_cauldrons/api.lua index 6b71984826..ef77ae19a7 100644 --- a/mods/ITEMS/mcl_cauldrons/api.lua +++ b/mods/ITEMS/mcl_cauldrons/api.lua @@ -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