2017-03-02 06:38:53 +01:00
|
|
|
-- power/ctrl.lua
|
2017-03-02 02:27:00 +01:00
|
|
|
|
|
|
|
local me = microexpansion
|
2019-05-04 13:53:49 +02:00
|
|
|
local network = me.network
|
2017-03-02 02:27:00 +01:00
|
|
|
|
2020-03-07 18:02:14 +01:00
|
|
|
--FIXME: accept multiple controllers in one network
|
|
|
|
|
2017-03-02 02:27:00 +01:00
|
|
|
-- [register node] Controller
|
|
|
|
me.register_node("ctrl", {
|
2019-05-04 13:53:49 +02:00
|
|
|
description = "ME Controller",
|
2017-07-25 19:47:25 +02:00
|
|
|
tiles = {
|
2017-03-02 02:27:00 +01:00
|
|
|
"ctrl_sides",
|
|
|
|
"ctrl_bottom",
|
|
|
|
"ctrl_sides",
|
|
|
|
"ctrl_sides",
|
|
|
|
"ctrl_sides",
|
|
|
|
"ctrl_sides"
|
|
|
|
},
|
2020-03-04 16:46:22 +01:00
|
|
|
recipe = {
|
|
|
|
{ 1, {
|
|
|
|
{"default:steel_ingot", "microexpansion:steel_infused_obsidian_ingot", "default:steel_ingot"},
|
|
|
|
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot"},
|
|
|
|
{"default:steel_ingot", "microexpansion:cable", "default:steel_ingot"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 19:47:25 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
paramtype = "light",
|
2017-03-02 02:27:00 +01:00
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.375, -0.375, -0.375, 0.375, 0.375, 0.375}, -- Core
|
|
|
|
{0.1875, -0.5, -0.5, 0.5, 0.5, -0.1875}, -- Corner1
|
|
|
|
{-0.5, -0.5, -0.5, -0.1875, 0.5, -0.1875}, -- Corner2
|
|
|
|
{-0.5, -0.5, 0.1875, -0.1875, 0.5, 0.5}, -- Corner3
|
|
|
|
{0.1875, -0.5, 0.1875, 0.5, 0.5, 0.5}, -- Corner4
|
|
|
|
{-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, -- Bottom
|
|
|
|
{-0.5, 0.1875, -0.5, 0.5, 0.5, -0.1875}, -- Top1
|
|
|
|
{0.1875, 0.1875, -0.5, 0.5, 0.5, 0.5}, -- Top2
|
|
|
|
{-0.5, 0.1875, -0.5, -0.1875, 0.5, 0.5}, -- Top3
|
|
|
|
{-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- Top4
|
|
|
|
{-0.1875, -0.5, -0.1875, 0.1875, -0.25, 0.1875}, -- Bottom2
|
|
|
|
},
|
|
|
|
},
|
2017-07-25 19:47:25 +02:00
|
|
|
groups = { cracky = 1, me_connect = 1, },
|
|
|
|
connect_sides = "nobottom",
|
2020-03-07 18:02:14 +01:00
|
|
|
me_update = function(pos,_,ev)
|
2020-03-01 08:23:39 +01:00
|
|
|
local cnet = me.get_network(pos)
|
|
|
|
if cnet == nil then
|
|
|
|
minetest.log("error","no network for ctrl at pos "..minetest.pos_to_string(pos))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
cnet:update()
|
2020-03-07 18:02:14 +01:00
|
|
|
end,
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local net = network.new({controller_pos = pos})
|
|
|
|
table.insert(me.networks,net)
|
|
|
|
me.send_event(pos,"connect",{net=net})
|
|
|
|
|
|
|
|
meta:set_string("infotext", "Network Controller")
|
2020-03-01 08:23:39 +01:00
|
|
|
end,
|
2017-07-25 19:47:25 +02:00
|
|
|
after_place_node = function(pos, player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-05-04 13:53:49 +02:00
|
|
|
meta:set_string("infotext", "Network Controller (owned by "..name..")")
|
2017-07-25 19:47:25 +02:00
|
|
|
meta:set_string("owner", name)
|
|
|
|
end,
|
2019-05-18 07:37:46 +02:00
|
|
|
on_destruct = function(pos)
|
2020-03-07 18:02:14 +01:00
|
|
|
local net = me.get_network(pos)
|
|
|
|
local net,idx = me.get_network(pos)
|
|
|
|
--disconnect all those who need the network
|
|
|
|
me.send_event(pos,"disconnect",{net=net})
|
|
|
|
if net then
|
|
|
|
net:destruct()
|
|
|
|
end
|
|
|
|
if idx then
|
|
|
|
table.remove(me.networks,idx)
|
|
|
|
end
|
|
|
|
--disconnect all those that haven't realized the network is gone
|
|
|
|
me.send_event(pos,"disconnect")
|
2017-07-25 19:47:25 +02:00
|
|
|
end,
|
2020-03-07 18:02:14 +01:00
|
|
|
after_destruct = function(pos)
|
|
|
|
--disconnect all those that haven't realized the controller was disconnected
|
|
|
|
me.send_event(pos,"disconnect")
|
2019-05-07 17:49:26 +02:00
|
|
|
end,
|
2017-07-25 19:47:25 +02:00
|
|
|
machine = {
|
2020-03-07 18:02:14 +01:00
|
|
|
type = "controller",
|
2017-07-25 19:47:25 +02:00
|
|
|
},
|
2017-03-02 06:38:53 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
-- [register node] Cable
|
2017-07-25 19:47:25 +02:00
|
|
|
me.register_machine("cable", {
|
|
|
|
description = "ME Cable",
|
|
|
|
tiles = {
|
|
|
|
"cable",
|
|
|
|
},
|
2020-03-04 16:46:22 +01:00
|
|
|
recipe = {
|
|
|
|
{ 12, "shapeless", {
|
|
|
|
"microexpansion:steel_infused_obsidian_ingot", "microexpansion:machine_casing"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 19:47:25 +02:00
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "connected",
|
|
|
|
fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
2017-03-02 06:38:53 +01:00
|
|
|
connect_top = {-0.25, -0.25, -0.25, 0.25, 0.5, 0.25}, -- y+
|
|
|
|
connect_bottom = {-0.25, -0.5, -0.25, 0.25, 0.25, 0.25}, -- y-
|
|
|
|
connect_front = {-0.25, -0.25, -0.5, 0.25, 0.25, 0.25}, -- z-
|
|
|
|
connect_back = {-0.25, -0.25, 0.25, 0.25, 0.25, 0.5 }, -- z+
|
|
|
|
connect_left = {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, -- x-
|
|
|
|
connect_right = {-0.25, -0.25, -0.25, 0.5, 0.25, 0.25}, -- x+
|
2017-07-25 19:47:25 +02:00
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
groups = { crumbly = 1, },
|
2020-03-07 18:02:14 +01:00
|
|
|
--TODO: move these functions into the registration
|
|
|
|
on_construct = function(pos)
|
|
|
|
me.send_event(pos,"connect")
|
|
|
|
end,
|
|
|
|
after_destruct = function(pos)
|
|
|
|
me.send_event(pos,"disconnect")
|
|
|
|
end,
|
|
|
|
me_update = function(pos,_,ev)
|
|
|
|
if ev then
|
|
|
|
if ev.type ~= "disconnect" then return end
|
|
|
|
end
|
|
|
|
--maybe this shouldn't be called on every update
|
2020-03-01 08:23:39 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if me.get_connected_network(pos) then
|
|
|
|
meta:set_string("infotext", "Network connected")
|
|
|
|
else
|
|
|
|
meta:set_string("infotext", "No Network")
|
|
|
|
end
|
|
|
|
end,
|
2017-07-25 19:47:25 +02:00
|
|
|
machine = {
|
2020-03-07 18:02:14 +01:00
|
|
|
type = "conductor",
|
2017-07-25 19:47:25 +02:00
|
|
|
},
|
2017-03-02 02:27:00 +01:00
|
|
|
})
|