2020-01-26 01:22:06 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
Copyright (C) 2019-2021 Joachim Stolberg
|
2020-01-26 01:22:06 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2020-01-26 01:22:06 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-01-26 01:22:06 +03:00
|
|
|
TA3 Power Switch Box
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local S2P = minetest.string_to_pos
|
|
|
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
|
|
|
local M = minetest.get_meta
|
2021-06-06 16:53:19 +03:00
|
|
|
local N = techage.get_node_lvm
|
2020-01-26 01:22:06 +03:00
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local Cable = techage.ElectricCable
|
2021-06-05 12:42:30 +03:00
|
|
|
local power = networks.power
|
2020-01-26 01:22:06 +03:00
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
local node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{ -1/4, -1/4, -2/4, 1/4, 1/4, 2/4},
|
2020-01-26 01:22:06 +03:00
|
|
|
},
|
2021-06-05 12:42:30 +03:00
|
|
|
}
|
2020-01-26 01:22:06 +03:00
|
|
|
|
2021-06-06 16:53:19 +03:00
|
|
|
function techage.legacy_switches(pos)
|
|
|
|
local meta = M(pos)
|
|
|
|
local node = N(pos)
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2021-06-06 16:53:19 +03:00
|
|
|
if node.name == "techage:powerswitch_box" then
|
|
|
|
if meta:get_int("netw_param2") == 0 then
|
|
|
|
node.name = "techage:powerswitch_box_off"
|
|
|
|
else
|
|
|
|
node.name = "techage:powerswitch_box_on"
|
|
|
|
end
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
elseif meta:get_string("netw_name") == "techage:powerswitch_box" then
|
|
|
|
if meta:get_int("netw_param2") == 0 then
|
|
|
|
meta:set_string("netw_name", "techage:powerswitch_box_off")
|
|
|
|
else
|
|
|
|
meta:set_string("netw_name", "techage:powerswitch_box_on")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if meta:contains("tl2_param2_copy") then
|
|
|
|
meta:set_string("netw_param2_copy", meta:get_string("tl2_param2_copy"))
|
|
|
|
meta:set_string("tl2_param2_copy", "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
-- The on-switch is a "primary node" like cables
|
|
|
|
minetest.register_node("techage:powerswitch_box_on", {
|
|
|
|
description = S("TA Power Switch Box"),
|
|
|
|
paramtype = "light",
|
2020-01-26 01:22:06 +03:00
|
|
|
drawtype = "nodebox",
|
2021-06-05 12:42:30 +03:00
|
|
|
node_box = node_box,
|
|
|
|
tiles = {
|
|
|
|
"techage_electric_switch.png^[transformR90",
|
|
|
|
"techage_electric_switch.png^[transformR90",
|
|
|
|
"techage_electric_switch.png",
|
|
|
|
"techage_electric_switch.png",
|
|
|
|
"techage_electric_junction.png",
|
|
|
|
"techage_electric_junction.png",
|
2020-01-26 01:22:06 +03:00
|
|
|
},
|
2020-01-26 22:15:40 +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
|
2020-01-26 01:22:06 +03:00
|
|
|
end,
|
2021-06-05 12:42:30 +03:00
|
|
|
on_rightclick = function(pos, node, clicker)
|
2021-06-06 16:53:19 +03:00
|
|
|
techage.legacy_switches(pos)
|
2021-07-19 21:37:31 +03:00
|
|
|
if M(pos):get_int("switch_sign_in") ~= 1 then
|
|
|
|
if power.turn_switch_off(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then
|
|
|
|
minetest.sound_play("doors_glass_door_open", {
|
2022-01-03 23:40:31 +03:00
|
|
|
pos = pos,
|
2021-07-19 21:37:31 +03:00
|
|
|
gain = 1,
|
|
|
|
max_hear_distance = 5})
|
|
|
|
end
|
2021-06-05 12:42:30 +03:00
|
|
|
end
|
|
|
|
end,
|
2020-01-26 22:15:40 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
|
|
|
end,
|
2020-01-26 01:22:06 +03:00
|
|
|
paramtype2 = "facedir",
|
2021-06-05 12:42:30 +03:00
|
|
|
on_rotate = screwdriver.disallow,
|
2021-07-29 22:08:44 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2021-06-05 12:42:30 +03:00
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = false,
|
2020-01-26 01:22:06 +03:00
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1},
|
2021-06-05 12:42:30 +03:00
|
|
|
sounds = default.node_sound_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- The off-switch is a "secondary node" without connection sides
|
|
|
|
minetest.register_node("techage:powerswitch_box_off", {
|
|
|
|
description = S("TA Power Switch Box"),
|
|
|
|
paramtype = "light",
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = node_box,
|
|
|
|
tiles = {
|
|
|
|
"techage_electric_switch_off.png^[transformR90",
|
|
|
|
"techage_electric_switch_off.png^[transformR90",
|
|
|
|
"techage_electric_switch_off.png",
|
|
|
|
"techage_electric_switch_off.png",
|
|
|
|
"techage_electric_junction.png",
|
|
|
|
"techage_electric_junction.png",
|
|
|
|
},
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
2021-06-06 16:53:19 +03:00
|
|
|
techage.legacy_switches(pos)
|
2021-07-19 21:37:31 +03:00
|
|
|
if M(pos):get_int("switch_sign_in") ~= 1 then
|
|
|
|
if power.turn_switch_on(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then
|
|
|
|
minetest.sound_play("doors_glass_door_open", {
|
2022-01-03 23:40:31 +03:00
|
|
|
pos = pos,
|
2021-07-19 21:37:31 +03:00
|
|
|
gain = 1,
|
|
|
|
max_hear_distance = 5})
|
|
|
|
end
|
2021-06-05 12:42:30 +03:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Cable:after_dig_node(pos)
|
|
|
|
end,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
on_rotate = screwdriver.disallow,
|
2021-07-29 22:08:44 +03:00
|
|
|
use_texture_alpha = techage.CLIP,
|
2021-06-05 12:42:30 +03:00
|
|
|
sunlight_propagates = true,
|
2020-01-26 01:22:06 +03:00
|
|
|
is_ground_content = false,
|
2021-06-05 12:42:30 +03:00
|
|
|
drop = "techage:powerswitch_box_on",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1, not_in_creative_inventory = 1},
|
|
|
|
sounds = default.node_sound_defaults(),
|
2020-01-26 01:22:06 +03:00
|
|
|
})
|
|
|
|
|
2021-06-05 12:42:30 +03:00
|
|
|
power.register_nodes({"techage:powerswitch_box_off"}, Cable, "con", {})
|
|
|
|
|
2020-01-26 22:15:40 +03:00
|
|
|
minetest.register_craft({
|
2021-06-05 12:42:30 +03:00
|
|
|
output = "techage:powerswitch_box_on",
|
2020-01-26 22:15:40 +03:00
|
|
|
recipe = {
|
|
|
|
{"", "basic_materials:plastic_sheet", ""},
|
|
|
|
{"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"},
|
|
|
|
{"", "basic_materials:plastic_sheet", ""},
|
|
|
|
},
|
2022-01-04 21:40:27 +03:00
|
|
|
})
|