Merge remote-tracking branch 'upstream/master'

This commit is contained in:
bri cassa 2022-08-26 15:11:33 +02:00
commit 4ecc694518
2 changed files with 53 additions and 22 deletions

View File

@ -23,17 +23,19 @@ local gate_get_input_rules_twoinputs = mesecon.horiz_rules_getter({
local function set_gate(pos, node, state) local function set_gate(pos, node, state)
local gate = minetest.registered_nodes[node.name] local gate = minetest.registered_nodes[node.name]
local new_nodename = state and gate.onstate or gate.offstate
minetest.swap_node(pos, {name = new_nodename, param2 = node.param2})
if new_nodename ~= node.name then
if mesecon.do_overheat(pos) then if mesecon.do_overheat(pos) then
minetest.remove_node(pos) minetest.remove_node(pos)
mesecon.receptor_off(pos, gate_get_output_rules(node)) mesecon.receptor_off(pos, gate_get_output_rules(node))
minetest.add_item(pos, gate.drop) minetest.add_item(pos, gate.drop)
elseif state then elseif state then
minetest.swap_node(pos, {name = gate.onstate, param2=node.param2})
mesecon.receptor_on(pos, gate_get_output_rules(node)) mesecon.receptor_on(pos, gate_get_output_rules(node))
else else
minetest.swap_node(pos, {name = gate.offstate, param2=node.param2})
mesecon.receptor_off(pos, gate_get_output_rules(node)) mesecon.receptor_off(pos, gate_get_output_rules(node))
end end
end
end end
local function update_gate(pos, node, link, newstate) local function update_gate(pos, node, link, newstate)
@ -42,11 +44,36 @@ local function update_gate(pos, node, link, newstate)
if gate.inputnumber == 1 then if gate.inputnumber == 1 then
set_gate(pos, node, gate.assess(newstate == "on")) set_gate(pos, node, gate.assess(newstate == "on"))
elseif gate.inputnumber == 2 then elseif gate.inputnumber == 2 then
-- Inputs are stored in param2. Bit 5 is always set.
-- input1 is bit 6 and input2 is bit 7.
local val1, val2
if node.param2 >= 32 then
-- Bit 5 is set, so param2 is in the proper format.
if link.name == "input1" then
val1 = newstate == "on"
val2 = node.param2 >= 128
else
val1 = node.param2 % 128 >= 64
val2 = newstate == "on"
end
else
-- Migrate old gates where the inputs are stored as metadata.
-- This also triggers for newly placed gates.
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int(link.name, newstate == "on" and 1 or 0) if link.name == "input1" then
val1 = newstate == "on"
local val1 = meta:get_int("input1") == 1 val2 = meta:get_int("input2") == 1
local val2 = meta:get_int("input2") == 1 else
val1 = meta:get_int("input1") == 1
val2 = newstate == "on"
end
-- Set bit 5 so this won't happen again.
node.param2 = node.param2 + 32
-- Clear the metadata.
meta:set_string("input1", "")
meta:set_string("input2", "")
end
node.param2 = node.param2 % 64 + (val1 and 64 or 0) + (val2 and 128 or 0)
set_gate(pos, node, gate.assess(val1, val2)) set_gate(pos, node, gate.assess(val1, val2))
end end
end end

View File

@ -332,7 +332,8 @@ yc.parse_get_eeprom_param = function(cond, starti)
local addr local addr
while s ~= "" do while s ~= "" do
s = string.sub(cond, i, i) s = string.sub(cond, i, i)
if string.find("0123456789", s) == nil or s == "" then local b = s:byte()
if s == "" or 48 > b or b > 57 then
addr = string.sub(cond, starti, i-1) -- i: last number i+1 after last number addr = string.sub(cond, starti, i-1) -- i: last number i+1 after last number
return addr, i return addr, i
end end
@ -419,7 +420,9 @@ yc.command_sbi = function(params, eeprom, L, Lv)
if status == nil then return nil, nil end if status == nil then return nil, nil end
if string.find("ABCD", params[1])~=nil and #params[1]==1 then --is a port if #params[1]==1 then
local b = params[1]:byte()
if 65 <= b and b <= 68 then -- is a port
if status == "1" then if status == "1" then
Lv = yc.set_portstate (params[1], true, Lv) Lv = yc.set_portstate (params[1], true, Lv)
else else
@ -427,6 +430,7 @@ yc.command_sbi = function(params, eeprom, L, Lv)
end end
return eeprom, Lv; return eeprom, Lv;
end end
end
--is an eeprom address --is an eeprom address
local new_eeprom = ""; local new_eeprom = "";