torch.lua 4.2 KB

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