forked from minetest-mods/craftguide
Minor cleaning
This commit is contained in:
parent
738c2140a7
commit
06bef9777a
79
init.lua
79
init.lua
|
@ -172,6 +172,10 @@ function craftguide.register_craft(def)
|
||||||
return log("error", "craftguide.register_craft(): output missing")
|
return log("error", "craftguide.register_craft(): output missing")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not is_table(def.items) then
|
||||||
|
def.items = {}
|
||||||
|
end
|
||||||
|
|
||||||
if def.grid then
|
if def.grid then
|
||||||
if not is_table(def.grid) then
|
if not is_table(def.grid) then
|
||||||
def.grid = {}
|
def.grid = {}
|
||||||
|
@ -195,20 +199,14 @@ function craftguide.register_craft(def)
|
||||||
c = c + 1
|
c = c + 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not is_table(def.items) then
|
|
||||||
def.items = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
local len = #def.items
|
local len = #def.items
|
||||||
|
|
||||||
for i = 1, len do
|
for i = 1, len do
|
||||||
def.items[i] = def.items[i]:gsub(",,", ", ,")
|
def.items[i] = def.items[i]:gsub(",,", ", ,")
|
||||||
|
local rlen = #split(def.items[i], ",")
|
||||||
|
|
||||||
local row = split(def.items[i], ",")
|
if rlen > def.width then
|
||||||
local l = #row
|
def.width = rlen
|
||||||
|
|
||||||
if l > def.width then
|
|
||||||
def.width = l
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -224,7 +222,7 @@ function craftguide.register_craft(def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = match(def.output, "%S*")
|
local output = clean_name(def.output)
|
||||||
recipes_cache[output] = recipes_cache[output] or {}
|
recipes_cache[output] = recipes_cache[output] or {}
|
||||||
insert(recipes_cache[output], def)
|
insert(recipes_cache[output], def)
|
||||||
end
|
end
|
||||||
|
@ -860,18 +858,17 @@ end
|
||||||
|
|
||||||
local old_register_craft = core.register_craft
|
local old_register_craft = core.register_craft
|
||||||
|
|
||||||
core.register_craft = function(recipe)
|
core.register_craft = function(def)
|
||||||
old_register_craft(recipe)
|
old_register_craft(def)
|
||||||
|
|
||||||
if recipe.type == "toolrepair" then
|
if def.type == "toolrepair" then
|
||||||
toolrepair = recipe.additional_wear * -100
|
toolrepair = def.additional_wear * -100
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = recipe.output or
|
local output = def.output or (is_str(def.recipe) and def.recipe or "")
|
||||||
(is_str(recipe.recipe) and recipe.recipe or "")
|
|
||||||
|
|
||||||
if output == "" then return end
|
if output == "" then return end
|
||||||
output = {clean_name(output)}
|
output = {clean_name(output)}
|
||||||
|
|
||||||
local groups
|
local groups
|
||||||
|
|
||||||
if is_group(output[1]) then
|
if is_group(output[1]) then
|
||||||
|
@ -880,37 +877,37 @@ core.register_craft = function(recipe)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #output do
|
for i = 1, #output do
|
||||||
local item = output[i]
|
local name = output[i]
|
||||||
if item == current_alias[1] then
|
if name == current_alias[1] then
|
||||||
item = current_alias[2]
|
name = current_alias[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
recipe.items = {}
|
def.items = {}
|
||||||
|
|
||||||
if recipe.type == "fuel" then
|
if def.type == "fuel" then
|
||||||
fuel_cache[item] = recipe
|
fuel_cache[name] = def
|
||||||
|
|
||||||
elseif recipe.type == "cooking" then
|
elseif def.type == "cooking" then
|
||||||
recipe.width = recipe.cooktime
|
def.width = def.cooktime
|
||||||
recipe.cooktime = nil
|
def.cooktime = nil
|
||||||
recipe.items[1] = recipe.recipe
|
def.items[1] = def.recipe
|
||||||
|
|
||||||
elseif recipe.type == "shapeless" then
|
elseif def.type == "shapeless" then
|
||||||
recipe.width = 0
|
def.width = 0
|
||||||
for j = 1, #recipe.recipe do
|
for j = 1, #def.recipe do
|
||||||
recipe.items[#recipe.items + 1] = recipe.recipe[j]
|
def.items[#def.items + 1] = def.recipe[j]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
recipe.width = #recipe.recipe[1]
|
def.width = #def.recipe[1]
|
||||||
local c = 1
|
local c = 1
|
||||||
|
|
||||||
for j = 1, #recipe.recipe do
|
for j = 1, #def.recipe do
|
||||||
if recipe.recipe[j] then
|
if def.recipe[j] then
|
||||||
for h = 1, recipe.width do
|
for h = 1, def.width do
|
||||||
local it = recipe.recipe[j][h]
|
local it = def.recipe[j][h]
|
||||||
|
|
||||||
if it and it ~= "" then
|
if it and it ~= "" then
|
||||||
recipe.items[c] = it
|
def.items[c] = it
|
||||||
end
|
end
|
||||||
|
|
||||||
c = c + 1
|
c = c + 1
|
||||||
|
@ -919,10 +916,10 @@ core.register_craft = function(recipe)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if recipe.type ~= "fuel" then
|
if def.type ~= "fuel" then
|
||||||
recipe.recipe = nil
|
def.recipe = nil
|
||||||
recipes_cache[item] = recipes_cache[item] or {}
|
recipes_cache[name] = recipes_cache[name] or {}
|
||||||
insert(recipes_cache[item], 1, recipe)
|
insert(recipes_cache[name], 1, def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user