torch.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. minetest.register_node("default:torch", {
  27. description = "Torch",
  28. drawtype = "mesh",
  29. mesh = "torch_floor.obj",
  30. inventory_image = "default_torch_on_floor.png",
  31. wield_image = "default_torch_on_floor.png",
  32. tiles = {{
  33. name = "default_torch_on_floor_animated.png",
  34. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  35. }},
  36. paramtype = "light",
  37. paramtype2 = "wallmounted",
  38. sunlight_propagates = true,
  39. walkable = false,
  40. liquids_pointable = false,
  41. light_source = 12,
  42. groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
  43. drop = "default:torch",
  44. selection_box = {
  45. type = "wallmounted",
  46. wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
  47. },
  48. sounds = default.node_sound_wood_defaults(),
  49. on_place = function(itemstack, placer, pointed_thing)
  50. local under = pointed_thing.under
  51. local node = minetest.get_node(under)
  52. local def = minetest.registered_nodes[node.name]
  53. if def and def.on_rightclick and
  54. ((not placer) or (placer and not placer:get_player_control().sneak)) then
  55. return def.on_rightclick(under, node, placer, itemstack,
  56. pointed_thing) or itemstack
  57. end
  58. local above = pointed_thing.above
  59. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  60. local fakestack = itemstack
  61. if wdir == 0 then
  62. fakestack:set_name("default:torch_ceiling")
  63. elseif wdir == 1 then
  64. fakestack:set_name("default:torch")
  65. else
  66. fakestack:set_name("default:torch_wall")
  67. end
  68. itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
  69. itemstack:set_name("default:torch")
  70. return itemstack
  71. end
  72. })
  73. minetest.register_node("default:torch_wall", {
  74. drawtype = "mesh",
  75. mesh = "torch_wall.obj",
  76. tiles = {{
  77. name = "default_torch_on_floor_animated.png",
  78. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  79. }},
  80. paramtype = "light",
  81. paramtype2 = "wallmounted",
  82. sunlight_propagates = true,
  83. walkable = false,
  84. light_source = 12,
  85. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  86. drop = "default:torch",
  87. selection_box = {
  88. type = "wallmounted",
  89. wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
  90. },
  91. sounds = default.node_sound_wood_defaults(),
  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. })
  113. minetest.register_lbm({
  114. name = "default:3dtorch",
  115. nodenames = {"default:torch", "torches:floor", "torches:wall"},
  116. action = function(pos, node)
  117. if node.param2 == 0 then
  118. minetest.set_node(pos, {name = "default:torch_ceiling",
  119. param2 = node.param2})
  120. elseif node.param2 == 1 then
  121. minetest.set_node(pos, {name = "default:torch",
  122. param2 = node.param2})
  123. else
  124. minetest.set_node(pos, {name = "default:torch_wall",
  125. param2 = node.param2})
  126. end
  127. end
  128. })