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 boolean check true if craft can be produced
---@return ItemStack[] materialStacks list of itemStacks for crafting ---@return ItemStack[] materialStacks list of itemStacks for crafting
function CraftSystem:checkPossiblePlayerInventoryCrafting(player, craft, recipeIndex, count) 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 inventory = player:get_inventory()
local OutputStack = ItemStack(craft.output)
OutputStack:set_count(OutputStack:get_count() * count) OutputStack:set_count(OutputStack:get_count() * count)
local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count) local materialStacks, materialGroups = getMaterials(craft, recipeIndex, count)

View File

@@ -83,6 +83,15 @@ end
---@param amount integer ---@param amount integer
---@return boolean ---@return boolean
function ImmersiveCraft:startCraft(pos, player, amount) 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?]] local workStation = Smc.getNodeSuperclassByPos(pos) --[[@as ImmersiveWorkStation?]]
assert(workStation ~= nil) assert(workStation ~= nil)
@@ -124,7 +133,7 @@ function ImmersiveCraft:endCraft(pos, player)
local playerName = meta:get_string('player_name') local playerName = meta:get_string('player_name')
assert(playerName ~= '') assert(playerName ~= '')
local amount = meta:get_float('craft_amount') local amount = meta:get_float('craft_amount')
assert(amount ~= 0) assert(amount > 0)
-- Drop the result of crafting. -- Drop the result of crafting.
local dropPos = v(pos) + v(0, 0.9,0) local dropPos = v(pos) + v(0, 0.9,0)

View File

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

View File

@@ -646,7 +646,7 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('%S+::%S+::craft_item', functio
end end
Smc.putOrDrop(player, inventory, craft.output) Smc.putOrDrop(player, inventory, craft.output)
elseif tabName == 'node_tab' and allowCrafting and handler.baseType == 'immersive' then elseif allowCrafting and tabName == 'node_tab' and handler.baseType == 'immersive' then
---@type CraftSystem.ImmersiveCraft ---@type CraftSystem.ImmersiveCraft
craft = craft craft = craft
local inventory = player:get_inventory() local inventory = player:get_inventory()