2018-04-08 14:11:39 +00:00
|
|
|
-- holostorage controller
|
2018-04-07 15:27:34 +00:00
|
|
|
|
2018-04-10 08:17:47 +00:00
|
|
|
local function get_formspec(list)
|
|
|
|
local tx = {}
|
|
|
|
for _,item in pairs(list) do
|
|
|
|
table.insert(tx, item[1].."x "..item[2])
|
|
|
|
end
|
|
|
|
|
|
|
|
local list = "textlist[0,0.5;7.8,3.5;devices;"..table.concat(tx, ",").."]"
|
|
|
|
|
|
|
|
return "size[8,8.5]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"label[0,0;Controller]"..
|
|
|
|
list..
|
|
|
|
"list[current_player;main;0,4.25;8,1;]"..
|
|
|
|
"list[current_player;main;0,5.5;8,3;8]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0, 4.25)
|
|
|
|
end
|
|
|
|
|
2018-04-08 14:11:39 +00:00
|
|
|
minetest.register_node("holostorage:controller", {
|
2018-04-07 15:27:34 +00:00
|
|
|
description = "Storage Controller",
|
2018-04-08 14:11:39 +00:00
|
|
|
tiles = {"holostorage_controller.png"},
|
2018-04-07 15:27:34 +00:00
|
|
|
on_construct = function (pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", "Storage Controller")
|
2018-04-10 08:17:47 +00:00
|
|
|
meta:set_string("formspec", get_formspec({}))
|
2018-04-07 15:27:34 +00:00
|
|
|
meta:set_string("active", 1)
|
|
|
|
meta:set_string("channel", "controller"..minetest.pos_to_string(pos))
|
2018-04-08 14:11:39 +00:00
|
|
|
minetest.swap_node(pos, {name="holostorage:controller_active"})
|
2018-04-07 15:27:34 +00:00
|
|
|
local poshash = minetest.hash_node_position(pos)
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage.network.redundant_warn[poshash] = nil
|
2018-04-07 15:27:34 +00:00
|
|
|
end,
|
|
|
|
after_dig_node = function(pos)
|
|
|
|
minetest.forceload_free_block(pos)
|
|
|
|
pos.y = pos.y - 1
|
|
|
|
minetest.forceload_free_block(pos)
|
|
|
|
local poshash = minetest.hash_node_position(pos)
|
|
|
|
technic.redundant_warn[poshash] = nil
|
|
|
|
end,
|
|
|
|
groups = {
|
|
|
|
cracky = 1,
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_controller = 1
|
2018-04-07 15:27:34 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-10 08:17:47 +00:00
|
|
|
local function compare(a,b)
|
|
|
|
return a[1] > b[1]
|
|
|
|
end
|
|
|
|
|
2018-04-08 14:11:39 +00:00
|
|
|
minetest.register_node("holostorage:controller_active", {
|
2018-04-07 15:27:34 +00:00
|
|
|
description = "Storage Controller",
|
|
|
|
tiles = {
|
|
|
|
{
|
2018-04-08 14:11:39 +00:00
|
|
|
name = "holostorage_controller_animated.png",
|
2018-04-07 15:27:34 +00:00
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 16,
|
|
|
|
aspect_h = 16,
|
|
|
|
length = 5.0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2018-04-08 14:25:50 +00:00
|
|
|
paramtype = "light",
|
|
|
|
light_source = 8,
|
2018-04-08 14:11:39 +00:00
|
|
|
drop = "holostorage:controller",
|
2018-04-10 08:17:47 +00:00
|
|
|
on_rightclick = function (pos, node, clicker, itemstack, pointed_thing)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local network_id = minetest.hash_node_position(pos)
|
|
|
|
local devices = {}
|
|
|
|
|
|
|
|
local network = holostorage.network.networks[network_id]
|
|
|
|
if network and network.all_nodes then
|
|
|
|
for _,pos in pairs(network.all_nodes) do
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local ndname = minetest.registered_nodes[node.name].description
|
|
|
|
if not devices[ndname] then
|
|
|
|
devices[ndname] = 0
|
|
|
|
end
|
|
|
|
devices[ndname] = devices[ndname] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local tfsort = {}
|
|
|
|
|
|
|
|
for name, count in pairs(devices) do
|
|
|
|
tfsort[#tfsort + 1] = {count, name}
|
|
|
|
end
|
|
|
|
|
|
|
|
table.sort(tfsort, compare)
|
|
|
|
|
|
|
|
meta:set_string("formspec", get_formspec(tfsort))
|
|
|
|
return itemstack
|
|
|
|
end,
|
2018-04-07 15:27:34 +00:00
|
|
|
groups = {
|
|
|
|
cracky = 1,
|
|
|
|
not_in_creative_inventory = 1,
|
2018-04-08 14:11:39 +00:00
|
|
|
holostorage_controller = 1
|
2018-04-07 15:27:34 +00:00
|
|
|
}
|
|
|
|
})
|