diff --git a/mods/lord/Blocks/grinder/src/grinder/Grinder.lua b/mods/lord/Blocks/grinder/src/grinder/Grinder.lua index d6f3cedc7..be39debd4 100644 --- a/mods/lord/Blocks/grinder/src/grinder/Grinder.lua +++ b/mods/lord/Blocks/grinder/src/grinder/Grinder.lua @@ -40,8 +40,8 @@ local function get_initiated_meta(pos) "fuel_totaltime", "fuel_time", "src_totaltime", - "src_time" }) do - -- init with 0.0 if var not set + "src_time" + }) do if not meta:get_float(name) then meta:set_float(name, 0.0) end @@ -49,6 +49,18 @@ local function get_initiated_meta(pos) return meta end +--- @param meta NodeMetaRef +local function reset_meta_vars(meta) + for _, name in pairs({ + "fuel_totaltime", + "fuel_time", + "src_totaltime", + "src_time" + }) do + meta:set_float(name, 0.0) + end +end + --- Swaps node if node is not same and return old node name. --- @see minetest.swap_node (https://dev.minetest.net/minetest.swap_node) --- @@ -90,6 +102,7 @@ end --- @public --- @param hint_en string A template for hinting in English. Use "%s" for machine name placeholder. function Grinder:deactivate(hint_en) + reset_meta_vars(self:get_meta()) swap_node(self.position, "grinder:grinder") self:get_meta():set_string("infotext", SL((hint_en):format(machine_name))) self:get_meta():set_string("formspec", form.get('inactive')) diff --git a/mods/lord/Blocks/grinder/src/grinder/Processor.lua b/mods/lord/Blocks/grinder/src/grinder/Processor.lua index abe38a58d..461f13442 100644 --- a/mods/lord/Blocks/grinder/src/grinder/Processor.lua +++ b/mods/lord/Blocks/grinder/src/grinder/Processor.lua @@ -5,9 +5,10 @@ local Grinder = require("grinder.Grinder") --- - Returns whether grinding possible & --- - if possible, also returns (RecipeOutput - result, RecipeInput - remaining) for source & fuel. --- - So, returns `possible, result_source, remaining_source, result_fuel, remaining_fuel` ---- @param inv InvRef +--- @param inv InvRef +--- @param meta NodeMetaRef --- @return boolean, RecipeOutput|nil, RecipeInput|nil, RecipeOutput|nil, RecipeInput|nil -local function grinding_possible(inv) +local function grinding_possible(inv, meta) local result_source, remaining_source = minetest.get_craft_result({ method = 'grinder', type = 'cooking', @@ -24,7 +25,10 @@ local function grinding_possible(inv) items = inv:get_list("fuel") }) - local possible = result_source.time > 0 and result_fuel.time > 0 and inv:room_for_item("dst", result_source.item) + local possible = + result_source.time > 0 and + (result_fuel.time > 0 or meta:get_int("fuel_time") > 0) and + inv:room_for_item("dst", result_source.item) if not possible then return false, nil, nil, nil, nil end @@ -39,11 +43,10 @@ local function burn_fuel(meta, remaining_fuel, result_fuel) local fuel_time = meta:get_int("fuel_time") local fuel_totaltime = meta:get_int("fuel_totaltime") - if fuel_totaltime ~= result_fuel.time then - meta:set_int("fuel_totaltime", result_fuel.time) - end if fuel_time == 0 then meta:get_inventory():set_list("fuel", remaining_fuel.items) + meta:set_int("fuel_totaltime", result_fuel.time) + fuel_totaltime = result_fuel.time end fuel_time = fuel_time + 1 @@ -96,7 +99,7 @@ function Processor.act(pos) local meta = g:get_meta() local inv = meta:get_inventory() - local possible, result_source, remaining_source, result_fuel, remaining_fuel = grinding_possible(inv) + local possible, result_source, remaining_source, result_fuel, remaining_fuel = grinding_possible(inv, meta) if possible then g:activate("%s Grinding")