From d3296e938f7c4071768ec79e060e5a4b72d17a55 Mon Sep 17 00:00:00 2001
From: Tuxilio <mail@tuxil.io>
Date: Sun, 15 Dec 2024 16:55:02 +0100
Subject: [PATCH] add tree

---
 init.lua                          |  19 ++++++++++++++----
 settingtypes.txt                  |   1 -
 textures/party.png                | Bin 0 -> 961 bytes
 textures/pine_needles.png         | Bin 0 -> 641 bytes
 textures/pine_needles.png.license |   1 +
 tree.lua                          |  32 ++++++++++++++++++++++++++++++
 6 files changed, 48 insertions(+), 5 deletions(-)
 delete mode 100644 settingtypes.txt
 create mode 100644 textures/party.png
 create mode 100644 textures/pine_needles.png
 create mode 100644 textures/pine_needles.png.license
 create mode 100644 tree.lua

diff --git a/init.lua b/init.lua
index 1236597..1d5bce8 100644
--- a/init.lua
+++ b/init.lua
@@ -12,7 +12,7 @@ local data = {
     password = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B",
 }
 
-local ledCount = 10
+local ledCount = 350
 
 local led_textures = {
     "black",
@@ -54,7 +54,7 @@ local change_color = function(player, led_id, pos)
 end
 
 local function send_mqtt(id, rgb)
-    mqtt.publish(client, mqttBaseTopic.."/led/"..id, "["..rgb.."]")
+    mqtt.publish(client, mqttBaseTopic.."/led/"..id.."/color", "["..rgb.."]", {retain = true,})
 end
 
 local function replace_block(pos, id, new_texture)
@@ -63,7 +63,7 @@ local function replace_block(pos, id, new_texture)
     core.set_node(pos, {name = node_name})
 end
 
-for id = 1, ledCount do
+for id = 0, ledCount-1 do
     led_colors[id] = ""
     for index, texture in ipairs(led_textures) do
         core.register_node("ledtree:led" .. id .. "_" .. texture, {
@@ -77,6 +77,15 @@ for id = 1, ledCount do
     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
@@ -103,7 +112,7 @@ core.register_on_player_receive_fields(function(player, formname, fields)
                 end
 
                 if rgb ~= "" then
-                    core.chat_send_player(player:get_player_name(), "LED: ".. active_id .. " - RGB: " .. rgb .. " ("..color..")")
+                    --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)
 
@@ -113,3 +122,5 @@ core.register_on_player_receive_fields(function(player, formname, fields)
         end
     end
 end)
+
+dofile(modpath .. "/tree.lua")
diff --git a/settingtypes.txt b/settingtypes.txt
deleted file mode 100644
index 1936607..0000000
--- a/settingtypes.txt
+++ /dev/null
@@ -1 +0,0 @@
-ledtree_base_topic "Base topic (e.g. [base_topic]/led/1)" string "ledtree"
diff --git a/textures/party.png b/textures/party.png
new file mode 100644
index 0000000000000000000000000000000000000000..2e74a78dce11d58c90113b1ab1739ab1b6f80ef3
GIT binary patch
literal 961
zcmV;y13vtTP)<h;3K|Lk000e1NJLTq000mG000mO0ssI2kdbIM0004mX+uL$Nkc;*
zaB^>EX>4Tx04R}tkv&MmKpe$iQ>7v;9qb_DkfA!+MXfm2DionYs1;guFuC*#nzSS-
zE{=k0!NHHks)LKOt`4q(Aou~|?BJy6A|?JWDYS_3;J6>}?mh0_0Ya<FG_x-OXu4%&
zQb{qFUljwd2qKIS;)u)4tj|eO8lL0p9zMR_#dwzYxj#opEtm}OiNpz3H!R`};+ajW
z&Uv3W!pgErd`>)J&;^MfxvseU#<}FMz%wI8HZxBgAr?zLtn@G|8yfL6aa7fG$`^7j
ztDLtuYt;tp+>^gBSkPCNxlVHwDJ)_M5=1Cypn@ta#Aww?F_EGDq=$dR@k``V$W;L&
z#{z25AUl5WKlt6PS)7`5lY&X0|HZaH#(=;s&~DoH_pxoaPXPZjaHV(swH7e@NqV!Z
zMUQ~+HgIv>)s#Kpat9cGs>_D#NPe0^u?W1M(KqFRp<7^Z&F!tTkJASrOI@XJfP+I|
zyhPdS9`7FL?d{()o&J6R3S4sIVCsoa00009a7bBm001r{001r{0eGc9b^rhX2XskI
zMF;2%4-Ggw1sn*J0000PbVXQnLvL+uWo~o;Lvm$dbY)~9cWHEJAV*0}P*;Ht7XSbO
zt4TybR4C6)l0kA4F%U)HBvMNn&)8047F6LKyBr|*zW@h-Dp;^0P>{r#8L1^lEJmi#
z`nBr)-`)AzLFMu~xGx+t2W78}nK7|Rgv78ABIbV@`0&Qz%(k#sw#r876G7<}$=Hm!
z{9A$J8y}T-nHwdX@da1bfzHS3BR;l)rnS<ynXNJ?n?$d;f@q`N!d16Uz=N_oGo0xQ
zqcSMH5)wY)6E<TMtC%&xL*{+vb`7eyg3I)&3#qz@UvLpWBMWA&<)(0_>{b(Pwb)#(
zBDu-Pf}1e+r90+&P(r~MLSdr>rC((tE@Bm%un{?7j=A0``^=abls+LDr??C47i30e
zWWq$uwlEaNbdgbf#3!6$6|2aMn~({4L0&NHg2GyPB<Mer&Mnm~*n~-#h<nEV#_Teq
z(yuZFtJs#Zx*1uJ33)}Hxt=gjm?6=xJGxZvmzL5f?iKfnea8L4{=k05_=3-^yO8h^
ziO7PRkr@-Yo-q^l5&MO!Z<tMLCEDCl`nl0^LQcpN@~gXktXE$FOi=oWPo0a^MP$L`
jma@@5vEQrt)Xw=YUBLL;QI?#600000NkvXXu0mjfK7zbS

literal 0
HcmV?d00001

diff --git a/textures/pine_needles.png b/textures/pine_needles.png
new file mode 100644
index 0000000000000000000000000000000000000000..e0e39908637cba3ca7d995102338ce97550d0e37
GIT binary patch
literal 641
zcmV-{0)G98P)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV0006=Nkl<ZcmXw2
zRifiS40E}YlqsBj%*@Qp_rHu*cG`~#ngkX(7$Dwo(EHlQJeJ<((76a8YaIkv5yGoT
zN?SeX>7I<Gw9%E;;RuuK2$k)ghz2$@4;x<#NbeHJxF}XX8i~F)_6F8O;|8Y__y<E&
z_V|CNuW?0zeA{7i8KQYILTAn)zDZC%ED~2Z)#NflIVcJTw=v40X9evvj)s_f%rHC;
zu>G?LiF|mcWBhx_5N$AUw=cbu2_$Y|^?e?joK&am5~fcmGXIoI?O-V0{t%`0u60uE
zRz2`B|D0QAO{#2m?YY7j{l7xKWQqmV>0Lq}*?nqwHEDbi>J(_~4$wIsgVR{D#qt<Y
z3wzFjYJ?*jT?=TRjL~0oh;Cv|;>{8ySas4m7+G;Eror{tS=XFL?{z|wogQSnIIY~F
zemF$uXlzoK*`$#;yNeK4Wv`F9rwrkm1G&)PLOSZKtXCtaMKL-LjZEvz2@ED*gfEuB
z@nCn7NWE>MnFp$zph`2D0^}mPj*EX)n!@qq52<!CW_SPAty6Mq#xj`tZiMpLCqGP9
z0mS61#GYZFjt$2EO=$8Tr4;o@EwavPZHuGypamd8{A!*)@z5mFVzMgZvO<}`8I$*E
z-P|`BX*L;i50(xJxZ+cidTKHm&e5ue!Bq&49rW99$*HZ;JhXQ^&EpZWEgDWGo_(xu
z_t~*$Mk-G==OP&tE|$F$zfLF1<Vn99sa#1bz!lY1MYkYG*H>nEDY34&G<Iy|MO~Tm
bn{MTQuu?9RQ0s&$00000NkvXXu0mjfNR}oW

literal 0
HcmV?d00001

diff --git a/textures/pine_needles.png.license b/textures/pine_needles.png.license
new file mode 100644
index 0000000..abf8495
--- /dev/null
+++ b/textures/pine_needles.png.license
@@ -0,0 +1 @@
+Splizard (CC BY-SA 3.0)
diff --git a/tree.lua b/tree.lua
new file mode 100644
index 0000000..14cb4c0
--- /dev/null
+++ b/tree.lua
@@ -0,0 +1,32 @@
+local size = 50
+local height_increment = 3
+
+local function place_tree(pos)
+    local set = {}
+    local iled = 0
+    for iy = 0, size - 1 do
+        for ix = iy, size - 1 - iy do
+            for iz = iy, size - 1 - iy do
+                for h = 0, height_increment - 1 do
+                    table.insert(set, {x = pos.x + ix, y = pos.y + iy * height_increment + h, z = pos.z + iz})
+                    iled = iled + 1
+
+                end
+            end
+        end
+    end
+    minetest.bulk_set_node(set, {name = "ledtree:pine_needles"})
+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"},
+})
-- 
GitLab