torch.lua 4.3 KB

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