fix overload bug, fix missing dominant 'on' issue

This commit is contained in:
Joachim Stolberg 2023-04-01 19:10:14 +02:00
parent 2e24ccbdcd
commit 062b3f5fef

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2020 Joachim Stolberg
Copyright (C) 2017-2023 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -33,6 +33,7 @@ local function send_message(pos, topic)
mem.overload_cnt = (mem.overload_cnt or 0) + 1
if mem.overload_cnt > OVER_LOAD_MAX then
logic.infotext(M(pos), S("TA3 Mesecons Converter"), "fault (overloaded)")
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter")
minetest.get_node_timer(pos):stop()
return false
end
@ -41,6 +42,40 @@ local function send_message(pos, topic)
techage.send_multi(own_num, numbers, topic)
end
local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local meta = M(pos)
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Mesecons Converter"))
meta:set_string("formspec", formspec(meta))
end
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
local function on_timer(pos,elapsed)
local mem = techage.get_mem(pos)
mem.overload_cnt = 0
return true
end
local function techage_set_numbers(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Mesecons Converter"))
meta:set_string("formspec", formspec(meta))
return res
end
local function after_dig_node(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
techage.del_mem(pos)
mesecon.on_dignode(pos, oldnode)
end
minetest.register_node("techage:ta3_mesecons_converter", {
description = S("TA3 Mesecons Converter"),
tiles = {
@ -56,37 +91,15 @@ minetest.register_node("techage:ta3_mesecons_converter", {
logic.after_place_node(pos, placer, "techage:ta3_mesecons_converter", S("TA3 Mesecons Converter"))
logic.infotext(meta, S("TA3 Mesecons Converter"))
meta:set_string("formspec", formspec(meta))
mem.overload_cnt = 0
mem.overload_cnt = -OVER_LOAD_MAX -- to prevent overload after placing
minetest.get_node_timer(pos):start(CYCLE_TIME)
mesecon.on_placenode(pos, minetest.get_node(pos))
end,
on_receive_fields = function(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local meta = M(pos)
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Mesecons Converter"))
meta:set_string("formspec", formspec(meta))
end
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
on_timer = function(pos,elapsed)
local mem = techage.get_mem(pos)
mem.overload_cnt = 0
return true
end,
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Mesecons Converter"))
meta:set_string("formspec", formspec(meta))
return res
end,
on_receive_fields = on_receive_fields,
on_timer = on_timer,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
mesecons = {
receptor = {
@ -96,29 +109,66 @@ minetest.register_node("techage:ta3_mesecons_converter", {
effector = {
rules = mesecon.rules.default,
action_on = function(pos, node)
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter_on")
send_message(pos, "on")
end,
action_off = function(pos, node)
send_message(pos, "off")
end,
action_change = function(pos, node)
send_message(pos, "change")
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter_on")
send_message(pos, "on")
end,
}
},
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos, oldnode, oldmetadata)
techage.del_mem(pos)
mesecon.on_dignode(pos, oldnode)
end,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:ta3_mesecons_converter_on", {
description = S("TA3 Mesecons Converter"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3_top.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_mesecons_converter.png",
},
on_receive_fields = on_receive_fields,
on_timer = on_timer,
techage_set_numbers = techage_set_numbers,
after_dig_node = after_dig_node,
mesecons = {
receptor = {
state = mesecon.state.on,
rules = mesecon.rules.default,
},
effector = {
rules = mesecon.rules.default,
action_on = function(pos, node)
end,
action_off = function(pos, node)
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter")
send_message(pos, "off")
end,
action_change = function(pos, node)
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter")
send_message(pos, "off")
end,
}
},
paramtype = "light",
light_source = 5,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
drop = "techage:ta3_mesecons_converter",
})
minetest.register_craft({
output = "techage:ta3_mesecons_converter",
@ -127,7 +177,7 @@ minetest.register_craft({
},
})
techage.register_node({"techage:ta3_mesecons_converter"}, {
techage.register_node({"techage:ta3_mesecons_converter", "techage:ta3_mesecons_converter_on"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = techage.get_mem(pos)
mem.overload_cnt = (mem.overload_cnt or 0) + 1
@ -136,8 +186,10 @@ techage.register_node({"techage:ta3_mesecons_converter"}, {
minetest.get_node_timer(pos):stop()
return false
elseif topic == "on" then
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter_on")
mesecon.receptor_on(pos, mesecon.rules.default)
elseif topic == "off" then
techage.logic.swap_node(pos, "techage:ta3_mesecons_converter")
mesecon.receptor_off(pos, mesecon.rules.default)
end
end,