2019-03-02 14:24:48 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-03-02 14:24:48 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
TA3 Electric Cables (AC)
|
2019-03-02 14:24:48 +03:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
2019-07-13 00:27:29 +03:00
|
|
|
local S2P = minetest.string_to_pos
|
|
|
|
local P2S = minetest.pos_to_string
|
2019-03-02 14:24:48 +03:00
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
local power = networks.power
|
2020-01-26 22:15:40 +03:00
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
local ELE1_MAX_CABLE_LENGHT = 1000
|
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
local Cable = tubelib2.Tube:new({
|
|
|
|
dirs_to_check = {1,2,3,4,5,6},
|
2022-01-03 23:40:31 +03:00
|
|
|
max_tube_length = ELE1_MAX_CABLE_LENGHT,
|
2019-03-02 14:24:48 +03:00
|
|
|
show_infotext = false,
|
2020-01-26 01:15:44 +03:00
|
|
|
tube_type = "ele1",
|
|
|
|
primary_node_names = {"techage:electric_cableS", "techage:electric_cableA",
|
2022-01-03 23:40:31 +03:00
|
|
|
"techage:power_line", "techage:power_lineS", "techage:power_lineA",
|
2021-06-05 12:42:30 +03:00
|
|
|
"techage:power_pole2", "techage:powerswitch_box", "techage:powerswitch_box_on"},
|
2019-05-11 02:21:03 +03:00
|
|
|
secondary_node_names = {},
|
2019-03-02 14:24:48 +03:00
|
|
|
after_place_tube = function(pos, param2, tube_type, num_tubes)
|
2021-09-08 14:02:11 +03:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local name = node.name
|
|
|
|
local color_param2 = math.floor(node.param2 / 32) * 32
|
2021-06-05 23:52:31 +03:00
|
|
|
if name == "techage:powerswitch_box" or name == "techage:powerswitch_box_on" or name == "techage:powerswitch_box_off" then
|
|
|
|
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
|
|
|
elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then
|
|
|
|
minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32})
|
2021-06-09 23:09:59 +03:00
|
|
|
elseif name == "techage:power_pole2" then
|
|
|
|
-- nothing
|
2021-06-05 23:52:31 +03:00
|
|
|
elseif not networks.hidden_name(pos) then
|
2021-09-08 14:02:11 +03:00
|
|
|
minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32 + color_param2})
|
2019-06-22 00:04:27 +03:00
|
|
|
end
|
2021-06-05 23:52:31 +03:00
|
|
|
M(pos):set_int("netw_param2", param2)
|
2021-09-08 14:02:11 +03:00
|
|
|
M(pos):set_int("netw_color_param2", color_param2)
|
2019-03-02 14:24:48 +03:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
-- Enable hidden cables
|
|
|
|
networks.use_metadata(Cable)
|
2021-06-09 23:09:59 +03:00
|
|
|
networks.register_hidden_message("Use the trowel tool to remove the node.")
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
-- Use global callback instead of node related functions
|
|
|
|
Cable:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
|
|
|
power.update_network(pos, outdir, tlib2, node)
|
|
|
|
end)
|
2019-03-02 14:24:48 +03:00
|
|
|
|
2021-09-08 14:02:11 +03:00
|
|
|
local preserve_metadata = function(pos, oldnode, oldmeta, drops)
|
|
|
|
for _,drop in ipairs(drops) do
|
|
|
|
local meta = drop:get_meta()
|
|
|
|
if meta:get_int("palette_index") == 0 then
|
|
|
|
meta:set_string("palette_index", "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
minetest.register_node("techage:electric_cableS", {
|
2019-07-02 22:33:12 +03:00
|
|
|
description = S("TA Electric Cable"),
|
2019-03-02 14:24:48 +03:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
2021-09-08 14:02:11 +03:00
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
},
|
|
|
|
overlay_tiles = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
{ name = "techage_electric_cable_end.png", color = "white" },
|
|
|
|
{ name = "techage_electric_cable_end.png", color = "white" },
|
2019-03-02 14:24:48 +03:00
|
|
|
},
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
|
|
|
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2021-06-05 23:52:31 +03:00
|
|
|
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
2019-03-02 14:24:48 +03:00
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-09-08 14:02:11 +03:00
|
|
|
paramtype2 = "colorfacedir", -- important!
|
|
|
|
palette = "techage_cable_palette.png",
|
2019-03-02 14:24:48 +03:00
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-3/32, -3/32, -4/8, 3/32, 3/32, 4/8},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on_rotate = screwdriver.disallow, -- important!
|
|
|
|
paramtype = "light",
|
2021-03-19 22:06:22 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2019-03-02 14:24:48 +03:00
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = false,
|
|
|
|
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
|
|
|
|
sounds = default.node_sound_defaults(),
|
2021-09-08 14:02:11 +03:00
|
|
|
preserve_metadata = preserve_metadata,
|
2019-03-02 14:24:48 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("techage:electric_cableA", {
|
2019-07-02 22:33:12 +03:00
|
|
|
description = S("TA Electric Cable"),
|
2019-03-02 14:24:48 +03:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
2021-09-08 14:02:11 +03:00
|
|
|
"techage_electric_cable.png",
|
|
|
|
"techage_electric_cable.png",
|
|
|
|
},
|
|
|
|
overlay_tiles = {
|
|
|
|
"",
|
|
|
|
{ name = "techage_electric_cable_end.png", color = "white" },
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
{ name = "techage_electric_cable_end.png", color = "white" },
|
2019-03-02 14:24:48 +03:00
|
|
|
},
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-03-02 14:24:48 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2021-06-05 23:52:31 +03:00
|
|
|
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
2019-03-02 14:24:48 +03:00
|
|
|
end,
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-09-08 14:02:11 +03:00
|
|
|
paramtype2 = "colorfacedir", -- important!
|
|
|
|
palette = "techage_cable_palette.png",
|
2019-03-02 14:24:48 +03:00
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-3/32, -4/8, -3/32, 3/32, 3/32, 3/32},
|
|
|
|
{-3/32, -3/32, -4/8, 3/32, 3/32, -3/32},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
on_rotate = screwdriver.disallow, -- important!
|
|
|
|
paramtype = "light",
|
2021-03-19 22:06:22 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2019-03-02 14:24:48 +03:00
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = false,
|
2022-01-03 23:40:31 +03:00
|
|
|
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3,
|
2019-04-28 22:34:21 +03:00
|
|
|
techage_trowel = 1, not_in_creative_inventory = 1},
|
2019-03-02 14:24:48 +03:00
|
|
|
sounds = default.node_sound_defaults(),
|
2021-09-08 14:02:11 +03:00
|
|
|
drop = {
|
|
|
|
items = {
|
|
|
|
{ items = { "techage:electric_cableS" }, inherit_color = true },
|
|
|
|
}
|
|
|
|
},
|
|
|
|
preserve_metadata = preserve_metadata,
|
2019-03-02 14:24:48 +03:00
|
|
|
})
|
|
|
|
|
2019-05-11 02:21:03 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:electric_cableS 6",
|
|
|
|
recipe = {
|
|
|
|
{"basic_materials:plastic_sheet", "", ""},
|
|
|
|
{"", "default:copper_ingot", ""},
|
|
|
|
{"", "", "basic_materials:plastic_sheet"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-01-26 01:15:44 +03:00
|
|
|
techage.ElectricCable = Cable
|
2021-10-01 15:26:17 +03:00
|
|
|
techage.ELE1_MAX_CABLE_LENGTH = ELE1_MAX_CABLE_LENGHT
|
2021-09-08 14:02:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
for idx, color in ipairs({ "white", "grey", "black", "brown", "yellow", "red", "dark_green", "blue" }) do
|
|
|
|
minetest.register_craft({
|
|
|
|
output = idx == 1 and "techage:electric_cableS 8" or minetest.itemstring_with_palette("techage:electric_cableS 8", (idx-1)*32),
|
|
|
|
recipe = {
|
|
|
|
{ "techage:electric_cableS", "techage:electric_cableS", "techage:electric_cableS", },
|
|
|
|
{ "techage:electric_cableS", "dye:"..color, "techage:electric_cableS", },
|
|
|
|
{ "techage:electric_cableS", "techage:electric_cableS", "techage:electric_cableS", },
|
|
|
|
}
|
|
|
|
})
|
2022-01-04 21:40:27 +03:00
|
|
|
end
|