torch.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. --[[
  2. Torch mod - formerly mod "Torches"
  3. ======================
  4. (c) Copyright BlockMen (2013-2015)
  5. (C) Copyright sofar <sofar@foo-projects.org> (2016)
  6. This mod changes the default torch drawtype from "torchlike" to "mesh",
  7. giving the torch a three dimensional appearance. The mesh contains the
  8. proper pixel mapping to make the animation appear as a particle above
  9. the torch, while in fact the animation is just the texture of the mesh.
  10. License:
  11. ~~~~~~~~
  12. (c) Copyright BlockMen (2013-2015)
  13. Textures and Meshes/Models:
  14. CC-BY 3.0 BlockMen
  15. Note that the models were entirely done from scratch by sofar.
  16. Code:
  17. Licensed under the GNU LGPL version 2.1 or higher.
  18. You can redistribute it and/or modify it under
  19. the terms of the GNU Lesser General Public License
  20. as published by the Free Software Foundation;
  21. You should have received a copy of the GNU Lesser General Public
  22. License along with this library; if not, write to the Free Software
  23. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
  25. --]]
  26. local function on_flood(pos, oldnode, newnode)
  27. minetest.add_item(pos, ItemStack("default:torch 1"))
  28. -- Play flame-extinguish sound if liquid is not an 'igniter'
  29. local nodedef = minetest.registered_items[newnode.name]
  30. if not (nodedef and nodedef.groups and
  31. nodedef.groups.igniter and nodedef.groups.igniter > 0) then
  32. minetest.sound_play(
  33. "default_cool_lava",
  34. {pos = pos, max_hear_distance = 16, gain = 0.1}
  35. )
  36. end
  37. -- Remove the torch node
  38. return false
  39. end
  40. minetest.register_node("default:torch", {
  41. description = "Torch",
  42. drawtype = "mesh",
  43. mesh = "torch_floor.obj",
  44. inventory_image = "default_torch_on_floor.png",
  45. wield_image = "default_torch_on_floor.png",
  46. stack_max = 36,
  47. tiles = {{
  48. name = "default_torch_on_floor_animated.png",
  49. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  50. }},
  51. paramtype = "light",
  52. paramtype2 = "wallmounted",
  53. sunlight_propagates = true,
  54. walkable = false,
  55. liquids_pointable = false,
  56. light_source = 12,
  57. groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
  58. drop = "default:torch",
  59. selection_box = {
  60. type = "wallmounted",
  61. wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
  62. },
  63. sounds = default.node_sound_wood_defaults(),
  64. on_place = function(itemstack, placer, pointed_thing)
  65. local under = pointed_thing.under
  66. local node = minetest.get_node(under)
  67. local def = minetest.registered_nodes[node.name]
  68. if def and def.on_rightclick and
  69. not (placer and placer:is_player() and
  70. placer:get_player_control().sneak) then
  71. return def.on_rightclick(under, node, placer, itemstack,
  72. pointed_thing) or itemstack
  73. end
  74. local above = pointed_thing.above
  75. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  76. local fakestack = itemstack
  77. if wdir == 0 then
  78. fakestack:set_name("default:torch_ceiling")
  79. elseif wdir == 1 then
  80. fakestack:set_name("default:torch")
  81. else
  82. fakestack:set_name("default:torch_wall")
  83. end
  84. itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
  85. itemstack:set_name("default:torch")
  86. return itemstack
  87. end,
  88. floodable = true,
  89. on_flood = on_flood,
  90. })
  91. minetest.register_node("default:torch_wall", {
  92. drawtype = "mesh",
  93. mesh = "torch_wall.obj",
  94. tiles = {{
  95. name = "default_torch_on_floor_animated.png",
  96. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  97. }},
  98. paramtype = "light",
  99. paramtype2 = "wallmounted",
  100. sunlight_propagates = true,
  101. walkable = false,
  102. light_source = 12,
  103. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  104. drop = "default:torch",
  105. selection_box = {
  106. type = "wallmounted",
  107. wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
  108. },
  109. sounds = default.node_sound_wood_defaults(),
  110. floodable = true,
  111. on_flood = on_flood,
  112. })
  113. minetest.register_node("default:torch_ceiling", {
  114. drawtype = "mesh",
  115. mesh = "torch_ceiling.obj",
  116. tiles = {{
  117. name = "default_torch_on_floor_animated.png",
  118. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  119. }},
  120. paramtype = "light",
  121. paramtype2 = "wallmounted",
  122. sunlight_propagates = true,
  123. walkable = false,
  124. light_source = 12,
  125. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  126. drop = "default:torch",
  127. selection_box = {
  128. type = "wallmounted",
  129. wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8},
  130. },
  131. sounds = default.node_sound_wood_defaults(),
  132. floodable = true,
  133. on_flood = on_flood,
  134. })
  135. minetest.register_lbm({
  136. name = "default:3dtorch",
  137. nodenames = {"default:torch", "torches:floor", "torches:wall"},
  138. action = function(pos, node)
  139. if node.param2 == 0 then
  140. minetest.set_node(pos, {name = "default:torch_ceiling",
  141. param2 = node.param2})
  142. elseif node.param2 == 1 then
  143. minetest.set_node(pos, {name = "default:torch",
  144. param2 = node.param2})
  145. else
  146. minetest.set_node(pos, {name = "default:torch_wall",
  147. param2 = node.param2})
  148. end
  149. end
  150. })