up
This commit is contained in:
parent
313957ea22
commit
8851bb9caf
1 changed files with 14 additions and 5 deletions
|
|
@ -912,14 +912,20 @@ function util.get_ingredient_amount(recipe_name, ingredient_name)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the amount of the result
|
-- Get the amount of the result (currently ignores probability)
|
||||||
function util.get_amount(recipe_name, product)
|
function util.get_amount(recipe_name, product)
|
||||||
if not product then product = recipe_name end
|
if not product then product = recipe_name end
|
||||||
local recipe = data.raw.recipe[recipe_name]
|
local recipe = data.raw.recipe[recipe_name]
|
||||||
if recipe then
|
if recipe then
|
||||||
if recipe.results then
|
if recipe.results then
|
||||||
for i, result in pairs(recipe.results) do
|
for i, result in pairs(recipe.results) do
|
||||||
if result.name == product then return result.amount end
|
if result.name == product then
|
||||||
|
if result.amount then
|
||||||
|
return result.amount
|
||||||
|
elseif result.amount_min then
|
||||||
|
return (result.amount_min + result.amount_max) / 2
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -944,7 +950,7 @@ end
|
||||||
-- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true.
|
-- Use amount to set an amount. If that amount is a multiplier instead of an exact amount, set multiply true.
|
||||||
function util.replace_ingredient(recipe_name, old, new, amount, multiply, options)
|
function util.replace_ingredient(recipe_name, old, new, amount, multiply, options)
|
||||||
if not should_force(options) and bypass(recipe_name) then return end
|
if not should_force(options) and bypass(recipe_name) then return end
|
||||||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
|
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) and (data.raw.item[old] or data.raw.fluid[old]) then
|
||||||
me.add_modified(recipe_name)
|
me.add_modified(recipe_name)
|
||||||
prepare_redo_recycling(recipe_name)
|
prepare_redo_recycling(recipe_name)
|
||||||
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
||||||
|
|
@ -1019,7 +1025,7 @@ function replace_some_product(recipe, old, old_amount, new, new_amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
add_product(recipe, {new, new_amount})
|
add_product(recipe, util.item(new, new_amount))
|
||||||
for i, product in pairs(recipe.results) do
|
for i, product in pairs(recipe.results) do
|
||||||
if product.name == old then
|
if product.name == old then
|
||||||
product.amount = math.max(1, product.amount - old_amount)
|
product.amount = math.max(1, product.amount - old_amount)
|
||||||
|
|
@ -1513,7 +1519,7 @@ end
|
||||||
|
|
||||||
-- Adds a result to a mineable type
|
-- Adds a result to a mineable type
|
||||||
function util.add_minable_result(t, name, result)
|
function util.add_minable_result(t, name, result)
|
||||||
if data.raw[t] and data.raw[t][name] and data.raw[t][name].minable then
|
if data.raw[t] and data.raw[t][name] and data.raw[t][name].minable and data.raw.item[result.name] then
|
||||||
if data.raw[t][name].minable.result and not data.raw[t][name].minable.results then
|
if data.raw[t][name].minable.result and not data.raw[t][name].minable.results then
|
||||||
data.raw[t][name].minable.results = {
|
data.raw[t][name].minable.results = {
|
||||||
util.item(data.raw[t][name].minable.result ,data.raw[t][name].minable.count)}
|
util.item(data.raw[t][name].minable.result ,data.raw[t][name].minable.count)}
|
||||||
|
|
@ -1521,6 +1527,9 @@ function util.add_minable_result(t, name, result)
|
||||||
data.raw[t][name].minable.result_count = nil
|
data.raw[t][name].minable.result_count = nil
|
||||||
end
|
end
|
||||||
if data.raw[t][name].minable.results then
|
if data.raw[t][name].minable.results then
|
||||||
|
for _, other in pairs(data.raw[t][name].minable.results) do
|
||||||
|
if other.name == result.name then return end -- don't add if already present
|
||||||
|
end
|
||||||
table.insert(data.raw[t][name].minable.results, result)
|
table.insert(data.raw[t][name].minable.results, result)
|
||||||
else
|
else
|
||||||
data.raw[t][name].minable.results = {result}
|
data.raw[t][name].minable.results = {result}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue