diff --git a/lavalamp/init.lua b/lavalamp/init.lua index c106c88..d096fea 100644 --- a/lavalamp/init.lua +++ b/lavalamp/init.lua @@ -1,84 +1,135 @@ -local lavalamps_list = { - { "Red Lava Lamp", "red"}, - { "Orange Lava Lamp", "orange"}, - { "Yellow Lava Lamp", "yellow"}, - { "Green Lava Lamp", "green"}, - { "Blue Lava Lamp", "blue"}, - { "Violet Lava Lamp", "violet"}, + +lavalamp = {} + +minetest.register_node("lavalamp:lavalamp", { + description = "Lava Lamp", + drawtype = "mesh", + mesh = "lavalamp.obj", + tiles = { + { name = "lavalamp_metal.png", color = 0xffffffff}, + { + name="lavalamp_lamp_anim.png", + animation={ + type="vertical_frames", + aspect_w=40, + aspect_h=40, + length=6.0, + }, + }, + }, + inventory_image = "lavalamp_lamp_inv.png", + paramtype = "light", + paramtype2 = "color", + palette = "unifieddyes_palette.png", + sunlight_propagates = true, + walkable = false, + light_source = 14, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 }, + }, + groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3}, + sounds = default.node_sound_glass_defaults(), + after_dig_node = unifieddyes.after_dig_node, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local itemname = itemstack:get_name() + if string.find(itemname, "dye:") or string.find(itemname, "unifieddyes:") then + unifieddyes.on_rightclick(pos, node, clicker, + itemstack, pointed_thing, "lavalamp:lavalamp", false) + else + node.name = "lavalamp:lavalamp_off" + minetest.swap_node(pos, node) + return itemstack + end + end +}) + +minetest.register_node("lavalamp:lavalamp_off", { + description = "Lava Lamp (off)", + drawtype = "mesh", + mesh = "lavalamp.obj", + tiles = { + { name = "lavalamp_metal.png", color = 0xffffffff }, + "lavalamp_lamp_off.png", + }, + paramtype = "light", + paramtype2 = "color", + palette = "unifieddyes_palette.png", + sunlight_propagates = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 }, + }, + groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1}, + sounds = default.node_sound_glass_defaults(), + drop = "lavalamp:lavalamp", + after_dig_node = unifieddyes.after_dig_node, + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + node.name = "lavalamp:lavalamp" + minetest.swap_node(pos, node) + return itemstack + end, +}) + +minetest.register_craft({ + output = "lavalamp:lavalamp", + recipe = { + {"", "wool:white", "", }, + {"", "bucket:bucket_water", "", }, + {"", "wool:black", "", } + } +}) + +-- convert to param2 coloring + +local colors = { + "red", + "orange", + "yellow", + "green", + "blue", + "violet" } -for i in ipairs(lavalamps_list) do - local lavalampdesc = lavalamps_list[i][1] - local colour = lavalamps_list[i][2] - - minetest.register_node("lavalamp:"..colour, { - description = lavalampdesc, - drawtype = "mesh", - mesh = "lavalamp.obj", - tiles = { - "lavalamp_metal.png", - { - name="lavalamp_lamp_anim_"..colour..".png", - animation={ - type="vertical_frames", - aspect_w=40, - aspect_h=40, - length=6.0, - }, - }, - }, - inventory_image = "lavalamp_lamp_"..colour.."_inv.png", - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - walkable = false, - light_source = 14, - selection_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 }, - }, - groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3}, - sounds = default.node_sound_glass_defaults(), - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - node.name = "lavalamp:"..colour.."_off" - minetest.set_node(pos, node) - return itemstack - end, - }) - - minetest.register_node("lavalamp:"..colour.."_off", { - description = lavalampdesc.." off", - drawtype = "mesh", - mesh = "lavalamp.obj", - tiles = { - "lavalamp_metal.png", - "lavalamp_lamp_off.png", - }, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - walkable = false, - selection_box = { - type = "fixed", - fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 }, - }, - groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1}, - sounds = default.node_sound_glass_defaults(), - drop = "lavalamp:"..colour, - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - node.name = "lavalamp:"..colour - minetest.set_node(pos, node) - return itemstack - end, - }) - - minetest.register_craft({ - output = "lavalamp:"..colour, - recipe = { - {"", "wool:"..colour, "", }, - {"", "bucket:bucket_water", "", }, - {"", "wool:black", "", } - } - }) - +lavalamp.old_static_nodes = {} +for _, color in ipairs(colors) do + table.insert(lavalamp.old_static_nodes, "lavalamp:"..color) + table.insert(lavalamp.old_static_nodes, "lavalamp:"..color.."_off") end + +print(dump(lavalamp.old_static_nodes)) + +minetest.register_lbm({ + name = "lavalamp:convert", + label = "Convert lava lamps to use param2 color", + run_at_every_load = true, + nodenames = lavalamp.old_static_nodes, + action = function(pos, node) + local name = node.name + local newname + local color + + if string.find(name, "red") then + color = "red" + elseif string.find(name, "orange") then + color = "orange" + elseif string.find(name, "yellow") then + color = "yellow" + elseif string.find(name, "green") then + color = "green" + elseif string.find(name, "blue") then + color = "blue" + elseif string.find(name, "violet") then + color = "violet" + end + + local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, false) + print("LAVALAMP: "..node.name..", "..color.." ("..paletteidx..")") + + minetest.set_node(pos, { name = "lavalamp:lavalamp", param2 = paletteidx }) + local meta = minetest.get_meta(pos) + meta:set_string("dye", "unifieddyes:"..color) + + end +}) diff --git a/lavalamp/textures/lavalamp_lamp_anim.png b/lavalamp/textures/lavalamp_lamp_anim.png new file mode 100644 index 0000000..d9f7d53 Binary files /dev/null and b/lavalamp/textures/lavalamp_lamp_anim.png differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_blue.png b/lavalamp/textures/lavalamp_lamp_anim_blue.png deleted file mode 100644 index 2c08584..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_blue.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_green.png b/lavalamp/textures/lavalamp_lamp_anim_green.png deleted file mode 100644 index 40f5ac1..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_green.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_orange.png b/lavalamp/textures/lavalamp_lamp_anim_orange.png deleted file mode 100644 index 98eb4da..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_orange.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_red.png b/lavalamp/textures/lavalamp_lamp_anim_red.png deleted file mode 100644 index 9a4d706..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_red.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_violet.png b/lavalamp/textures/lavalamp_lamp_anim_violet.png deleted file mode 100644 index 8b09496..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_violet.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_anim_yellow.png b/lavalamp/textures/lavalamp_lamp_anim_yellow.png deleted file mode 100644 index 1c1af2c..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_anim_yellow.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_blue_inv.png b/lavalamp/textures/lavalamp_lamp_blue_inv.png deleted file mode 100644 index 144643f..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_blue_inv.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_green_inv.png b/lavalamp/textures/lavalamp_lamp_green_inv.png deleted file mode 100644 index 594f82d..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_green_inv.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_red_inv.png b/lavalamp/textures/lavalamp_lamp_inv.png similarity index 100% rename from lavalamp/textures/lavalamp_lamp_red_inv.png rename to lavalamp/textures/lavalamp_lamp_inv.png diff --git a/lavalamp/textures/lavalamp_lamp_off.png b/lavalamp/textures/lavalamp_lamp_off.png index 704f9c5..491708e 100644 Binary files a/lavalamp/textures/lavalamp_lamp_off.png and b/lavalamp/textures/lavalamp_lamp_off.png differ diff --git a/lavalamp/textures/lavalamp_lamp_orange_inv.png b/lavalamp/textures/lavalamp_lamp_orange_inv.png deleted file mode 100644 index da41b96..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_orange_inv.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_violet_inv.png b/lavalamp/textures/lavalamp_lamp_violet_inv.png deleted file mode 100644 index c599731..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_violet_inv.png and /dev/null differ diff --git a/lavalamp/textures/lavalamp_lamp_yellow_inv.png b/lavalamp/textures/lavalamp_lamp_yellow_inv.png deleted file mode 100644 index 6c2b21a..0000000 Binary files a/lavalamp/textures/lavalamp_lamp_yellow_inv.png and /dev/null differ