First working version of the multicolour light.

master
Pedro Gimeno 2017-12-21 00:11:24 +01:00
commit 85081ca776
5 changed files with 104 additions and 0 deletions

1
depends.txt Normal file
View File

@ -0,0 +1 @@
digilines

103
init.lua Normal file
View File

@ -0,0 +1,103 @@
-- Copyright © 2017 Pedro Gimeno Fortea.
local function multicolour_light_on_punch(pos, node, puncher, pointed_thing)
local channel = minetest.get_meta(pos):get_string("digich")
if channel == "" then
return
end
digiline:receptor_send(pos, digiline.rules.default, channel, "punch")
end
local function multicolour_light_on_rightclick(pos, node, clicker, itemstack,
pointed_thing)
local channel = minetest.get_meta(pos):get_string("digich")
if channel == "" then
return
end
digiline:receptor_send(pos, digiline.rules.default, channel, "action")
end
local function multicolour_light_on_construct(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[channel;Digiline Channel;]")
end
local function multicolour_light_on_receive_fields(pos, formname, fields, sender)
if fields.channel and fields.channel ~= "" then
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "")
meta:set_string("digich", fields.channel)
end
end
local function multicolour_light_effector_action(pos, node, channel, msg)
local configured_channel = minetest.get_meta(pos):get_string("digich")
if channel == configured_channel then
-- quick test
local node = minetest.get_node(pos)
local onoff,colour = msg:match("^([^#]+)#?(%x-)$")
if onoff == "off" and node.name == "digiplay:multicolour_light_on" then
node.name = "digiplay:multicolour_light"
elseif onoff == "on" and node.name == "digiplay:multicolour_light" then
node.name = "digiplay:multicolour_light_on"
end
if colour ~= "" then
local base
if colour:match("^%x%x%x%x%x%x$") then
base = 256
elseif colour:match("^%x%x%x$") then
base = 16
end
if base then
local r = tonumber(colour, 16)
local b = r % base
r = (r - b) / base
local g = r % base
r = (r - g) / base
node.param2 = math.floor(g*5/base)*25 + math.floor(r*5/base)*5 + math.floor(b*5/base) + 1
if node.param2 == 125 then node.param2 = 0 end
end
end
minetest.swap_node(pos, node)
end
end
for i = 0, 1 do
local onoff = i == 0 and "" or "_on"
local node_definition = {
description = "Multi-coloured light";
tiles = {"digiplay_multicolour_light" .. onoff .. ".png"};
groups = {dig_immediate = 2, not_in_creative_inventory = 1};
drawtype = "color";
paramtype2 = "color";
palette = "digiplay_palette.png";
place_param2 = 0;
on_receive_fields = multicolour_light_on_receive_fields;
on_punch = multicolour_light_on_punch;
on_construct = multicolour_light_on_construct;
on_rightclick = multicolour_light_on_rightclick;
digiline = {
receptor = {
rules = digiline.rules.default;
};
effector = {
rules = digiline.rules.default;
action = multicolour_light_effector_action;
};
};
}
if i == 1 then
node_definition.tiles[1] = "digiplay_multicolour_light_on.png"
node_definition.light_source = 12
node_definition.drop = "digiplay:multicolour_light"
end
minetest.register_node("digiplay:multicolour_light" .. onoff, node_definition)
end
print("[mod] digiplay successfully loaded!")

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B