Allow singleplayer to place lava on y>0. Logic block: allow to use output numbers for the expression

This commit is contained in:
Joachim Stolberg 2021-08-02 20:18:29 +02:00
parent fe37465f65
commit 428a3d552f
2 changed files with 10 additions and 4 deletions

View File

@ -119,7 +119,7 @@ local function register_liquid(source, flowing, itemname, inventory_image, name,
-------------------------------- Start Modification -------------------------------- Start Modification
-- minetest.set_node(lpos, {name = source}) -- 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!")) minetest.chat_send_player(user:get_player_name(), S("[Bucket] Lava can only be placed below sea level!"))
return return
else else

View File

@ -106,8 +106,12 @@ end
local function get_inputs(pos) local function get_inputs(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos)
-- old data is needed for formspec 'input' values -- old data is needed for formspec 'input' values
nvm.old_inp_tbl = table.copy(nvm.inp_tbl or {}) 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 return nvm.old_inp_tbl
end end
@ -148,11 +152,12 @@ local function data(nvm)
return table.concat(inp, ", "), table.concat(outp, ", ") return table.concat(inp, ", "), table.concat(outp, ", ")
end end
local function get_code(pos, nvm) local function get_code(pos, nvm, mem)
local meta = M(pos) local meta = M(pos)
local tbl = {"local inputs = get_inputs(pos) or {}"} local tbl = {"local inputs = get_inputs(pos) or {}"}
local owner = M(pos):get_string("owner") local owner = M(pos):get_string("owner")
nvm.own_num = nvm.own_num or M(pos):get_string("node_number") nvm.own_num = nvm.own_num or M(pos):get_string("node_number")
mem.outp_num = {}
for i = 1,NUM_RULES do for i = 1,NUM_RULES do
local outp = meta:get_string("outp" .. i) 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, 'on', '"on"')
expr = string.gsub(expr, 'off', '"off"') expr = string.gsub(expr, 'off', '"off"')
tbl[#tbl + 1] = "if "..expr.." then send(pos, '"..outp.."', '"..val.."') end" tbl[#tbl + 1] = "if "..expr.." then send(pos, '"..outp.."', '"..val.."') end"
table.insert(mem.outp_num, outp)
else else
nvm.error = err nvm.error = err
return return
@ -190,7 +196,7 @@ end
local function execute(pos) local function execute(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(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 if mem.code then
local res, _ = pcall(mem.code) local res, _ = pcall(mem.code)
if not res then if not res then
@ -304,7 +310,7 @@ minetest.register_node("techage:ta3_logic2", {
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.code = nil mem.code = nil
get_code(pos, nvm) get_code(pos, nvm, mem)
meta:set_string("formspec", formspec(pos, meta)) meta:set_string("formspec", formspec(pos, meta))
end end
end, end,