Add Smc.putOrDrop function

This commit is contained in:
Van
2026-11-09 21:30:23 +03:00
parent 2d3bdf4d02
commit c2e16834d8
3 changed files with 29 additions and 15 deletions

View File

@@ -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')

View 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