init.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. local S = minetest.get_translator("lavalamp")
  2. lavalamp = {}
  3. minetest.register_node("lavalamp:lavalamp", {
  4. description = S("Lava Lamp/Light"),
  5. drawtype = "mesh",
  6. mesh = "lavalamp.obj",
  7. tiles = {
  8. { name = "lavalamp_metal.png", color = "white" },
  9. { name = "lavalamp_lamp_liquid.png", color = "white" },
  10. },
  11. overlay_tiles = {
  12. "",
  13. {
  14. name="lavalamp_lamp_anim.png",
  15. animation={
  16. type="vertical_frames",
  17. aspect_w=40,
  18. aspect_h=40,
  19. length=6.0,
  20. },
  21. },
  22. },
  23. use_texture_alpha = true,
  24. inventory_image = "lavalamp_lamp_inv.png",
  25. paramtype = "light",
  26. paramtype2 = "color",
  27. palette = "unifieddyes_palette_extended.png",
  28. sunlight_propagates = true,
  29. walkable = false,
  30. light_source = 14,
  31. selection_box = {
  32. type = "fixed",
  33. fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 },
  34. },
  35. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, ud_param2_colorable = 1},
  36. sounds = default.node_sound_glass_defaults(),
  37. on_construct = unifieddyes.on_construct,
  38. on_dig = unifieddyes.on_dig,
  39. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  40. node.name = "lavalamp:lavalamp_off"
  41. minetest.swap_node(pos, node)
  42. return itemstack
  43. end
  44. })
  45. minetest.register_node("lavalamp:lavalamp_off", {
  46. description = S("Lava Lamp/Light (off)"),
  47. drawtype = "mesh",
  48. mesh = "lavalamp.obj",
  49. tiles = {
  50. { name = "lavalamp_metal.png", color = 0xffffffff },
  51. "lavalamp_lamp_off.png",
  52. },
  53. paramtype = "light",
  54. paramtype2 = "color",
  55. palette = "unifieddyes_palette_extended.png",
  56. sunlight_propagates = true,
  57. walkable = false,
  58. selection_box = {
  59. type = "fixed",
  60. fixed = { -0.25, -0.5, -0.25, 0.25,0.5, 0.25 },
  61. },
  62. groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, not_in_creative_inventory=1},
  63. sounds = default.node_sound_glass_defaults(),
  64. on_construct = unifieddyes.on_construct,
  65. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  66. node.name = "lavalamp:lavalamp"
  67. minetest.swap_node(pos, node)
  68. return itemstack
  69. end,
  70. drop = {
  71. items = {
  72. {items = {"lavalamp:lavalamp"}, inherit_color = true },
  73. }
  74. }
  75. })
  76. minetest.register_craft({
  77. output = "lavalamp:lavalamp",
  78. recipe = {
  79. {"", "wool:white", "", },
  80. {"", "bucket:bucket_water", "", },
  81. {"", "wool:black", "", }
  82. }
  83. })
  84. unifieddyes.register_color_craft({
  85. output = "lavalamp:lavalamp",
  86. palette = "extended",
  87. type = "shapeless",
  88. neutral_node = "lavalamp:lavalamp",
  89. recipe = {
  90. "NEUTRAL_NODE",
  91. "MAIN_DYE"
  92. }
  93. })
  94. -- convert to param2 coloring
  95. local colors = {
  96. "red",
  97. "orange",
  98. "yellow",
  99. "green",
  100. "blue",
  101. "violet"
  102. }
  103. lavalamp.old_static_nodes = {}
  104. for _, color in ipairs(colors) do
  105. table.insert(lavalamp.old_static_nodes, "lavalamp:"..color)
  106. table.insert(lavalamp.old_static_nodes, "lavalamp:"..color.."_off")
  107. end
  108. minetest.register_lbm({
  109. name = "lavalamp:convert",
  110. label = "Convert lava lamps to use param2 color",
  111. run_at_every_load = false,
  112. nodenames = lavalamp.old_static_nodes,
  113. action = function(pos, node)
  114. local name = node.name
  115. local color
  116. if string.find(name, "red") then
  117. color = "red"
  118. elseif string.find(name, "orange") then
  119. color = "orange"
  120. elseif string.find(name, "yellow") then
  121. color = "yellow"
  122. elseif string.find(name, "green") then
  123. color = "green"
  124. elseif string.find(name, "blue") then
  125. color = "blue"
  126. elseif string.find(name, "violet") then
  127. color = "violet"
  128. end
  129. local paletteidx, _ = unifieddyes.getpaletteidx("unifieddyes:"..color, "extended")
  130. minetest.set_node(pos, { name = "lavalamp:lavalamp", param2 = paletteidx })
  131. local meta = minetest.get_meta(pos)
  132. meta:set_string("dye", "unifieddyes:"..color)
  133. end
  134. })