2018-10-29 13:16:55 +01:00
|
|
|
--[[
|
|
|
|
|
|
|
|
=================================================
|
2019-02-11 11:07:11 +01:00
|
|
|
SmartLine Modules
|
2019-02-01 18:52:30 +01:00
|
|
|
by Micu (c) 2018, 2019
|
2018-10-29 13:16:55 +01:00
|
|
|
|
|
|
|
This file contains:
|
|
|
|
* Furnace Monitor
|
|
|
|
|
2019-02-11 11:07:11 +01:00
|
|
|
Furnace Monitor:
|
|
|
|
|
2018-10-29 13:16:55 +01:00
|
|
|
Monitor Minetest Game standard furnace with
|
|
|
|
Tubelib/Smartline devices like Controllers.
|
|
|
|
It is a one-way (read-only) gateway that converts
|
|
|
|
furnace operational status to Tubelib states.
|
|
|
|
|
|
|
|
Device checks attached node only when status is
|
|
|
|
requested so it does not consume CPU resources
|
|
|
|
when idle.
|
|
|
|
|
|
|
|
Placement: place on any side of a furnace, make
|
|
|
|
sure back plate of device has contact with
|
|
|
|
monitored node. In case of wrong orientation use
|
|
|
|
screwdriver.
|
|
|
|
|
|
|
|
Status:
|
|
|
|
"fault" - monitor is not placed on a furnace
|
|
|
|
"stopped" - furnace is not smelting/cooking
|
|
|
|
"running" - furnace is smelting/cooking items
|
|
|
|
"standby" - furnace is burning fuel but there
|
|
|
|
are no items loaded
|
|
|
|
|
|
|
|
Punch node to see current status.
|
|
|
|
|
|
|
|
License: LGPLv2.1+
|
|
|
|
=================================================
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
|
2019-02-11 11:07:11 +01:00
|
|
|
slmodules = {}
|
2018-10-29 13:16:55 +01:00
|
|
|
|
|
|
|
--[[
|
|
|
|
-------
|
|
|
|
Helpers
|
|
|
|
-------
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- get furnace status as tubelib text string:
|
|
|
|
-- not a furnace node = "fault"
|
|
|
|
-- furnace not burning = "stopped"
|
|
|
|
-- furnace smelting items = "running"
|
|
|
|
-- furnace burning without items = "standby"
|
|
|
|
local function get_tubelib_furnace_state(monitor_pos, monitor_node)
|
2019-02-01 18:52:30 +01:00
|
|
|
local monnode = monitor_node or minetest.get_node(monitor_pos)
|
2018-10-29 13:16:55 +01:00
|
|
|
local pos = vector.add(monitor_pos,
|
|
|
|
minetest.facedir_to_dir(monnode.param2))
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if node.name == "default:furnace" then
|
2019-02-01 18:52:30 +01:00
|
|
|
return tubelib.StateStrings[tubelib.STOPPED]
|
2018-10-29 13:16:55 +01:00
|
|
|
elseif node.name == "default:furnace_active" then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv:is_empty("src") then
|
2019-02-01 18:52:30 +01:00
|
|
|
return tubelib.StateStrings[tubelib.STANDBY]
|
2018-10-29 13:16:55 +01:00
|
|
|
else
|
2019-02-01 18:52:30 +01:00
|
|
|
return tubelib.StateStrings[tubelib.RUNNING]
|
2018-10-29 13:16:55 +01:00
|
|
|
end
|
|
|
|
end
|
2019-02-01 18:52:30 +01:00
|
|
|
return tubelib.StateStrings[tubelib.FAULT]
|
2018-10-29 13:16:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
-----------------
|
|
|
|
Node registration
|
|
|
|
-----------------
|
|
|
|
]]--
|
|
|
|
|
2019-02-11 11:07:11 +01:00
|
|
|
minetest.register_node("slmodules:furnacemonitor", {
|
2018-10-29 13:16:55 +01:00
|
|
|
description = "SmartLine Furnace Monitor",
|
|
|
|
inventory_image = "furnacemonitor_inventory.png",
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png",
|
|
|
|
"smartline.png^furnacemonitor_flame_black.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -6/32, -6/32, 14/32, 6/32, 6/32, 16/32},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-02-11 11:07:11 +01:00
|
|
|
local number = tubelib.add_node(pos, "slmodules:furnacemonitor")
|
2018-10-29 13:16:55 +01:00
|
|
|
meta:set_string("number", number)
|
|
|
|
meta:set_string("infotext", "Smartline Furnace Monitor " .. number)
|
|
|
|
meta:set_string("owner", placer:get_player_name())
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
tubelib.remove_node(pos)
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_punch = function(pos, node, puncher, pointed_thing)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local player_name = puncher:get_player_name()
|
|
|
|
if meta:get_string("owner") ~= player_name then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local state = get_tubelib_furnace_state(pos, node)
|
|
|
|
local msgclr = { ["fault"] = "#FFBFBF",
|
|
|
|
["standby"] = "#BFFFFF",
|
|
|
|
["stopped"] = "#BFBFFF",
|
|
|
|
["running"] = "#BFFFBF" }
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
minetest.colorize("#FFFF00", "[FurnaceMonitor:" ..
|
|
|
|
meta:get_string("number") .. "]") .. " Status is " ..
|
|
|
|
minetest.colorize(msgclr[state],
|
|
|
|
"\"" .. state .. "\""))
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = { cracky = 2, crumbly = 2 },
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2019-02-11 11:07:11 +01:00
|
|
|
tubelib.register_node("slmodules:furnacemonitor", {}, {
|
2018-10-29 13:16:55 +01:00
|
|
|
on_recv_message = function(pos, topic, payload)
|
|
|
|
if topic == "state" then
|
|
|
|
return get_tubelib_furnace_state(pos)
|
|
|
|
else
|
2019-02-01 18:52:30 +01:00
|
|
|
return "unsupported"
|
2018-10-29 13:16:55 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
--[[
|
|
|
|
--------
|
|
|
|
Crafting
|
|
|
|
--------
|
|
|
|
]]--
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2019-02-11 11:07:11 +01:00
|
|
|
output = "slmodules:furnacemonitor",
|
2018-10-29 13:16:55 +01:00
|
|
|
type = "shaped",
|
|
|
|
recipe = {
|
|
|
|
{"", "default:tin_ingot", ""},
|
|
|
|
{"dye:blue", "default:copper_ingot", "tubelib:wlanchip"},
|
|
|
|
{"", "dye:black", ""},
|
|
|
|
},
|
|
|
|
})
|
2019-02-11 11:07:11 +01:00
|
|
|
|
|
|
|
--[[
|
|
|
|
---------------------
|
|
|
|
FurnaceMonitor update
|
|
|
|
---------------------
|
|
|
|
]]--
|
|
|
|
|
|
|
|
minetest.register_lbm({
|
|
|
|
label = "FurnaceMonitor update",
|
|
|
|
name = "slmodules:furnacemonitor_update",
|
|
|
|
nodenames = {
|
|
|
|
"furnacemonitor:furnacemonitor",
|
|
|
|
},
|
|
|
|
run_at_every_load = true,
|
|
|
|
action = function(pos, node)
|
2019-02-11 11:19:18 +01:00
|
|
|
minetest.swap_node(pos, { name = "slmodules:furnacemonitor" })
|
2019-02-11 11:07:11 +01:00
|
|
|
end
|
|
|
|
})
|