init.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. torches = torches or {}
  2. torches.modpath = minetest.get_modpath("torches")
  3. function torches.node_supports_torch(name, def)
  4. if name == "protector:protect" or name == "protector:protect3" then
  5. return true
  6. end
  7. local dt = def.drawtype
  8. if dt == "normal" or dt == "glasslike" or dt == "glasslike_framed" or
  9. dt == "glasslike_framed_optional" or dt == "allfaces" or
  10. dt == "allfaces_optional" then
  11. return true
  12. elseif minetest.get_item_group(name, "tree") ~= 0 then
  13. return true
  14. elseif string.find(name, "^maptools:") then
  15. return true
  16. end
  17. return false
  18. end
  19. function torches.put_torch(itemstack, placer, pt, only_wall)
  20. local under = pt.under
  21. local above = pt.above
  22. local node = minetest.get_node(under)
  23. local ndef = minetest.reg_ns_nodes[node.name]
  24. -- Call on_rightclick if target node defines it.
  25. if ndef and ndef.on_rightclick and
  26. ((not placer) or (placer and not placer:get_player_control().sneak)) then
  27. return ndef.on_rightclick(under, node, placer, itemstack, pt) or itemstack
  28. end
  29. local def = minetest.reg_ns_nodes[itemstack:get_name()]
  30. local good = false
  31. if def then
  32. if def._torches_node_ceiling and def._torches_node_floor and def._torches_node_wall then
  33. good = true
  34. end
  35. end
  36. if not good then
  37. return itemstack
  38. end
  39. -- If node under is buildable_to, place into it instead (eg. snow)
  40. local place_to = above
  41. if ndef and ndef.buildable_to then
  42. place_to = under
  43. end
  44. local place_in_non_air = (minetest.get_node(place_to).name ~= "air")
  45. local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
  46. if only_wall then
  47. if wdir == 0 or wdir == 1 then
  48. return itemstack
  49. end
  50. end
  51. local fakestack = itemstack
  52. local torch
  53. if wdir == 0 then
  54. torch = def._torches_node_ceiling
  55. elseif wdir == 1 then
  56. torch = def._torches_node_floor
  57. else
  58. torch = def._torches_node_wall
  59. end
  60. fakestack:set_name(torch)
  61. itemstack = minetest.item_place_node(fakestack, placer, pt, wdir)
  62. itemstack:set_name(def._torches_node_floor)
  63. return itemstack
  64. end
  65. if not torches.run_once then
  66. dofile(torches.modpath .. "/iron_torch.lua")
  67. dofile(torches.modpath .. "/cave_torch.lua")
  68. dofile(torches.modpath .. "/kalite_torch.lua")
  69. local c = "torches:core"
  70. local f = torches.modpath .. "/init.lua"
  71. reload.register_file(c, f, false)
  72. torches.run_once = true
  73. end