From 62be5cf8181aef682e4dd3e26b34090a03bb352a Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 14 May 2021 18:38:08 +0200 Subject: [PATCH] Fix no-power issues for several machines, fix grinder recipe bug --- basic_machines/autocrafter.lua | 3 +++ basic_machines/distributor.lua | 1 - basic_machines/electronic_fab.lua | 3 +++ basic_machines/gravelrinser.lua | 34 ++++++++++++------------------- basic_machines/gravelsieve.lua | 3 +++ basic_machines/grinder.lua | 30 +++++++++++++++++++++------ basic_machines/quarry.lua | 9 ++------ basic_machines/recycler.lua | 3 +++ basic_machines/ta4_injector.lua | 3 +++ basis/node_states.lua | 10 +++++++-- 10 files changed, 62 insertions(+), 37 deletions(-) diff --git a/basic_machines/autocrafter.lua b/basic_machines/autocrafter.lua index 1b937c9..b8d29ee 100644 --- a/basic_machines/autocrafter.lua +++ b/basic_machines/autocrafter.lua @@ -380,6 +380,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = diff --git a/basic_machines/distributor.lua b/basic_machines/distributor.lua index 4f70342..339dd0a 100644 --- a/basic_machines/distributor.lua +++ b/basic_machines/distributor.lua @@ -478,7 +478,6 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, - on_node_load = function(pos) CRD(pos).State:on_node_load(pos) end, diff --git a/basic_machines/electronic_fab.lua b/basic_machines/electronic_fab.lua index 0db86a6..b73318f 100644 --- a/basic_machines/electronic_fab.lua +++ b/basic_machines/electronic_fab.lua @@ -204,6 +204,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = diff --git a/basic_machines/gravelrinser.lua b/basic_machines/gravelrinser.lua index e8786e3..77b853f 100644 --- a/basic_machines/gravelrinser.lua +++ b/basic_machines/gravelrinser.lua @@ -129,6 +129,15 @@ local function get_random_gravel_ore() end end +local function remove_objects(pos) + for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do + local lua_entity = object:get_luaentity() + if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then + object:remove() + end + end +end + local function washing(pos, crd, nvm, inv) -- for testing purposes if inv:contains_item("src", ItemStack("default:stick")) then @@ -163,7 +172,6 @@ local function keep_running(pos, elapsed) local crd = CRD(pos) local inv = M(pos):get_inventory() washing(pos, crd, nvm, inv) - return crd.State:is_active(nvm) end local function on_receive_fields(pos, formname, fields, player) @@ -240,6 +248,10 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + remove_objects({x=pos.x, y=pos.y+1, z=pos.z}) + CRD(pos).State:on_node_load(pos) + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = @@ -321,26 +333,6 @@ function techage.add_rinser_recipe(recipe) end end -local function remove_objects(pos) - for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do - local lua_entity = object:get_luaentity() - if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then - object:remove() - end - end -end - -minetest.register_lbm({ - label = "[techage] Rinser update", - name = "techage:rinser_update", - nodenames = {"techage:ta2_rinser_act", "techage:ta3_rinser_act"}, - run_at_every_load = true, - action = function(pos, node) - remove_objects({x=pos.x, y=pos.y+1, z=pos.z}) - end -}) - - techage.add_rinser_recipe({input="techage:sieved_gravel", output="techage:usmium_nuggets", probability=30}) techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=15}) diff --git a/basic_machines/gravelsieve.lua b/basic_machines/gravelsieve.lua index 6f307c5..6c2a340 100644 --- a/basic_machines/gravelsieve.lua +++ b/basic_machines/gravelsieve.lua @@ -175,6 +175,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index 1094a6c..53a3b7b 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -73,10 +73,22 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player return stack:get_count() end -local function src_to_dst(src_stack, idx, num_items, inv, dst_name) - local taken = src_stack:take_item(num_items) - local output = ItemStack(dst_name) - output:set_count(output:get_count() * taken:get_count()) +-- Grinder normaly handles 'num_items' per cycle. 'num_items' is node stage dependent. +-- But if 'inp_num' > 1 (wheat recipes), use 'inp_num' and produce one output item. +local function src_to_dst(src_stack, idx, num_items, inp_num, inv, dst_name, num_input) + local taken, output + if inp_num > 1 then + if src_stack:get_count() >= inp_num then + taken = src_stack:take_item(inp_num) + output = ItemStack(dst_name) + else + return false + end + else + taken = src_stack:take_item(num_items) + output = ItemStack(dst_name) + output:set_count(output:get_count() * taken:get_count()) + end if inv:room_for_item("dst", output) then inv:set_stack("src", idx, src_stack) inv:add_item("dst", output) @@ -91,7 +103,8 @@ local function grinding(pos, crd, nvm, inv) if not stack:is_empty() then local name = stack:get_name() if Recipes[name] then - if src_to_dst(stack, idx, crd.num_items, inv, Recipes[name]) then + local recipe = Recipes[name] + if src_to_dst(stack, idx, crd.num_items, recipe.inp_num, inv, recipe.output) then crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) else crd.State:blocked(pos, nvm) @@ -186,6 +199,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local node_name_ta2, node_name_ta3, node_name_ta4 = @@ -264,7 +280,9 @@ if minetest.global_exists("unified_inventory") then end function techage.add_grinder_recipe(recipe) - Recipes[recipe.input] = recipe.output + local name, num = unpack(string.split(recipe.input, " ", false, 1)) + Recipes[name] = {input = name,inp_num = tonumber(num) or 1, output = recipe.output} + if minetest.global_exists("unified_inventory") then recipe.items = {recipe.input} recipe.type = "grinding" diff --git a/basic_machines/quarry.lua b/basic_machines/quarry.lua index 22ebfa1..d87200a 100644 --- a/basic_machines/quarry.lua +++ b/basic_machines/quarry.lua @@ -368,13 +368,8 @@ local tubing = { return CRD(pos).State:on_receive_message(pos, topic, payload) end end, - on_node_load = function(pos, node) - local nvm = techage.get_nvm(pos) - if nvm.techage_state == techage.RUNNING then - play_sound(pos) - else - stop_sound(pos) - end + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) end, } diff --git a/basic_machines/recycler.lua b/basic_machines/recycler.lua index 59271cf..ce85b3f 100644 --- a/basic_machines/recycler.lua +++ b/basic_machines/recycler.lua @@ -231,6 +231,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local _, _, node_name_ta4 = diff --git a/basic_machines/ta4_injector.lua b/basic_machines/ta4_injector.lua index 61c264f..86cca3d 100644 --- a/basic_machines/ta4_injector.lua +++ b/basic_machines/ta4_injector.lua @@ -242,6 +242,9 @@ local tubing = { on_recv_message = function(pos, src, topic, payload) return CRD(pos).State:on_receive_message(pos, topic, payload) end, + on_node_load = function(pos) + CRD(pos).State:on_node_load(pos) + end, } local _, node_name_ta3, node_name_ta4 = diff --git a/basis/node_states.lua b/basis/node_states.lua index 23a1909..4614481 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -471,9 +471,15 @@ function NodeStates:on_receive_message(pos, topic, payload) end end --- repair corrupt node data +-- restart timer function NodeStates:on_node_load(pos) - -- tbd + local nvm = techage.get_nvm(pos) + local state = nvm.techage_state or STOPPED + if state == RUNNING then + minetest.get_node_timer(pos):start(self.cycle_time) + elseif state < FAULT then + minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks) + end end minetest.register_node("techage:defect_dummy", {