rename variables to reflect the official api and making the code more clear
This commit is contained in:
parent
7b9571912d
commit
d3110a9e20
@ -17,43 +17,43 @@ local function autocraft(inventory, pos)
|
|||||||
if not inventory then return end
|
if not inventory then return end
|
||||||
local recipe = inventory:get_list("recipe")
|
local recipe = inventory:get_list("recipe")
|
||||||
if not recipe then return end
|
if not recipe then return end
|
||||||
local recipe_last
|
local cached_recipe
|
||||||
local result
|
local output
|
||||||
local new
|
local decremented_input
|
||||||
|
|
||||||
local hash, craft = get_cached_craft(pos)
|
local hash, craft = get_cached_craft(pos)
|
||||||
if craft == nil then
|
if craft == nil then
|
||||||
recipe_last = {}
|
cached_recipe = {}
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
recipe_last[i] = recipe[i]
|
cached_recipe[i] = recipe[i]
|
||||||
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
||||||
end
|
end
|
||||||
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
||||||
autocrafterCache[hash] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
|
autocrafterCache[hash] = {recipe = recipe, output = output, decremented_input = decremented_input}
|
||||||
else
|
else
|
||||||
recipe_last, result, new = craft.recipe, craft.result, craft.new
|
cached_recipe, output, decremented_input = craft.recipe, craft.output, craft.decremented_input
|
||||||
local recipe_changed = false
|
local recipe_changed = false
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
local recipe_entry, recipe_last_entry = recipe[i], recipe_last[i]
|
local recipe_entry, cached_recipe_entry = recipe[i], cached_recipe[i]
|
||||||
if recipe_entry:get_name() ~= recipe_last_entry:get_name()
|
if recipe_entry:get_name() ~= cached_recipe_entry:get_name()
|
||||||
or recipe_entry:get_count() ~= recipe_last_entry:get_count() then
|
or recipe_entry:get_count() ~= cached_recipe_entry:get_count() then
|
||||||
recipe_changed = true
|
recipe_changed = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if recipe_changed then
|
if recipe_changed then
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
recipe_last[i] = recipe[i]
|
cached_recipe[i] = recipe[i]
|
||||||
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
|
||||||
end
|
end
|
||||||
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
||||||
autocrafterCache[hash] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
|
autocrafterCache[hash] = {recipe = recipe, output = output, decremented_input = decremented_input}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if result.item:is_empty() then return end
|
if output.item:is_empty() then return end
|
||||||
result = result.item
|
output = output.item
|
||||||
if not inventory:room_for_item("dst", result) then return end
|
if not inventory:room_for_item("dst", output) then return end
|
||||||
local to_use = {}
|
local to_use = {}
|
||||||
for _, item in ipairs(recipe) do
|
for _, item in ipairs(recipe) do
|
||||||
if item~= nil and not item:is_empty() then
|
if item~= nil and not item:is_empty() then
|
||||||
@ -74,9 +74,9 @@ local function autocraft(inventory, pos)
|
|||||||
inventory:remove_item("src", ItemStack(itemname))
|
inventory:remove_item("src", ItemStack(itemname))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
inventory:add_item("dst", result)
|
inventory:add_item("dst", output)
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
inventory:add_item("dst", new.items[i])
|
inventory:add_item("dst", decremented_input.items[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user