Compare commits

...

2 commits

Author SHA1 Message Date
Simon Brodtmann
bf7d05e3be 1.0.0 2025-11-23 19:02:37 +01:00
Simon Brodtmann
a9782564bf Add Recipe:addResult 2025-11-23 19:02:28 +01:00
3 changed files with 51 additions and 7 deletions

View file

@ -1,18 +1,26 @@
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 1.0.0
Date: 23.11.2025
Changes:
- Add table.filterKey
- Add class Settings
- Add Recipe:removeResult
- Add Recipe:addResult
---------------------------------------------------------------------------------------------------
Version: 0.0.14 Version: 0.0.14
Date: 10.06.2025 Date: 10.06.2025
Changes: Changes:
Add :merge - Add :merge
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.0.13 Version: 0.0.13
Date: 23.05.2025 Date: 23.05.2025
Changes: Changes:
Add Item class - Add Item class
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.0.12 Version: 0.0.12
Date: 06.04.2025 Date: 06.04.2025
Changes: Changes:
Add table.count - Add table.count
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 0.0.11 Version: 0.0.11
Date: 28.03.2025 Date: 28.03.2025

View file

@ -112,14 +112,50 @@ function Recipe:removeIngredient(ingredientName)
return self return self
end end
--- Adds a result to the recipe
--- @param resultName string The name of the result
--- @param amount number|table The amount of the result (default: 1) or a table with custom properties
function Recipe:addResult(resultName, amount)
local props = amount
if type(props) == "string" then
props = { amount = props }
end
if not props.amount then
props.amount = 1
end
local resultType = data.raw.item[resultName] and "item"
or data.raw.module[resultName] and "item"
or data.raw.fluid[resultName] and "fluid"
or nil
if not resultType then
log("Unknown result: " .. resultName)
return
end
self.prototype.results = self.prototype.results or {}
for _, result in pairs(self.prototype.results) do
if result.name == resultName then
result.amount = nil
result.amount_min = nil
result.amount_max = nil
result.probability = nil
for k, v in pairs(props) do
result[k] = v
end
return self
end
end
props.name = resultName
props.type = resultType
table.insert(self.prototype.results, props)
return self
end
--- Replaces an existing result by name with a new result --- Replaces an existing result by name with a new result
--- @param old string The name of the existing result --- @param old string The name of the existing result
--- @param new? string The name of the new result --- @param new? string The name of the new result
--- @param amount? number The amount of the new result (keeps the old value if not set) --- @param amount? number The amount of the new result (keeps the old value if not set)
--- @param expensiveAmount? number The amount of the new result for the expensive recipe (uses amount if not set) function Recipe:replaceResult(old, new, amount)
function Recipe:replaceResult(old, new, amount, expensiveAmount)
if type(new) == "number" then if type(new) == "number" then
expensiveAmount = amount
amount = new amount = new
new = old new = old
end end

View file

@ -1,6 +1,6 @@
{ {
"name": "cf-lib", "name": "cf-lib",
"version": "0.0.14", "version": "1.0.0",
"title": "cackling fiends library", "title": "cackling fiends library",
"description": "Because I'd like to have my own library :-)", "description": "Because I'd like to have my own library :-)",
"author": "cackling fiend", "author": "cackling fiend",