torches.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. local colour_list = {
  2. {"black", "Darkened",}, {"blue", "Blue",},
  3. {"cyan", "Cyan",}, {"green", "Green",},
  4. {"magenta", "Magenta",}, {"orange", "Orange",},
  5. {"purple", "Purple",}, {"red", "Red",},
  6. {"yellow", "Yellow",}, {"white", "Frosted",},
  7. }
  8. local enable_ceiling = true
  9. for i in ipairs(colour_list) do
  10. local colour = colour_list[i][1]
  11. local desc = colour_list[i][2]
  12. minetest.register_craftitem("abritorch:torch_"..colour, {
  13. description = desc.." Torch",
  14. inventory_image = "abritorch_torch_on_floor_"..colour..".png",
  15. wield_image = "abritorch_torch_on_floor_"..colour..".png",
  16. wield_scale = {x = 1, y = 1, z = 1 + 1/16},
  17. liquids_pointable = false,
  18. on_place = function(itemstack, placer, pointed_thing)
  19. local above = pointed_thing.above
  20. local under = pointed_thing.under
  21. local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z})
  22. if wdir < 1 and not enable_ceiling then
  23. return itemstack
  24. end
  25. local fakestack = itemstack
  26. local retval = false
  27. if wdir <= 1 then
  28. retval = fakestack:set_name("abritorch:floor_"..colour)
  29. else
  30. retval = fakestack:set_name("abritorch:wall_"..colour)
  31. end
  32. if not retval then
  33. return itemstack
  34. end
  35. itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, param2)
  36. itemstack:set_name("abritorch:torch_"..colour)
  37. return itemstack
  38. end
  39. })
  40. minetest.register_node("abritorch:floor_"..colour, {
  41. description = desc.." Torch",
  42. inventory_image = "abritorch_torch_on_floor_"..colour..".png",
  43. wield_image = "abritorch_torch_on_floor_"..colour..".png",
  44. wield_scale = {x = 1, y = 1, z = 1 + 1/16},
  45. drawtype = "mesh",
  46. mesh = "torch_floor.obj",
  47. tiles = {
  48. {
  49. name = "abritorch_torch_on_floor_animated_"..colour..".png",
  50. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  51. }
  52. },
  53. paramtype = "light",
  54. paramtype2 = "wallmounted",
  55. sunlight_propagates = true,
  56. walkable = false,
  57. light_source = 13,
  58. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  59. drop = "abritorch:torch_"..colour,
  60. selection_box = {
  61. type = "wallmounted",
  62. wall_top = {-1/16, -2/16, -1/16, 1/16, 0.5, 1/16},
  63. wall_bottom = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
  64. },
  65. })
  66. minetest.register_node("abritorch:wall_"..colour, {
  67. inventory_image = "abritorch_torch_on_floor_"..colour..".png",
  68. wield_image = "abritorch_torch_on_floor_"..colour..".png",
  69. wield_scale = {x = 1, y = 1, z = 1 + 1/16},
  70. drawtype = "mesh",
  71. mesh = "torch_wall.obj",
  72. tiles = {
  73. {
  74. name = "abritorch_torch_on_floor_animated_"..colour..".png",
  75. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  76. }
  77. },
  78. paramtype = "light",
  79. paramtype2 = "wallmounted",
  80. sunlight_propagates = true,
  81. walkable = false,
  82. light_source = 13,
  83. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  84. drop = "abritorch:torch_"..colour,
  85. selection_box = {
  86. type = "wallmounted",
  87. wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
  88. wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
  89. wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
  90. },
  91. })
  92. minetest.register_abm({
  93. nodenames = {"abritorch:torch_"..colour},
  94. interval = 1,
  95. chance = 1,
  96. action = function(pos)
  97. local n = minetest.get_node(pos)
  98. local def = minetest.registered_nodes[n.name]
  99. if n and def then
  100. local wdir = n.param2
  101. local node_name = "abritorch:wall_"..colour
  102. if wdir < 1 and not enable_ceiling then
  103. minetest.remove_node(pos)
  104. return
  105. elseif wdir <= 1 then
  106. node_name = "abritorch:floor_"..colour
  107. end
  108. minetest.set_node(pos, {name = node_name, param2 = wdir})
  109. end
  110. end
  111. })
  112. end