mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-12-26 02:40:23 +01:00
let the autocrafter catch up on missed crafts
This commit is contained in:
parent
44bafb844a
commit
f3b636d63e
@ -1,5 +1,7 @@
|
|||||||
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
|
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
|
||||||
|
|
||||||
|
local craft_time = 1
|
||||||
|
|
||||||
local function count_index(invlist)
|
local function count_index(invlist)
|
||||||
local index = {}
|
local index = {}
|
||||||
for _, stack in pairs(invlist) do
|
for _, stack in pairs(invlist) do
|
||||||
@ -57,14 +59,14 @@ local function on_recipe_change(pos, inventory)
|
|||||||
|
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
if not timer:is_started() then
|
if not timer:is_started() then
|
||||||
timer:start(1)
|
timer:start(craft_time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_inventory_change(pos, inventory)
|
local function on_inventory_change(pos, inventory)
|
||||||
local timer = minetest.get_node_timer(pos)
|
local timer = minetest.get_node_timer(pos)
|
||||||
if not timer:is_started() then
|
if not timer:is_started() then
|
||||||
timer:start(1)
|
timer:start(craft_time)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -101,7 +103,12 @@ local function run_autocrafter(pos, elapsed)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inventory = meta:get_inventory()
|
local inventory = meta:get_inventory()
|
||||||
local craft = get_craft(pos, inventory)
|
local craft = get_craft(pos, inventory)
|
||||||
return autocraft(inventory, craft)
|
|
||||||
|
for step = 1, math.floor(elapsed/craft_time) do
|
||||||
|
local continue = autocraft(inventory, craft)
|
||||||
|
if not continue then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_autocrafter(pos)
|
local function update_autocrafter(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user