Fix libs
This commit is contained in:
parent
2c078c66fd
commit
903c34b08e
2 changed files with 2 additions and 243 deletions
|
@ -11,7 +11,6 @@ function thxbob.lib.item.get_type(name)
|
||||||
"fluid",
|
"fluid",
|
||||||
"gun",
|
"gun",
|
||||||
"item",
|
"item",
|
||||||
"mining-tool",
|
|
||||||
"module",
|
"module",
|
||||||
"tool",
|
"tool",
|
||||||
"item-with-entity-data"
|
"item-with-entity-data"
|
||||||
|
|
|
@ -8,7 +8,7 @@ function thxbob.lib.recipe.replace_ingredient(recipe, old, new)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(new) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(new) then
|
||||||
|
|
||||||
local amount = 0
|
local amount = 0
|
||||||
if data.raw.recipe[recipe].ingredients and not data.raw.recipe[recipe].normal and not data.raw.recipe[recipe].expensive then
|
if data.raw.recipe[recipe].ingredients then
|
||||||
for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
|
for i, ingredient in pairs(data.raw.recipe[recipe].ingredients) do
|
||||||
local item = thxbob.lib.item.basic_item(ingredient)
|
local item = thxbob.lib.item.basic_item(ingredient)
|
||||||
if item.name == old then
|
if item.name == old then
|
||||||
|
@ -29,51 +29,6 @@ function thxbob.lib.recipe.replace_ingredient(recipe, old, new)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--~ local retval = false
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
amount = 0
|
|
||||||
for i, ingredient in pairs(data.raw.recipe[recipe].normal.ingredients) do
|
|
||||||
local item = thxbob.lib.item.basic_item(ingredient)
|
|
||||||
if item.name == old then
|
|
||||||
amount = item.amount + amount
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if amount > 0 then
|
|
||||||
if thxbob.lib.item.get_type(old) == "fluid" and thxbob.lib.item.get_type(new) == "item" then
|
|
||||||
amount = math.ceil(amount / 10)
|
|
||||||
end
|
|
||||||
if thxbob.lib.item.get_type(old) == "item" and thxbob.lib.item.get_type(new) == "fluid" then
|
|
||||||
amount = amount * 10
|
|
||||||
end
|
|
||||||
thxbob.lib.recipe.remove_difficulty_ingredient(recipe, "normal", old)
|
|
||||||
thxbob.lib.recipe.add_difficulty_ingredient(recipe, "normal", {new, amount})
|
|
||||||
retval = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
amount = 0
|
|
||||||
for i, ingredient in pairs(data.raw.recipe[recipe].expensive.ingredients) do
|
|
||||||
local item = thxbob.lib.item.basic_item(ingredient)
|
|
||||||
if item.name == old then
|
|
||||||
amount = item.amount + amount
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if amount > 0 then
|
|
||||||
if thxbob.lib.item.get_type(old) == "fluid" and thxbob.lib.item.get_type(new) == "item" then
|
|
||||||
amount = math.ceil(amount / 10)
|
|
||||||
end
|
|
||||||
if thxbob.lib.item.get_type(old) == "item" and thxbob.lib.item.get_type(new) == "fluid" then
|
|
||||||
amount = amount * 10
|
|
||||||
end
|
|
||||||
thxbob.lib.recipe.remove_difficulty_ingredient(recipe, "expensive", old)
|
|
||||||
thxbob.lib.recipe.add_difficulty_ingredient(recipe, "expensive", {new, amount})
|
|
||||||
retval = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--~ return retval
|
|
||||||
else
|
else
|
||||||
if not data.raw.recipe[recipe] then
|
if not data.raw.recipe[recipe] then
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
||||||
|
@ -101,13 +56,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.remove_ingredient(recipe, item)
|
function thxbob.lib.recipe.remove_ingredient(recipe, item)
|
||||||
if data.raw.recipe[recipe] then
|
if data.raw.recipe[recipe] then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].expensive.ingredients, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].normal.ingredients, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].ingredients then
|
if data.raw.recipe[recipe].ingredients then
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].ingredients, item)
|
thxbob.lib.item.remove(data.raw.recipe[recipe].ingredients, item)
|
||||||
end
|
end
|
||||||
|
@ -120,13 +68,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_new_ingredient(recipe, item)
|
function thxbob.lib.recipe.add_new_ingredient(recipe, item)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.item.add_new(data.raw.recipe[recipe].expensive.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.item.add_new(data.raw.recipe[recipe].normal.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].ingredients then
|
if data.raw.recipe[recipe].ingredients then
|
||||||
thxbob.lib.item.add_new(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
thxbob.lib.item.add_new(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
||||||
end
|
end
|
||||||
|
@ -143,13 +84,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_ingredient(recipe, item)
|
function thxbob.lib.recipe.add_ingredient(recipe, item)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].expensive.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].normal.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].ingredients then
|
if data.raw.recipe[recipe].ingredients then
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
thxbob.lib.item.add(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
||||||
end
|
end
|
||||||
|
@ -166,13 +100,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.set_ingredient(recipe, item)
|
function thxbob.lib.recipe.set_ingredient(recipe, item)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].expensive.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].normal.ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].ingredients then
|
if data.raw.recipe[recipe].ingredients then
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
thxbob.lib.item.set(data.raw.recipe[recipe].ingredients, thxbob.lib.item.basic_item(item))
|
||||||
end
|
end
|
||||||
|
@ -190,14 +117,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_result(recipe, item)
|
function thxbob.lib.recipe.add_result(recipe, item)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].expensive)
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].expensive.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].normal)
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].normal.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe])
|
thxbob.lib.result_check(data.raw.recipe[recipe])
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe].results, item)
|
thxbob.lib.item.add(data.raw.recipe[recipe].results, item)
|
||||||
|
@ -215,15 +134,6 @@ end
|
||||||
|
|
||||||
function thxbob.lib.recipe.set_result(recipe, item)
|
function thxbob.lib.recipe.set_result(recipe, item)
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].expensive)
|
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].expensive.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].normal)
|
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].normal.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe])
|
thxbob.lib.result_check(data.raw.recipe[recipe])
|
||||||
thxbob.lib.item.set(data.raw.recipe[recipe].results, item)
|
thxbob.lib.item.set(data.raw.recipe[recipe].results, item)
|
||||||
|
@ -243,15 +153,6 @@ function thxbob.lib.recipe.remove_result(recipe, item)
|
||||||
local f_name = "remove_result"
|
local f_name = "remove_result"
|
||||||
BioInd.writeDebug("Entered function %s(%s, %s)", {f_name, recipe, item})
|
BioInd.writeDebug("Entered function %s(%s, %s)", {f_name, recipe, item})
|
||||||
if data.raw.recipe[recipe] then
|
if data.raw.recipe[recipe] then
|
||||||
|
|
||||||
if data.raw.recipe[recipe].expensive then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].expensive)
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].expensive.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].normal then
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe].normal)
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].normal.results, item)
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
if data.raw.recipe[recipe].result or data.raw.recipe[recipe].results then
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe])
|
thxbob.lib.result_check(data.raw.recipe[recipe])
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe].results, item)
|
thxbob.lib.item.remove(data.raw.recipe[recipe].results, item)
|
||||||
|
@ -261,144 +162,3 @@ BioInd.writeDebug("Entered function %s(%s, %s)", {f_name, recipe, item})
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function split_line(recipe, tag)
|
|
||||||
if data.raw.recipe[recipe][tag] then
|
|
||||||
if not data.raw.recipe[recipe].normal[tag] then
|
|
||||||
data.raw.recipe[recipe].normal[tag] = table.deepcopy(data.raw.recipe[recipe][tag])
|
|
||||||
end
|
|
||||||
if not data.raw.recipe[recipe].expensive[tag] then
|
|
||||||
data.raw.recipe[recipe].expensive[tag] = table.deepcopy(data.raw.recipe[recipe][tag])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
if data.raw.recipe[recipe] then
|
|
||||||
if not data.raw.recipe[recipe].normal then
|
|
||||||
data.raw.recipe[recipe].normal = {}
|
|
||||||
end
|
|
||||||
if not data.raw.recipe[recipe].expensive then
|
|
||||||
data.raw.recipe[recipe].expensive = {}
|
|
||||||
end
|
|
||||||
split_line(recipe, "energy_required")
|
|
||||||
if data.raw.recipe[recipe].enabled == false then
|
|
||||||
if data.raw.recipe[recipe].normal.enabled ~= true then
|
|
||||||
data.raw.recipe[recipe].normal.enabled = false
|
|
||||||
end
|
|
||||||
if data.raw.recipe[recipe].expensive.enabled ~= true then
|
|
||||||
data.raw.recipe[recipe].expensive.enabled = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
split_line(recipe, "ingredients")
|
|
||||||
split_line(recipe, "result")
|
|
||||||
split_line(recipe, "results")
|
|
||||||
split_line(recipe, "result_count")
|
|
||||||
split_line(recipe, "requester_paste_multiplier")
|
|
||||||
else
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.remove_difficulty_ingredient(recipe, difficulty, item)
|
|
||||||
if data.raw.recipe[recipe] and (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
|
|
||||||
if not data.raw.recipe[recipe][difficulty] then
|
|
||||||
thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
end
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe][difficulty].ingredients, item)
|
|
||||||
|
|
||||||
else
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_new_difficulty_ingredient(recipe, difficulty, item)
|
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) and (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
|
|
||||||
if not data.raw.recipe[recipe][difficulty] then
|
|
||||||
thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
end
|
|
||||||
thxbob.lib.item.add_new(data.raw.recipe[recipe][difficulty].ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
|
|
||||||
else
|
|
||||||
if not data.raw.recipe[recipe] then
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
if not thxbob.lib.item.get_type(item) then
|
|
||||||
BioInd.writeDebug("Ingredient %s does not exist.", {thxbob.lib.item.basic_item(item).name})
|
|
||||||
end
|
|
||||||
if not (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
BioInd.writeDebug("Difficulty %s is invalid.", {difficulty})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_difficulty_ingredient(recipe, difficulty, item)
|
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) and (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
|
|
||||||
if not data.raw.recipe[recipe][difficulty] then
|
|
||||||
thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
end
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe][difficulty].ingredients, thxbob.lib.item.basic_item(item))
|
|
||||||
|
|
||||||
else
|
|
||||||
if not data.raw.recipe[recipe] then
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
if not thxbob.lib.item.get_basic_type(thxbob.lib.item.basic_item(item).name) then
|
|
||||||
BioInd.writeDebug("Ingredient %s does not exist.", {thxbob.lib.item.basic_item(item).name})
|
|
||||||
end
|
|
||||||
if not (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
BioInd.writeDebug("Difficulty %s is invalid.", {difficulty})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.add_difficulty_result(recipe, difficulty, item)
|
|
||||||
if data.raw.recipe[recipe] and thxbob.lib.item.get_type(thxbob.lib.item.basic_item(item).name) and (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
|
|
||||||
if not data.raw.recipe[recipe][difficulty] then
|
|
||||||
thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
end
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe][difficulty])
|
|
||||||
thxbob.lib.item.add(data.raw.recipe[recipe][difficulty].results, item)
|
|
||||||
|
|
||||||
else
|
|
||||||
if not data.raw.recipe[recipe] then
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
if not thxbob.lib.item.get_basic_type(thxbob.lib.item.basic_item(item).name) then
|
|
||||||
BioInd.writeDebug("Item %s does not exist.", {thxbob.lib.item.basic_item(item).name})
|
|
||||||
end
|
|
||||||
if not (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
BioInd.writeDebug("Difficulty %s is invalid.", {difficulty})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function thxbob.lib.recipe.remove_difficulty_result(recipe, difficulty, item)
|
|
||||||
if data.raw.recipe[recipe] and (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
|
|
||||||
if not data.raw.recipe[recipe][difficulty] then
|
|
||||||
thxbob.lib.recipe.difficulty_split(recipe)
|
|
||||||
end
|
|
||||||
thxbob.lib.result_check(data.raw.recipe[recipe][difficulty])
|
|
||||||
thxbob.lib.item.remove(data.raw.recipe[recipe][difficulty].results, item)
|
|
||||||
|
|
||||||
else
|
|
||||||
if not data.raw.recipe[recipe] then
|
|
||||||
BioInd.writeDebug("Recipe %s does not exist.", {recipe})
|
|
||||||
end
|
|
||||||
if not (difficulty == "normal" or difficulty == "expensive") then
|
|
||||||
BioInd.writeDebug("Difficulty %s is invalid.", {difficulty})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue