torches.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. -- This code was derived by sofar from the 'torches' mod by
  2. -- BlockMen (LGPLv2.1+), modified by Amaz
  3. -- The models from Minetest Game were not used, they made from scratch
  4. -- https://forum.minetest.net/viewtopic.php?f=11&t=6099
  5. -- https://github.com/minetest/minetest_game/blob/master/mods/default/torch.lua
  6. local function on_flood(pos, oldnode, newnode)
  7. minetest.add_item(pos, ItemStack("default:torch 1"))
  8. return false
  9. end
  10. minetest.register_node("default:torch", {
  11. description = "Torch",
  12. drawtype = "mesh",
  13. mesh = "default_torch_floor.obj",
  14. inventory_image = "default_torch_on_floor.png",
  15. wield_image = "default_torch_on_floor.png",
  16. tiles = {{
  17. name = "default_torch_on_floor_animated.png",
  18. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  19. }},
  20. paramtype = "light",
  21. paramtype2 = "wallmounted",
  22. sunlight_propagates = true,
  23. walkable = false,
  24. liquids_pointable = false,
  25. light_source = 12,
  26. groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
  27. drop = "default:torch",
  28. selection_box = {
  29. type = "wallmounted",
  30. wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
  31. wall_top = {-1/8, -3/16, -1/8, 1/8, 1/2, 1/8},
  32. },
  33. on_place = function(itemstack, placer, pointed_thing)
  34. local under = pointed_thing.under
  35. local node = minetest.get_node(under)
  36. local def = minetest.registered_nodes[node.name]
  37. if def and def.on_rightclick and
  38. not (placer and placer:is_player() and
  39. placer:get_player_control().sneak) then
  40. return def.on_rightclick(under, node, placer, itemstack,
  41. pointed_thing) or itemstack
  42. end
  43. local above = pointed_thing.above
  44. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  45. local fakestack = itemstack
  46. if wdir == 0 or wdir == 1 then
  47. fakestack:set_name("default:torch")
  48. else
  49. fakestack:set_name("default:torch_wall")
  50. end
  51. itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
  52. itemstack:set_name("default:torch")
  53. return itemstack
  54. end,
  55. floodable = true,
  56. on_flood = on_flood,
  57. })
  58. minetest.register_node("default:torch_wall", {
  59. drawtype = "mesh",
  60. mesh = "default_torch_wall.obj",
  61. tiles = {{
  62. name = "default_torch_on_floor_animated.png",
  63. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  64. }},
  65. paramtype = "light",
  66. paramtype2 = "wallmounted",
  67. sunlight_propagates = true,
  68. walkable = false,
  69. light_source = 12,
  70. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  71. drop = "default:torch",
  72. selection_box = {
  73. type = "wallmounted",
  74. wall_side = {-1/2, -1/2, -1/8, -5/16, 1/8, 1/8},
  75. },
  76. floodable = true,
  77. on_flood = on_flood,
  78. })
  79. minetest.register_lbm({
  80. name = "default:3dtorch",
  81. nodenames = {"default:torch", "torches:floor", "torches:wall"},
  82. action = function(pos, node)
  83. if node.param2 == 0 or node.param2 == 1 then
  84. minetest.set_node(pos, {name = "default:torch",
  85. param2 = node.param2})
  86. else
  87. minetest.set_node(pos, {name = "default:torch_wall",
  88. param2 = node.param2})
  89. end
  90. end
  91. })