initial 2.0 vanilla compat
This commit is contained in:
parent
5520061fc8
commit
a2163f7e0f
6 changed files with 255 additions and 328 deletions
103
data-util.lua
103
data-util.lua
|
|
@ -305,15 +305,12 @@ function util.se_matter(params)
|
|||
end
|
||||
end
|
||||
|
||||
-- deprecated
|
||||
-- Get the normal prototype for a recipe -- either .normal or the recipe itself
|
||||
function util.get_normal(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
recipe = data.raw.recipe[recipe_name]
|
||||
if recipe.normal and recipe.normal.ingredients then
|
||||
return recipe.normal
|
||||
elseif recipe.ingredients then
|
||||
return recipe
|
||||
end
|
||||
return recipe
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -428,17 +425,13 @@ end
|
|||
|
||||
function util.set_enabled(recipe_name, enabled)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.enabled = enabled end
|
||||
if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.enabled = enabled end
|
||||
if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].enabled = enabled end
|
||||
data.raw.recipe[recipe_name].enabled = enabled
|
||||
end
|
||||
end
|
||||
|
||||
function util.set_hidden(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
if data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].normal.hidden = true end
|
||||
if data.raw.recipe[recipe_name].expensive then data.raw.recipe[recipe_name].expensive.hidden = true end
|
||||
if not data.raw.recipe[recipe_name].normal then data.raw.recipe[recipe_name].hidden = true end
|
||||
data.raw.recipe[recipe_name].hidden = true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -448,8 +441,6 @@ function util.add_or_add_to_ingredient(recipe_name, ingredient, quantity, option
|
|||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
me.add_modified(recipe_name)
|
||||
add_or_add_to_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
add_or_add_to_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
||||
add_or_add_to_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -472,8 +463,6 @@ function util.add_ingredient(recipe_name, ingredient, quantity, options)
|
|||
if data.raw.recipe[recipe_name] and (data.raw.item[ingredient] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
add_ingredient(data.raw.recipe[recipe_name], ingredient, quantity, is_fluid)
|
||||
add_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity, is_fluid)
|
||||
add_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity, is_fluid)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -498,8 +487,6 @@ function util.add_ingredient_raw(recipe_name, ingredient, options)
|
|||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient.name] then
|
||||
me.add_modified(recipe_name)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name], ingredient)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name].normal, ingredient)
|
||||
add_ingredient_raw(data.raw.recipe[recipe_name].expensive, ingredient)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -520,8 +507,6 @@ function util.set_ingredient(recipe_name, ingredient, quantity, options)
|
|||
if data.raw.recipe[recipe_name] and data.raw.item[ingredient] then
|
||||
me.add_modified(recipe_name)
|
||||
set_ingredient(data.raw.recipe[recipe_name], ingredient, quantity)
|
||||
set_ingredient(data.raw.recipe[recipe_name].normal, ingredient, quantity)
|
||||
set_ingredient(data.raw.recipe[recipe_name].expensive, ingredient, quantity)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -546,35 +531,27 @@ function util.add_product(recipe_name, product, options)
|
|||
(data.raw.item[product.name] or data.raw.fluid[product.name]
|
||||
) then
|
||||
add_product(data.raw.recipe[recipe_name], product)
|
||||
add_product(data.raw.recipe[recipe_name].normal, product)
|
||||
add_product(data.raw.recipe[recipe_name].expensive, product)
|
||||
end
|
||||
end
|
||||
|
||||
function add_product(recipe, product)
|
||||
if recipe ~= nil then
|
||||
if product.name and data.raw[product.type][product.name] then
|
||||
if not recipe.normal then
|
||||
if recipe.results == nil then
|
||||
recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}}
|
||||
end
|
||||
recipe.result = nil
|
||||
recipe.result_count = nil
|
||||
table.insert(recipe.results, product)
|
||||
if recipe.results == nil then
|
||||
recipe.results = {{recipe.result, recipe.result_count and recipe.result_count or 1}}
|
||||
end
|
||||
recipe.result = nil
|
||||
recipe.result_count = nil
|
||||
table.insert(recipe.results, product)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get the amount of the ingredient, will check base/normal not expensive
|
||||
-- Get the amount of the ingredient
|
||||
function util.get_ingredient_amount(recipe_name, ingredient_name)
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.normal and recipe.normal.ingredients then
|
||||
for i, ingredient in pairs(recipe.normal.ingredients) do
|
||||
if ingredient.name == ingredient_name then return ingredient.amount end
|
||||
end
|
||||
elseif recipe.ingredients then
|
||||
if recipe.ingredients then
|
||||
for i, ingredient in pairs(recipe.ingredients) do
|
||||
if ingredient.name == ingredient_name then return ingredient.amount end
|
||||
end
|
||||
|
|
@ -584,25 +561,17 @@ function util.get_ingredient_amount(recipe_name, ingredient_name)
|
|||
return 0
|
||||
end
|
||||
|
||||
-- Get the amount of the result, will check base/normal not expensive
|
||||
-- Get the amount of the result
|
||||
function util.get_amount(recipe_name, product)
|
||||
if not product then product = recipe_name end
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.normal and recipe.normal.results then
|
||||
for i, result in pairs(recipe.normal.results) do
|
||||
if result.name == product then return result.amount end
|
||||
end
|
||||
elseif recipe.normal and recipe.normal.result_count then
|
||||
return recipe.normal.result_count
|
||||
elseif recipe.results then
|
||||
if recipe.results then
|
||||
for i, result in pairs(recipe.results) do
|
||||
if result.name == product then return result.amount end
|
||||
end
|
||||
elseif recipe.result_count then
|
||||
return recipe.result_count
|
||||
end
|
||||
return 1
|
||||
return 0
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
|
@ -612,9 +581,7 @@ function util.get_result_count(recipe_name, product)
|
|||
if not product then product = recipe_name end
|
||||
local recipe = data.raw.recipe[recipe_name]
|
||||
if recipe then
|
||||
if recipe.normal and recipe.normal.results then
|
||||
return #(recipe.normal.results)
|
||||
elseif recipe.results then
|
||||
if recipe.results then
|
||||
return #(recipe.results)
|
||||
end
|
||||
return 1
|
||||
|
|
@ -629,8 +596,6 @@ function util.replace_ingredient(recipe_name, old, new, amount, multiply, option
|
|||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or data.raw.fluid[new]) then
|
||||
me.add_modified(recipe_name)
|
||||
replace_ingredient(data.raw.recipe[recipe_name], old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].normal, old, new, amount, multiply)
|
||||
replace_ingredient(data.raw.recipe[recipe_name].expensive, old, new, amount, multiply)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -662,8 +627,6 @@ function util.remove_ingredient(recipe_name, old, options)
|
|||
if data.raw.recipe[recipe_name] then
|
||||
me.add_modified(recipe_name)
|
||||
remove_ingredient(data.raw.recipe[recipe_name], old)
|
||||
remove_ingredient(data.raw.recipe[recipe_name].normal, old)
|
||||
remove_ingredient(data.raw.recipe[recipe_name].expensive, old)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -689,8 +652,6 @@ function util.replace_some_product(recipe_name, old, old_amount, new, new_amount
|
|||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
replace_some_product(data.raw.recipe[recipe_name], old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_product(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_product(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount, is_fluid)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -720,8 +681,6 @@ function util.replace_some_ingredient(recipe_name, old, old_amount, new, new_amo
|
|||
if data.raw.recipe[recipe_name] and (data.raw.item[new] or is_fluid) then
|
||||
me.add_modified(recipe_name)
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name], old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name].normal, old, old_amount, new, new_amount, is_fluid)
|
||||
replace_some_ingredient(data.raw.recipe[recipe_name].expensive, old, old_amount, new, new_amount, is_fluid)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -747,8 +706,6 @@ function util.set_product_amount(recipe_name, product, amount, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_product_amount(data.raw.recipe[recipe_name], product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].normal, product, amount)
|
||||
set_product_amount(data.raw.recipe[recipe_name].expensive, product, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -784,8 +741,6 @@ function util.multiply_recipe(recipe_name, multiple, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
multiply_recipe(data.raw.recipe[recipe_name], multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].normal, multiple)
|
||||
multiply_recipe(data.raw.recipe[recipe_name].expensive, multiple)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -831,9 +786,8 @@ end
|
|||
|
||||
-- Returns true if a recipe has an ingredient
|
||||
function util.has_ingredient(recipe_name, ingredient)
|
||||
return data.raw.recipe[recipe_name] and (
|
||||
has_ingredient(data.raw.recipe[recipe_name], ingredient) or
|
||||
has_ingredient(data.raw.recipe[recipe_name].normal, ingredient))
|
||||
return data.raw.recipe[recipe_name] and
|
||||
has_ingredient(data.raw.recipe[recipe_name], ingredient)
|
||||
end
|
||||
|
||||
function has_ingredient(recipe, ingredient)
|
||||
|
|
@ -853,8 +807,6 @@ function util.remove_product(recipe_name, old, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
remove_product(data.raw.recipe[recipe_name], old)
|
||||
remove_product(data.raw.recipe[recipe_name].normal, old)
|
||||
remove_product(data.raw.recipe[recipe_name].expensive, old)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -877,8 +829,6 @@ function util.set_main_product(recipe_name, product, options)
|
|||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_main_product(data.raw.recipe[recipe_name], product)
|
||||
set_main_product(data.raw.recipe[recipe_name].normal, product)
|
||||
set_main_product(data.raw.recipe[recipe_name].expensive, product)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -893,8 +843,6 @@ function util.replace_product(recipe_name, old, new, options)
|
|||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
replace_product(data.raw.recipe[recipe_name], old, new, options)
|
||||
replace_product(data.raw.recipe[recipe_name].normal, old, new, options)
|
||||
replace_product(data.raw.recipe[recipe_name].expensive, old, new, options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -937,8 +885,6 @@ function util.set_recipe_time(recipe_name, time, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
set_recipe_time(data.raw.recipe[recipe_name], time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].normal, time)
|
||||
set_recipe_time(data.raw.recipe[recipe_name].expensive, time)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -956,8 +902,6 @@ function util.multiply_time(recipe_name, factor, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
multiply_time(data.raw.recipe[recipe_name], factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].normal, factor)
|
||||
multiply_time(data.raw.recipe[recipe_name].expensive, factor)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -975,8 +919,6 @@ function util.add_time(recipe_name, amount, options)
|
|||
me.add_modified(recipe_name)
|
||||
if data.raw.recipe[recipe_name] then
|
||||
add_time(data.raw.recipe[recipe_name], amount)
|
||||
add_time(data.raw.recipe[recipe_name].normal, amount)
|
||||
add_time(data.raw.recipe[recipe_name].expensive, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1037,13 +979,6 @@ function util.add_icon(recipe_name, icon, options)
|
|||
icon_size=data.raw.item[data.raw.recipe[recipe_name].result].icon_size,
|
||||
icon_mipmaps=data.raw.item[data.raw.recipe[recipe_name].result].icon_mipmaps,
|
||||
}}
|
||||
elseif data.raw.recipe[recipe_name].normal and
|
||||
data.raw.item[data.raw.recipe[recipe_name].normal.result] then
|
||||
data.raw.recipe[recipe_name].icons = {{
|
||||
icon=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon,
|
||||
icon_size=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon_size,
|
||||
icon_mipmaps=data.raw.item[data.raw.recipe[recipe_name].normal.result].icon_mipmaps,
|
||||
}}
|
||||
end
|
||||
data.raw.recipe[recipe_name].icon = nil
|
||||
data.raw.recipe[recipe_name].icon_size = nil
|
||||
|
|
@ -1106,8 +1041,6 @@ function util.add_to_ingredient(recipe, ingredient, amount, options)
|
|||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe] then
|
||||
add_to_ingredient(data.raw.recipe[recipe], ingredient, amount)
|
||||
add_to_ingredient(data.raw.recipe[recipe].normal, ingredient, amount)
|
||||
add_to_ingredient(data.raw.recipe[recipe].expensive, ingredient, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1130,8 +1063,6 @@ function util.add_to_product(recipe_name, product, amount, options)
|
|||
if not should_force(options) and bypass(recipe_name) then return end
|
||||
if data.raw.recipe[recipe_name] then
|
||||
add_to_product(data.raw.recipe[recipe_name], product, amount)
|
||||
add_to_product(data.raw.recipe[recipe_name].normal, product, amount)
|
||||
add_to_product(data.raw.recipe[recipe_name].expensive, product, amount)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue