techage/logic/signallamp.lua

134 lines
3.4 KiB
Lua
Raw Normal View History

2019-08-24 11:28:58 +03:00
--[[
TechAge
=======
2020-01-31 21:55:10 +03:00
Copyright (C) 2020 Joachim Stolberg
2019-08-24 11:28:58 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2019-08-24 11:28:58 +03:00
See LICENSE.txt for more information
Colored Signal Lamp (requires unifieddyes)
2022-01-03 23:40:31 +03:00
2019-08-24 11:28:58 +03:00
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
local logic = techage.logic
2019-08-25 22:16:42 +03:00
local COLORED = minetest.get_modpath("unifieddyes") and minetest.global_exists("unifieddyes")
2019-08-24 11:28:58 +03:00
local function switch_on(pos, node)
node.name = "techage:signal_lamp_on"
minetest.swap_node(pos, node)
2022-01-03 23:40:31 +03:00
end
2019-08-24 11:28:58 +03:00
local function switch_off(pos, node)
node.name = "techage:signal_lamp_off"
minetest.swap_node(pos, node)
2022-01-03 23:40:31 +03:00
end
2019-08-24 11:28:58 +03:00
minetest.register_node("techage:signal_lamp_off", {
description = S("TechAge Signal Lamp (can be colored)"),
2019-08-24 11:28:58 +03:00
tiles = {"techage_signal_lamp.png^[colorize:#000000:100"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-6/16, -6/16, -6/16, 6/16, 6/16, 6/16},
{-4/16, -10/16, -4/16, 4/16, -6/16, 4/16},
},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
logic.after_place_node(pos, placer, "techage:signal_lamp_off", S("TechAge Signal Lamp"))
logic.infotext(M(pos), S("TechAge Signal Lamp"))
2019-08-24 11:28:58 +03:00
if COLORED then
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end
end,
on_rightclick = switch_on,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
2020-06-14 00:32:00 +03:00
techage.remove_node(pos, oldnode, oldmetadata)
2019-08-24 11:28:58 +03:00
if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end
end,
2019-08-26 23:19:59 +03:00
on_construct = COLORED and unifieddyes.on_construct or nil,
on_dig = COLORED and unifieddyes.on_dig or nil,
2022-01-03 23:40:31 +03:00
2019-08-24 11:28:58 +03:00
paramtype = "light",
paramtype2 = "color",
palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png',
2019-08-24 11:28:58 +03:00
place_param2 = 241,
sunlight_propagates = true,
sounds = default.node_sound_stone_defaults(),
groups = {choppy=2, cracky=1, ud_param2_colorable = 1},
is_ground_content = false,
drop = "techage:signal_lamp_off"
})
minetest.register_node("techage:signal_lamp_on", {
description = S("TechAge Signal Lamp"),
2019-08-24 11:28:58 +03:00
tiles = {"techage_signal_lamp.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-6/16, -6/16, -6/16, 6/16, 6/16, 6/16},
{-4/16, -10/16, -4/16, 4/16, -6/16, 4/16},
},
},
on_rightclick = switch_off,
paramtype = "light",
paramtype2 = "color",
palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png',
2019-08-24 11:28:58 +03:00
groups = {choppy=2, cracky=1, not_in_creative_inventory=1, ud_param2_colorable = 1},
2022-01-03 23:40:31 +03:00
2019-08-26 23:19:59 +03:00
on_construct = COLORED and unifieddyes.on_construct or nil,
after_place_node = COLORED and unifieddyes.recolor_on_place or nil,
2022-01-03 23:40:31 +03:00
2019-08-24 11:28:58 +03:00
after_dig_node = function(pos, oldnode, oldmetadata, digger)
2020-06-14 00:32:00 +03:00
techage.remove_node(pos, oldnode, oldmetadata)
2019-08-24 11:28:58 +03:00
if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end
end,
2022-01-03 23:40:31 +03:00
2019-08-26 23:19:59 +03:00
on_dig = COLORED and unifieddyes.on_dig or nil,
2022-01-03 23:40:31 +03:00
light_source = 10,
2019-08-24 11:28:58 +03:00
is_ground_content = false,
drop = "techage:signal_lamp_off"
})
techage.register_node({"techage:signal_lamp_off", "techage:signal_lamp_on"}, {
on_recv_message = function(pos, src, topic, payload)
2019-08-24 11:28:58 +03:00
if topic == "on" then
local node = techage.get_node_lvm(pos)
2019-08-24 11:28:58 +03:00
switch_on(pos, node)
elseif topic == "off" then
local node = techage.get_node_lvm(pos)
2019-08-24 11:28:58 +03:00
switch_off(pos, node)
2019-08-29 22:43:00 +03:00
else
return "unsupported"
2019-08-24 11:28:58 +03:00
end
end,
2022-01-03 23:40:31 +03:00
})
2019-08-24 11:28:58 +03:00
minetest.register_craft({
output = "techage:signal_lamp_off",
recipe = {
{"", "wool:white", ""},
{"", "default:torch", ""},
{"", "techage:vacuum_tube", ""},
},
})