nixie_tubes/init.lua

102 lines
2.2 KiB
Lua
Raw Normal View History

2015-06-09 21:41:51 +02:00
-- simple nixie tubes mod
-- by Vanessa Ezekowitz
nixie_tubes = {}
local S
if minetest.get_modpath("intllib") then
S = intllib.Getter()
else
S = function(s) return s end
end
local nixie_types = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
"colon",
"period",
"off"
}
local tube_cbox = {
type = "fixed",
2015-06-10 20:48:30 +02:00
fixed = { -11/32, -8/16, -11/32, 11/32, 8/16, 11/32 }
2015-06-09 21:41:51 +02:00
}
-- the following functions based on the so-named ones in Jeija's digilines mod
local reset_meta = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]")
end
local on_digiline_receive = function(pos, node, channel, msg)
local meta = minetest.get_meta(pos)
local setchan = meta:get_string("channel")
if setchan ~= channel then return end
2015-06-10 19:54:13 +02:00
local num = tonumber(msg)
if msg == "colon" or msg == "period" or msg == "off" or (num and (num >= 0 and num <= 9)) then
2015-06-09 21:41:51 +02:00
minetest.swap_node(pos, { name = "nixie_tubes:tube_"..msg, param2 = node.param2})
end
end
-- the nodes:
for _,tube in ipairs(nixie_types) do
local groups = { cracky = 2, not_in_creative_inventory = 1}
local light = LIGHT_MAX-4
2015-06-09 22:00:43 +02:00
local description = S("Nixie Tube ("..tube..")")
local cathode = "nixie_tube_cathode_off.png^nixie_tube_cathode_"..tube..".png"
2015-06-09 21:41:51 +02:00
if tube == "off" then
groups = {cracky = 2}
light = nil
2015-06-09 22:00:43 +02:00
description = S("Nixie Tube")
cathode = "nixie_tube_cathode_off.png"
2015-06-09 21:41:51 +02:00
end
minetest.register_node("nixie_tubes:tube_"..tube, {
2015-06-09 22:00:43 +02:00
description = description,
2015-06-09 21:41:51 +02:00
drawtype = "mesh",
mesh = "nixie_tube.obj",
tiles = {
"nixie_tube_base.png",
"nixie_tube_backing.png",
cathode,
2015-06-09 21:41:51 +02:00
"nixie_tube_anode.png",
"nixie_tube_glass.png",
},
use_texture_alpha = true,
groups = groups,
paramtype = "light",
paramtype2 = "facedir",
light_source = light,
selection_box = tube_cbox,
collision_box = tube_cbox,
on_construct = function(pos)
reset_meta(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
if (fields.channel) then
minetest.get_meta(pos):set_string("channel", fields.channel)
end
end,
digiline = {
receptor = {},
effector = {
action = on_digiline_receive
},
},
2015-06-09 22:00:43 +02:00
drop = "nixie_tubes:tube_off"
2015-06-09 21:41:51 +02:00
})
end