From dc44a858dad7efe899b26e66b6c08f181aaf730e Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 11 Aug 2022 03:47:27 +0200 Subject: [PATCH] Randomly move fireflies around --- mods/ITEMS/mcl_fireflies/init.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_fireflies/init.lua b/mods/ITEMS/mcl_fireflies/init.lua index 71a11d216..5ed6d12a8 100644 --- a/mods/ITEMS/mcl_fireflies/init.lua +++ b/mods/ITEMS/mcl_fireflies/init.lua @@ -3,7 +3,14 @@ -- Load support for MT game translation. local S = minetest.get_translator("fireflies") - +local adjacents = { + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,1,0), + vector.new(0,-1,0), + vector.new(0,0,1), + vector.new(0,0,-1), +} minetest.register_node("mcl_fireflies:firefly", { description = S("Firefly"), drawtype = "plantlike", @@ -44,6 +51,14 @@ minetest.register_node("mcl_fireflies:firefly", { return itemstack end, on_timer = function(pos, elapsed) + if math.random(2) == 1 then + local npos = vector.add(pos,adjacents[math.random(#adjacents)]) + if minetest.get_node(npos).name == "air" then + minetest.set_node(npos, {name = "mcl_fireflies:firefly"}) + minetest.remove_node(pos) + pos = npos + end + end if minetest.get_node_light(pos) > 11 then minetest.set_node(pos, {name = "mcl_fireflies:hidden_firefly"}) end