2013-07-17 21:34:35 +02:00
|
|
|
|
2013-10-30 18:45:32 +01:00
|
|
|
local S = technic.getter
|
2013-07-17 21:34:35 +02:00
|
|
|
|
2016-03-20 02:34:56 +01:00
|
|
|
local cable_tier = {}
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
function technic.is_tier_cable(name, tier)
|
2016-03-20 02:34:56 +01:00
|
|
|
return cable_tier[name] == tier
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function technic.get_cable_tier(name)
|
2016-03-20 02:34:56 +01:00
|
|
|
return cable_tier[name]
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
2017-03-05 11:09:23 +01:00
|
|
|
local function clear_networks(pos)
|
|
|
|
local positions = {
|
|
|
|
{x=pos.x+1, y=pos.y, z=pos.z},
|
|
|
|
{x=pos.x-1, y=pos.y, z=pos.z},
|
|
|
|
{x=pos.x, y=pos.y+1, z=pos.z},
|
|
|
|
{x=pos.x, y=pos.y-1, z=pos.z},
|
|
|
|
{x=pos.x, y=pos.y, z=pos.z+1},
|
|
|
|
{x=pos.x, y=pos.y, z=pos.z-1}}
|
|
|
|
for _,connected_pos in pairs(positions) do
|
2017-03-10 08:19:36 +01:00
|
|
|
local net = technic.cables[minetest.hash_node_position(connected_pos)]
|
|
|
|
if net and technic.networks[net] then
|
|
|
|
for _,v in pairs(technic.networks[net].all_nodes) do
|
|
|
|
local pos1 = minetest.hash_node_position(v)
|
|
|
|
technic.cables[pos1] = nil
|
|
|
|
end
|
|
|
|
technic.networks[net] = nil
|
2017-03-05 11:09:23 +01:00
|
|
|
end
|
|
|
|
end
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
|
2016-03-20 02:34:56 +01:00
|
|
|
function technic.register_cable(tier, size)
|
|
|
|
local ltier = string.lower(tier)
|
|
|
|
cable_tier["technic:"..ltier.."_cable"] = tier
|
|
|
|
|
|
|
|
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}
|
|
|
|
|
|
|
|
local node_box = {
|
|
|
|
type = "connected",
|
|
|
|
fixed = {-size, -size, -size, size, size, size},
|
|
|
|
connect_top = {-size, -size, -size, size, 0.5, size}, -- y+
|
|
|
|
connect_bottom = {-size, -0.5, -size, size, size, size}, -- y-
|
|
|
|
connect_front = {-size, -size, -0.5, size, size, size}, -- z-
|
|
|
|
connect_back = {-size, -size, size, size, size, 0.5 }, -- z+
|
|
|
|
connect_left = {-0.5, -size, -size, size, size, size}, -- x-
|
|
|
|
connect_right = {-size, -size, -size, 0.5, size, size}, -- x+
|
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node("technic:"..ltier.."_cable", {
|
|
|
|
description = S("%s Cable"):format(tier),
|
|
|
|
tiles = {"technic_"..ltier.."_cable.png"},
|
|
|
|
inventory_image = "technic_"..ltier.."_cable_wield.png",
|
|
|
|
wield_image = "technic_"..ltier.."_cable_wield.png",
|
|
|
|
groups = groups,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
drop = "technic:"..ltier.."_cable",
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = node_box,
|
|
|
|
connects_to = {"technic:"..ltier.."_cable",
|
|
|
|
"group:technic_"..ltier, "group:technic_all_tiers"},
|
|
|
|
on_construct = clear_networks,
|
|
|
|
on_destruct = clear_networks,
|
|
|
|
})
|
|
|
|
end
|
2013-07-17 21:34:35 +02:00
|
|
|
|
|
|
|
|
2016-03-20 02:34:56 +01:00
|
|
|
local function clear_nets_if_machine(pos, node)
|
|
|
|
for tier, machine_list in pairs(technic.machines) do
|
|
|
|
if machine_list[node.name] ~= nil then
|
2017-03-05 11:09:23 +01:00
|
|
|
return clear_networks(pos)
|
2016-03-20 02:34:56 +01:00
|
|
|
end
|
2013-07-17 21:34:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-20 02:34:56 +01:00
|
|
|
minetest.register_on_placenode(clear_nets_if_machine)
|
|
|
|
minetest.register_on_dignode(clear_nets_if_machine)
|
|
|
|
|