check for negative quantities in crafting functions

This commit is contained in:
Van
2026-11-11 20:31:41 +03:00
parent ba8dad4798
commit af0b7c8beb
4 changed files with 23 additions and 4 deletions

View File

@@ -205,9 +205,19 @@ end
---@return boolean check true if craft can be produced
---@return ItemStack[] materialStacks list of itemStacks for crafting
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count)
local OutputStack = ItemStack(craft.output)
if count <= 0 then
Logger.warningLog('`CraftSystem:checkPossiblePlayerInventoryCrafting()`: param `count` <= 0. '..
'Was force-reset to `1`. '..
'Info: value: `%s`, player: `%s`, craft: `%s`',
count, player:get_player_name(), craft.name
)
count = 1
end
local inventory = player:get_inventory()
local OutputStack = ItemStack(craft.output)
OutputStack:set_count(OutputStack:get_count() * count)
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)

View File

@@ -83,6 +83,15 @@ end
---@param amount integer
---@return boolean
function ImmersiveCraft:startCraft(pos, player, amount)
if amount <= 0 then
Logger.warningLog('`ImmersiveCraft:startCraft()`: param `amount` <= 0. '..
'Was force-reset to `1`. '..
'Info: value: `%s`, player: `%s`, craft: `%s`',
amount, player:get_player_name(), self.name
)
amount = 1
end
local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
assert(workStation ~= nil)
@@ -124,7 +133,7 @@ function ImmersiveCraft:endCraft(pos, player)
local playerName = meta:get_string('player_name')
assert(playerName ~= '')
local amount = meta:get_float('craft_amount')
assert(amount ~= 0)
assert(amount > 0)
-- Drop the result of crafting.
local dropPos = v(pos) + v(0, 0.9,0)

View File

@@ -129,7 +129,7 @@ function TappingStage:new(def)
assert(stageData ~= nil)
local amount = meta:get_float('craft_amount')
assert(amount ~= 0)
assert(amount > 0)
---@type CraftSystem.ImmersiveCraftStage.TappingStageData?
local stageData = stageData