torch.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. local S = minetest.get_translator("sticks_and_torches")
  2. minetest.register_node("sticks_and_torches:torch", {
  3. description = S("Torch"),
  4. drawtype = "mesh",
  5. mesh = "torch_floor.obj",
  6. inventory_image = "sticks_and_torches_torch_on_floor.png",
  7. wield_image = "sticks_and_torches_torch_on_floor.png",
  8. tiles = {{
  9. name = "sticks_and_torches_torch_on_floor_animated.png",
  10. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  11. }},
  12. stack_max = 128,
  13. paramtype = "light",
  14. paramtype2 = "wallmounted",
  15. sunlight_propagates = true,
  16. walkable = false,
  17. liquids_pointable = false,
  18. light_source = 12,
  19. groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
  20. drop = "sticks_and_torches:torch",
  21. selection_box = {
  22. type = "wallmounted",
  23. wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
  24. },
  25. sounds = generic_media.node_sound_wood_defaults(),
  26. on_place = function(itemstack, placer, pointed_thing)
  27. local under = pointed_thing.under
  28. local node = minetest.get_node(under)
  29. local def = minetest.registered_nodes[node.name]
  30. if def and def.on_rightclick and
  31. not (placer and placer:is_player() and
  32. placer:get_player_control().sneak) then
  33. return def.on_rightclick(under, node, placer, itemstack,
  34. pointed_thing) or itemstack
  35. end
  36. local above = pointed_thing.above
  37. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  38. local fakestack = itemstack
  39. if wdir == 0 then
  40. fakestack:set_name("sticks_and_torches:torch_ceiling")
  41. elseif wdir == 1 then
  42. fakestack:set_name("sticks_and_torches:torch")
  43. else
  44. fakestack:set_name("sticks_and_torches:torch_wall")
  45. end
  46. itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
  47. itemstack:set_name("sticks_and_torches:torch")
  48. return itemstack
  49. end,
  50. floodable = true,
  51. })
  52. minetest.register_node("sticks_and_torches:torch_wall", {
  53. drawtype = "mesh",
  54. mesh = "torch_wall.obj",
  55. tiles = {{
  56. name = "sticks_and_torches_torch_on_floor_animated.png",
  57. animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
  58. }},
  59. paramtype = "light",
  60. paramtype2 = "wallmounted",
  61. sunlight_propagates = true,
  62. walkable = false,
  63. light_source = 12,
  64. groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
  65. drop = "sticks_and_torches:torch",
  66. selection_box = {
  67. type = "wallmounted",
  68. wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
  69. },
  70. sounds = generic_media.node_sound_wood_defaults(),
  71. floodable = true,
  72. })
  73. minetest.register_node("sticks_and_torches:torch_ceiling", {
  74. drawtype = "mesh",
  75. mesh = "torch_ceiling.obj",
  76. tiles = {{
  77. name = "sticks_and_torches_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 = "sticks_and_torches:torch",
  87. selection_box = {
  88. type = "wallmounted",
  89. wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8},
  90. },
  91. sounds = generic_media.node_sound_wood_defaults(),
  92. floodable = true,
  93. })
  94. minetest.register_lbm({
  95. name = "sticks_and_torches:3dtorch",
  96. nodenames = {"sticks_and_torches:torch", "torches:floor", "torches:wall"},
  97. action = function(pos, node)
  98. if node.param2 == 0 then
  99. minetest.set_node(pos, {name = "sticks_and_torches:torch_ceiling",
  100. param2 = node.param2})
  101. elseif node.param2 == 1 then
  102. minetest.set_node(pos, {name = "sticks_and_torches:torch",
  103. param2 = node.param2})
  104. else
  105. minetest.set_node(pos, {name = "sticks_and_torches:torch_wall",
  106. param2 = node.param2})
  107. end
  108. end
  109. })
  110. minetest.register_alias("torch", "sticks_and_torches:torch")