From 428a3d552f332cda9395af0e6ed7eb7ddfa8ae6e Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 2 Aug 2021 20:18:29 +0200 Subject: [PATCH] Allow singleplayer to place lava on y>0. Logic block: allow to use output numbers for the expression --- iron_age/recipes.lua | 2 +- logic/logic_block.lua | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/iron_age/recipes.lua b/iron_age/recipes.lua index af1e1ec..c00e7ea 100644 --- a/iron_age/recipes.lua +++ b/iron_age/recipes.lua @@ -119,7 +119,7 @@ local function register_liquid(source, flowing, itemname, inventory_image, name, -------------------------------- Start Modification -- minetest.set_node(lpos, {name = source}) - if source == "default:lava_source" and lpos.y > 0 then + if source == "default:lava_source" and lpos.y > 0 and not minetest.is_singleplayer() then minetest.chat_send_player(user:get_player_name(), S("[Bucket] Lava can only be placed below sea level!")) return else diff --git a/logic/logic_block.lua b/logic/logic_block.lua index 942a410..d81d463 100644 --- a/logic/logic_block.lua +++ b/logic/logic_block.lua @@ -106,8 +106,12 @@ end local function get_inputs(pos) local nvm = techage.get_nvm(pos) + local mem = techage.get_mem(pos) -- old data is needed for formspec 'input' values nvm.old_inp_tbl = table.copy(nvm.inp_tbl or {}) + for _, num in ipairs(mem.outp_num or {}) do + nvm.old_inp_tbl[num] = nvm.outp_tbl[num] or "off" + end return nvm.old_inp_tbl end @@ -148,11 +152,12 @@ local function data(nvm) return table.concat(inp, ", "), table.concat(outp, ", ") end -local function get_code(pos, nvm) +local function get_code(pos, nvm, mem) local meta = M(pos) local tbl = {"local inputs = get_inputs(pos) or {}"} local owner = M(pos):get_string("owner") nvm.own_num = nvm.own_num or M(pos):get_string("node_number") + mem.outp_num = {} for i = 1,NUM_RULES do local outp = meta:get_string("outp" .. i) @@ -167,6 +172,7 @@ local function get_code(pos, nvm) expr = string.gsub(expr, 'on', '"on"') expr = string.gsub(expr, 'off', '"off"') tbl[#tbl + 1] = "if "..expr.." then send(pos, '"..outp.."', '"..val.."') end" + table.insert(mem.outp_num, outp) else nvm.error = err return @@ -190,7 +196,7 @@ end local function execute(pos) local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos) - mem.code = mem.code or get_code(pos, nvm) + mem.code = mem.code or get_code(pos, nvm, mem) if mem.code then local res, _ = pcall(mem.code) if not res then @@ -304,7 +310,7 @@ minetest.register_node("techage:ta3_logic2", { local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos) mem.code = nil - get_code(pos, nvm) + get_code(pos, nvm, mem) meta:set_string("formspec", formspec(pos, meta)) end end,