torch.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. local function on_flood(pos, oldnode, newnode)
  2. minetest.add_item(pos, ItemStack("default:torch 1"))
  3. -- Play flame-extinguish sound if liquid is not an 'igniter'
  4. local nodedef = minetest.registered_items[newnode.name]
  5. if not (nodedef and nodedef.groups and
  6. nodedef.groups.igniter and nodedef.groups.igniter > 0) then
  7. minetest.sound_play(
  8. "default_cool_lava",
  9. {pos = pos, max_hear_distance = 16, gain = 0.1}
  10. )
  11. end
  12. -- Remove the torch node
  13. return false
  14. end
  15. minetest.register_node("default:torch", {
  16. description = "Torch",
  17. drawtype = "mesh",
  18. mesh = "torch_floor.obj",
  19. inventory_image = "default_torch_on_floor.png",
  20. wield_image = "default_torch_on_floor.png",
  21. tiles = {{
  22. name = "default_torch_on_floor_animated.png",
  23. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  24. }},
  25. paramtype = "light",
  26. paramtype2 = "wallmounted",
  27. sunlight_propagates = true,
  28. walkable = false,
  29. liquids_pointable = false,
  30. light_source = 12,
  31. groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
  32. drop = "default:torch",
  33. selection_box = {
  34. type = "wallmounted",
  35. wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
  36. },
  37. sounds = default.node_sound_wood_defaults(),
  38. on_place = function(itemstack, placer, pointed_thing)
  39. local under = pointed_thing.under
  40. local node = minetest.get_node(under)
  41. local def = minetest.registered_nodes[node.name]
  42. if def and def.on_rightclick and
  43. not (placer and placer:is_player() and
  44. placer:get_player_control().sneak) then
  45. return def.on_rightclick(under, node, placer, itemstack,
  46. pointed_thing) or itemstack
  47. end
  48. local above = pointed_thing.above
  49. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  50. local fakestack = itemstack
  51. if wdir == 0 then
  52. fakestack:set_name("default:torch_ceiling")
  53. elseif wdir == 1 then
  54. fakestack:set_name("default:torch")
  55. else
  56. fakestack:set_name("default:torch_wall")
  57. end
  58. itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
  59. itemstack:set_name("default:torch")
  60. return itemstack
  61. end,
  62. floodable = true,
  63. on_flood = on_flood,
  64. })
  65. minetest.register_node("default:torch_wall", {
  66. drawtype = "mesh",
  67. mesh = "torch_wall.obj",
  68. tiles = {{
  69. name = "default_torch_on_floor_animated.png",
  70. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  71. }},
  72. paramtype = "light",
  73. paramtype2 = "wallmounted",
  74. sunlight_propagates = true,
  75. walkable = false,
  76. light_source = 12,
  77. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  78. drop = "default:torch",
  79. selection_box = {
  80. type = "wallmounted",
  81. wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
  82. },
  83. sounds = default.node_sound_wood_defaults(),
  84. floodable = true,
  85. on_flood = on_flood,
  86. })
  87. minetest.register_node("default:torch_ceiling", {
  88. drawtype = "mesh",
  89. mesh = "torch_ceiling.obj",
  90. tiles = {{
  91. name = "default_torch_on_floor_animated.png",
  92. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  93. }},
  94. paramtype = "light",
  95. paramtype2 = "wallmounted",
  96. sunlight_propagates = true,
  97. walkable = false,
  98. light_source = 12,
  99. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  100. drop = "default:torch",
  101. selection_box = {
  102. type = "wallmounted",
  103. wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8},
  104. },
  105. sounds = default.node_sound_wood_defaults(),
  106. floodable = true,
  107. on_flood = on_flood,
  108. })
  109. minetest.register_lbm({
  110. name = "default:3dtorch",
  111. nodenames = {"default:torch", "torches:floor", "torches:wall"},
  112. action = function(pos, node)
  113. if node.param2 == 0 then
  114. minetest.set_node(pos, {name = "default:torch_ceiling",
  115. param2 = node.param2})
  116. elseif node.param2 == 1 then
  117. minetest.set_node(pos, {name = "default:torch",
  118. param2 = node.param2})
  119. else
  120. minetest.set_node(pos, {name = "default:torch_wall",
  121. param2 = node.param2})
  122. end
  123. end
  124. })