Skip to content
Snippets Groups Projects
Verified Commit d3296e93 authored by Tuxilio's avatar Tuxilio
Browse files

add tree

parent c426b94c
No related branches found
No related tags found
No related merge requests found
......@@ -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")
ledtree_base_topic "Base topic (e.g. [base_topic]/led/1)" string "ledtree"
textures/party.png

961 B

textures/pine_needles.png

641 B

Splizard (CC BY-SA 3.0)
tree.lua 0 → 100644
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"},
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment