Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tuxilio/ledtree
  • codecraft/ledtree
2 results
Show changes
Commits on Source (9)
# Luanti LED Tree
You have to add the mod to the trusted mods in minetest.conf:
secure.http_mods = ledtree
......@@ -2,40 +2,125 @@
--
-- SPDX-License-Identifier: GPL-3.0-or-later
local HTTPApiTable = core.request_http_api()
local modname = core.get_current_modname()
local modpath = core.get_modpath(modname)
local data = {
url = "wss://mqtt.felix-zauberer.de:443",
url = "mqtt.felix-zauberer.de",
clientId = "ledtree_luanti",
username = "kalle1",
token = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B",
password = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B",
}
change_color = function(led_id)
local resquest = {
url = data.url,
method = 'POST',
timeout = 15,
username = data.username,
clientId = data.clientId,
extra_headers = {
"Authorization: Bearer "..data.token,
}
}
HTTPApiTable.fetch(request, function(response)
print(dump(request))
if response.code ~= 200 then
return false
else
return true
end
end)
local ledCount = 350
local led_textures = {
"black",
"blue",
"cyan",
"gray",
"green",
"magenta",
"red",
"white",
"yellow",
}
local led_colors = {}
local active_pos
local active_id
local mqttBaseTopic = core.settings:get("ledtree_base_topic") or "ledtree"
local client = mqtt.connect(data.url, data.clientId, data.username, data.password)
local change_color = function(player, led_id, pos)
local pos_string = core.serialize(pos)
active_pos = pos
active_id = led_id
local formspec = "size[3,3]" ..
"image_button[0,0;1,1;red.png;red;red;false;false;]" ..
"image_button[1,0;1,1;green.png;green;green;false;false;]" ..
"image_button[2,0;1,1;blue.png;blue;blue;false;false;]" ..
"image_button[0,1;1,1;yellow.png;yellow;yellow;false;false;]" ..
"image_button[1,1;1,1;cyan.png;cyan;cyan;false;false;]" ..
"image_button[2,1;1,1;magenta.png;magenta;magenta;false;false;]" ..
"image_button[0,2;1,1;white.png;white;white;false;false;]" ..
"image_button[1,2;1,1;black.png;black;black;false;false;]" ..
"image_button[2,2;1,1;gray.png;gray;gray;false;false;]"
core.show_formspec(player:get_player_name(), "ledtree:colorpicker", formspec)
end
for i=1, 10, 1 do
core.register_node("ledtree:led"..i, {
description = "LED"..i,
--tiles = "",
on_rightclick = change_color(i),
})
local function send_mqtt(id, rgb)
mqtt.publish(client, mqttBaseTopic.."/led/"..id.."/color", "["..rgb.."]", {retain = true,})
end
local function replace_block(pos, id, new_texture)
--local node = core.get_node(pos)
local node_name = "ledtree:led" .. id .. "_" .. new_texture
core.set_node(pos, {name = node_name})
end
for id = 0, ledCount-1 do
led_colors[id] = ""
for index, texture in ipairs(led_textures) do
core.register_node("ledtree:led" .. id .. "_" .. texture, {
description = "LED" .. id .." " .. texture,
tiles = {texture .. ".png",},
light_source = 10,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
change_color(player, id, pos)
end,
})
end
end
core.register_node("ledtree:party", {
description = "Party",
tiles = {"party.png"},
light_source = 10,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
mqtt.publish(client, mqttBaseTopic.."/effects", "[party]")
end,
})
core.register_on_player_receive_fields(function(player, formname, fields)
if formname == "ledtree:colorpicker" then
for color, _ in pairs(fields) do
if color then
local rgb = ""
if color == "red" then
rgb = "255,0,0"
elseif color == "green" then
rgb = "0,255,0"
elseif color == "blue" then
rgb = "0,0,255"
elseif color == "yellow" then
rgb = "255,255,0"
elseif color == "cyan" then
rgb = "0,255,255"
elseif color == "magenta" then
rgb = "255,0,255"
elseif color == "white" then
rgb = "255,255,255"
elseif color == "black" then
rgb = "0,0,0"
elseif color == "gray" then
rgb = "128,128,128"
end
if rgb ~= "" then
--core.chat_send_player(player:get_player_name(), "LED: ".. active_id .. " - RGB: " .. rgb .. " ("..color..")")
send_mqtt(active_id, rgb)
replace_block(active_pos, active_id, color)
core.close_formspec(player:get_player_name(), "ledtree:colorpicker")
end
end
end
end
end)
dofile(modpath .. "/tree.lua")
name = ledtree
title = Teckids LED-Weihnachtsbaum
description = Teckids LED-Weihnachtsbaum
depends = mqtt
author = Tuxilio <mail@tuxil.io>
textures/black.png

550 B

textures/blue.png

560 B

textures/cyan.png

560 B

textures/gray.png

560 B

textures/green.png

558 B

textures/magenta.png

560 B

textures/party.png

961 B

textures/pine_needles.png

641 B

Splizard (CC BY-SA 3.0)
textures/red.png

556 B

textures/white.png

560 B

textures/yellow.png

558 B

-- NUR DURCH 4 TEILBARE ZAHLEN > 20 VERWENDEN!!!
local leds = {
64,
56,
48,
36,
20,
}
for i = 1, #leds do
if leds[i] % 4 ~= 0 then
error("[ledtree] led count per layer must be divisible by 4. Error location: 'leds' table, item "..i..": "..leds[i])
end
if leds[i] < 20 then
error("[ledtree] led count per layer must be greater than or qual to 20. Error location: 'leds' table, item "..i..": "..leds[i])
end
end
local height_increment = 3
local function breite(n)
return n / 4
end
local function is_led(center, breite, pos)
if math.abs(center.x - pos.x) >= (breite - 1) / 2 and math.abs(center.z - pos.z) >= (breite - 1) / 2 then
return false
end
if math.abs(center.x - pos.x) == (breite - 1) / 2 then
return math.abs(center.z - pos.z) % 2 == 0
end
if math.abs(center.z - pos.z) == (breite - 1) / 2 then
return math.abs(center.x - pos.x) % 2 == 0
end
end
local function place_layer(center, breite)
breite = breite * 2 + 1
local needles = {}
local leds = {}
local max_offset = math.floor(breite / 2)
for y = math.ceil(-height_increment / 2), math.floor(height_increment / 2) do
for x = -max_offset, max_offset do
for z = -max_offset, max_offset do
local pos = vector.new({x = center.x + x, y = center.y + y, z = center.z + z})
table.insert(needles, pos)
if y == 0 and is_led(center, breite, pos) then
table.insert(leds, pos)
end
end
end
end
core.bulk_set_node(needles, {name = "ledtree:pine_needles"})
return leds
end
local function place_leds(led_index, leds)
for i = 1, #leds do
core.set_node(leds[i], {name = "ledtree:led"..led_index.."_red"})
led_index = led_index + 1
end
return led_index
end
local function place_tree(pos)
local led_index = 0
for index = 1, #leds do
local l = leds[index]
local layer_center = vector.new(pos.x, pos.y + index * height_increment - height_increment / 2, pos.z)
local leds = place_layer(layer_center, breite(l))
led_index = place_leds(led_index, leds)
end
end
core.register_node("ledtree:ledtree", {
description = "Place LED tree",
on_construct = function(pos)
place_tree(pos)
end,
})
core.register_node("ledtree:pine_needles", {
description = "Pine Needles",
paramtype = "light",
tiles = {"pine_needles.png"},
})