techpack/tubelib_addons2/invisiblelamp.lua

108 lines
2.7 KiB
Lua
Raw Normal View History

2018-08-16 21:16:34 +02:00
--[[
Tubelib Addons 2
================
Copyright (C) 2017-2020 Joachim Stolberg
2018-08-16 21:16:34 +02:00
AGPL v3
2018-08-16 21:16:34 +02:00
See LICENSE.txt for more information
invisiblelamp.lua:
2018-08-16 21:16:34 +02:00
]]--
-- Load support for I18n
local S = tubelib_addons2.S
2018-08-16 21:16:34 +02:00
local function switch_on(pos, node)
node.name = "tubelib_addons2:invisiblelamp_on"
minetest.swap_node(pos, node)
end
2018-08-16 21:16:34 +02:00
local function switch_off(pos, node)
node.name = "tubelib_addons2:invisiblelamp"
minetest.swap_node(pos, node)
local pos1 = {x=pos.x-5, y=pos.y-5, z=pos.z-5}
local pos2 = {x=pos.x+5, y=pos.y+5, z=pos.z+5}
minetest.fix_light(pos1, pos2)
end
2018-08-16 21:16:34 +02:00
minetest.register_node("tubelib_addons2:invisiblelamp", {
description = S("Tubelib Invisible Lamp"),
2018-08-16 21:16:34 +02:00
drawtype = "glasslike_framed_optional",
tiles = {"tubelib_addons2_invisiblelamp.png"},
inventory_image = 'tubelib_addons2_invisiblelamp_inventory.png',
2018-08-16 21:16:34 +02:00
after_place_node = function(pos, placer)
local number = tubelib.add_node(pos, "tubelib_addons2:invisiblelamp")
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Tubelib Invisible Lamp").." "..number)
2018-08-16 21:16:34 +02:00
end,
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
switch_on(pos, node)
end
end,
after_dig_node = function(pos)
tubelib.remove_node(pos)
end,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
walkable = false,
is_ground_content = false,
groups = {cracky = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
on_blast = function() end,
2018-08-16 21:16:34 +02:00
})
minetest.register_node("tubelib_addons2:invisiblelamp_on", {
description = S("Tubelib Invisible Lamp"),
2018-08-16 21:16:34 +02:00
drawtype = "glasslike_framed_optional",
tiles = {"tubelib_addons2_invisiblelamp.png"},
2018-08-16 21:16:34 +02:00
on_rightclick = function(pos, node, clicker)
if not minetest.is_protected(pos, clicker:get_player_name()) then
switch_off(pos, node)
end
end,
after_dig_node = function(pos)
tubelib.remove_node(pos)
end,
2018-08-16 21:16:34 +02:00
paramtype = "light",
light_source = minetest.LIGHT_MAX,
sunlight_propagates = true,
walkable = false,
is_ground_content = false,
drop = "tubelib_addons2:invisiblelamp",
groups = {cracky = 3, oddly_breakable_by_hand = 3, not_in_creative_inventory=1},
sounds = default.node_sound_glass_defaults(),
on_blast = function() end,
2018-08-16 21:16:34 +02:00
})
minetest.register_craft({
output = "tubelib_addons2:invisiblelamp 2",
recipe = {
{"", "default:torch", ""},
{"default:torch", "tubelib:wlanchip", "default:torch"},
{"", "default:torch", ""},
}
})
tubelib.register_node("tubelib_addons2:invisiblelamp", {"tubelib_addons2:invisiblelamp_on"}, {
on_recv_message = function(pos, topic, payload)
local node = minetest.get_node(pos)
if topic == "on" then
switch_on(pos, node)
elseif topic == "off" then
switch_off(pos, node)
end
end,
})