2018-03-10 22:14:57 +01:00
|
|
|
--[[
|
|
|
|
|
|
|
|
Tube Library
|
|
|
|
============
|
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
Copyright (C) 2017-2020 Joachim Stolberg
|
2018-03-10 22:14:57 +01:00
|
|
|
|
2020-11-20 14:45:28 +01:00
|
|
|
AGPL v3
|
2018-03-10 22:14:57 +01:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
lamp.lua:
|
2022-06-09 23:49:50 +02:00
|
|
|
|
2018-03-10 22:14:57 +01:00
|
|
|
Example of a simple communication node, only receiving messages from others.
|
|
|
|
This node claims a position number and registers its message interface.
|
|
|
|
The Lamp supports the following messages:
|
|
|
|
- topic = "on", payload = nil
|
|
|
|
- topic = "off" , payload = nil
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
2020-11-03 20:19:38 +01:00
|
|
|
-- Load support for I18n
|
|
|
|
local S = tubelib.S
|
|
|
|
|
2018-03-10 22:14:57 +01:00
|
|
|
local function switch_on(pos, node)
|
|
|
|
node.name = "tubelib:lamp_on"
|
|
|
|
minetest.swap_node(pos, node)
|
2022-06-09 23:49:50 +02:00
|
|
|
end
|
2018-03-10 22:14:57 +01:00
|
|
|
|
|
|
|
local function switch_off(pos, node)
|
|
|
|
node.name = "tubelib:lamp"
|
|
|
|
minetest.swap_node(pos, node)
|
2022-06-09 23:49:50 +02:00
|
|
|
end
|
2018-03-10 22:14:57 +01:00
|
|
|
|
|
|
|
minetest.register_node("tubelib:lamp", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Lamp"),
|
2018-03-10 22:14:57 +01:00
|
|
|
tiles = {
|
|
|
|
'tubelib_lamp.png',
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
2018-03-31 19:03:53 +02:00
|
|
|
local number = tubelib.add_node(pos, "tubelib:lamp") -- <<=== tubelib
|
2018-03-10 22:14:57 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2020-11-03 20:19:38 +01:00
|
|
|
meta:set_string("infotext", S("Tubelib Lamp").." "..number)
|
2018-03-10 22:14:57 +01: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) -- <<=== tubelib
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
2022-06-09 23:49:50 +02:00
|
|
|
light_source = 0,
|
2018-03-10 22:14:57 +01:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2022-06-09 23:49:50 +02:00
|
|
|
on_blast = function() end,
|
2018-03-10 22:14:57 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("tubelib:lamp_on", {
|
2020-11-03 20:19:38 +01:00
|
|
|
description = S("Tubelib Lamp"),
|
2018-03-10 22:14:57 +01:00
|
|
|
tiles = {
|
|
|
|
'tubelib_lamp.png',
|
|
|
|
},
|
|
|
|
|
|
|
|
on_rightclick = function(pos, node, clicker)
|
|
|
|
if not minetest.is_protected(pos, clicker:get_player_name()) then
|
|
|
|
switch_off(pos, node)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
paramtype = "light",
|
2022-06-09 23:49:50 +02:00
|
|
|
light_source = minetest.LIGHT_MAX,
|
2018-03-10 22:14:57 +01:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {crumbly=0, not_in_creative_inventory=1},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2022-06-09 23:49:50 +02:00
|
|
|
on_blast = function() end,
|
2018-03-10 22:14:57 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "tubelib:lamp 4",
|
|
|
|
recipe = {
|
|
|
|
{"wool:white", "wool:white", "wool:white"},
|
|
|
|
{"tubelib:wlanchip", "default:coal_lump", ""},
|
|
|
|
{"group:wood", "", "group:wood"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
--------------------------------------------------------------- tubelib
|
|
|
|
tubelib.register_node("tubelib:lamp", {"tubelib:lamp_on"}, {
|
|
|
|
on_pull_item = nil, -- lamp has no inventory
|
|
|
|
on_push_item = nil, -- lamp has no inventory
|
|
|
|
on_unpull_item = nil, -- lamp has no inventory
|
|
|
|
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,
|
2022-06-09 23:49:50 +02:00
|
|
|
})
|
2018-03-10 22:14:57 +01:00
|
|
|
--------------------------------------------------------------- tubelib
|