diff --git a/init.lua b/init.lua index 12365977983c2aeb19c5c25b89644d186bf774d1..1d5bce8736713a00cdeac3214ed5270c71e8daa2 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 1936607847358ffef477b8d1a2e1aaa45403480c..0000000000000000000000000000000000000000 --- 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 Binary files /dev/null and b/textures/party.png differ diff --git a/textures/pine_needles.png b/textures/pine_needles.png new file mode 100644 index 0000000000000000000000000000000000000000..e0e39908637cba3ca7d995102338ce97550d0e37 Binary files /dev/null and b/textures/pine_needles.png differ diff --git a/textures/pine_needles.png.license b/textures/pine_needles.png.license new file mode 100644 index 0000000000000000000000000000000000000000..abf8495a44bb2b97a7aeb6c3962890bf125d8cb1 --- /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 0000000000000000000000000000000000000000..14cb4c0c04e04d23e8c8f4186d2d01f813f02d8a --- /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"}, +})