From f3b636d63e488ac409e2f0a895c5f00f7955cb44 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 27 Jan 2015 05:27:36 +0100 Subject: let the autocrafter catch up on missed crafts --- autocrafter.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/autocrafter.lua b/autocrafter.lua index 4216517..d8cfc2d 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -1,5 +1,7 @@ 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 index = {} for _, stack in pairs(invlist) do @@ -57,14 +59,14 @@ local function on_recipe_change(pos, inventory) local timer = minetest.get_node_timer(pos) if not timer:is_started() then - timer:start(1) + timer:start(craft_time) end end local function on_inventory_change(pos, inventory) local timer = minetest.get_node_timer(pos) if not timer:is_started() then - timer:start(1) + timer:start(craft_time) end end @@ -101,7 +103,12 @@ local function run_autocrafter(pos, elapsed) local meta = minetest.get_meta(pos) local inventory = meta:get_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 local function update_autocrafter(pos) -- cgit v1.2.3