Add Smc.putOrDrop function
This commit is contained in:
@@ -9,6 +9,7 @@ local require = modInfo.require
|
||||
-- Independent of SMC methods
|
||||
require('Lib.activeFormspecs')
|
||||
require('Lib.globalStep')
|
||||
require('Lib.inventoryHelpers')
|
||||
require('Lib.color')
|
||||
require('Lib.itemStackInventory')
|
||||
require('Lib.nodeSuperClasses')
|
||||
|
||||
23
mods/SYSTEM/HelperLib/src/Lib/inventoryHelpers.lua
Normal file
23
mods/SYSTEM/HelperLib/src/Lib/inventoryHelpers.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local ItemStack = ItemStack
|
||||
|
||||
---Adds the specified stack to the player's inventory, provided there is space available.
|
||||
---
|
||||
---If there is no space, it drops the stack on the ground.
|
||||
---
|
||||
---Returns `true` if the stack was placed in the inventory, and `false` if it was dropped.
|
||||
---@param player Player
|
||||
---@param inventory InvRef
|
||||
---@param item ItemStack|ItemStackString|ItemStackString
|
||||
---@return boolean
|
||||
function Smc.putOrDrop(player, inventory, item)
|
||||
item = ItemStack(item)
|
||||
if inventory:room_for_item('main', item) then
|
||||
inventory:add_item('main', item)
|
||||
|
||||
return true
|
||||
else
|
||||
core.item_drop(item, player, player:get_pos())
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user