fix crash and add mcl2 support

This commit is contained in:
AFCMS 2021-06-01 14:48:47 +02:00
parent 9a985ede61
commit 27286e2298
2 changed files with 81 additions and 49 deletions

129
init.lua

@ -3,6 +3,8 @@ minetest.log("action", "[mesecons_onlinedetector] loading...")
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local F = minetest.formspec_escape local F = minetest.formspec_escape
local has_mcl_core = minetest.get_modpath("mcl_core")
local table = table local table = table
local function get_detector_form(default) local function get_detector_form(default)
@ -38,56 +40,74 @@ local function update_detector_off(pos, target)
end end
end end
minetest.register_node("mesecons_onlinedetector:online_detector_off", { local nodedef = {
description = S("Online Detector"), description = S("Online Detector"),
_doc_items_longdesc = S("Allows you to know if a player is connected."), _doc_items_longdesc = S("Allows you to know if a player is connected."),
tiles = {"mesecons_onlinedetector_online_detector_off.png"},
groups = {cracky = 2, mesecon_detector_off = 1, mesecon = 2},
mesecons = {
receptor = {
state = mesecon.state.off,
rules = mesecon.rules.alldirs,
},
},
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_detector_form(meta:get_string("name"))) meta:set_string("formspec", get_detector_form(meta:get_string("name")))
end, end,
on_receive_fields = function(pos, formname, fields, sender) }
if fields.name then
local meta = minetest.get_meta(pos)
meta:set_string("name", fields.name)
meta:set_string("formspec", get_detector_form(fields.name))
update_detector_off(pos, fields.name)
end
end,
})
minetest.register_node("mesecons_onlinedetector:online_detector_on", {
description = S("Online Detector"), local off_def = table.copy(nodedef)
_doc_items_longdesc = S("Allows you to know if a player is connected."),
tiles = {"mesecons_onlinedetector_online_detector_on.png"}, off_def.tiles = {"mesecons_onlinedetector_online_detector_off.png"}
groups = {cracky = 2, mesecon_detector_on = 1, mesecon = 2, not_in_creative_inventory = 1},
drop = "mesecons_onlinedetector:online_detector_off", off_def.mesecons = {
mesecons = { receptor = {
receptor = { state = mesecon.state.off,
state = mesecon.state.on, rules = mesecon.rules.alldirs,
rules = mesecon.rules.alldirs,
},
}, },
on_construct = function(pos) }
function off_def.on_receive_fields(pos, formname, fields, sender)
if fields.name then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("formspec", get_detector_form(meta:get_string("name"))) meta:set_string("name", fields.name)
end, meta:set_string("formspec", get_detector_form(fields.name))
on_receive_fields = function(pos, formname, fields, sender) update_detector_off(pos, fields.name)
if fields.name then end
local meta = minetest.get_meta(pos) end
meta:set_string("name", fields.name)
meta:set_string("formspec", get_detector_form(fields.name)) if has_mcl_core then
update_detector_on(pos, fields.name) --off_def.groups = {cracky = 2, mesecon_detector_off = 1, mesecon = 2}
end off_def.groups = {handy = 1, mesecon_detector_off = 1, mesecon = 2}
end, else
}) off_def.groups = {cracky = 2, mesecon_detector_off = 1, mesecon = 2}
end
minetest.register_node("mesecons_onlinedetector:online_detector_off", off_def)
local on_def = table.copy(nodedef)
on_def.tiles = {"mesecons_onlinedetector_online_detector_on.png"}
on_def.mesecons = {
receptor = {
state = mesecon.state.on,
rules = mesecon.rules.alldirs,
},
}
function on_def.on_receive_fields(pos, formname, fields, sender)
if fields.name then
local meta = minetest.get_meta(pos)
meta:set_string("name", fields.name)
meta:set_string("formspec", get_detector_form(fields.name))
update_detector_on(pos, fields.name)
end
end
if has_mcl_core then
--on_def.groups = {cracky = 2, mesecon_detector_off = 1, mesecon = 2}
on_def.groups = {handy = 1, mesecon_detector_on = 1, mesecon = 2}
else
on_def.groups = {cracky = 2, mesecon_detector_on = 1, mesecon = 2}
end
minetest.register_node("mesecons_onlinedetector:online_detector_on", on_def)
minetest.register_abm({ minetest.register_abm({
label = "mesecons_onlinedetector:online_detector_off", label = "mesecons_onlinedetector:online_detector_off",
@ -109,13 +129,24 @@ minetest.register_abm({
end, end,
}) })
--[[minetest.register_craft({ if minetest.get_modpath("default") then
output = "mesecons_onlinedetector:online_detector_off", minetest.register_craft({
recipe = { output = "mesecons_onlinedetector:online_detector_off",
{'mcl_dye:black', 'mcl_dye:black', 'mcl_dye:black'}, recipe = {
{'mcl_dye:black', 'pala_paladium:paladium_ingot', 'mcl_dye:black'}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{'pala_paladium:titanium_ingot', 'pala_paladium:titanium_ingot', 'pala_paladium:titanium_ingot'}, {"default:steel_ingot", "mesecons_luacontroller:luacontroller0000", "default:steel_ingot"},
} {"default:stone", "default:stone", "default:stone"},
})]] },
})
elseif has_mcl_core then
minetest.register_craft({
output = "mesecons_onlinedetector:online_detector_off",
recipe = {
{"mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot"},
{"mcl_core:iron_ingot", "mesecons:wire_00000000_off", "mcl_core:iron_ingot"},
{"mcl_core:stone", "mcl_core:stone", "mcl_core:stone"},
},
})
end
minetest.log("action", "[mesecons_onlinedetector] loaded succesfully") minetest.log("action", "[mesecons_onlinedetector] loaded succesfully")

@ -1,4 +1,5 @@
name = mesecons_onlinedetector name = mesecons_onlinedetector
description = Add online detector to mesecons description = Add online detector to mesecons
depends = mesecons depends = mesecons
optional_depends = default, mcl_core, mesecons_luacontroller
author = AFCMS author = AFCMS