init.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. arrows = {
  2. {"throwing:arrow", "throwing:arrow_entity"},
  3. {"throwing:arrow_fire", "throwing:arrow_fire_entity"},
  4. {"throwing:arrow_teleport", "throwing:arrow_teleport_entity"},
  5. {"throwing:arrow_dig", "throwing:arrow_dig_entity"},
  6. {"throwing:arrow_build", "throwing:arrow_build_entity"}
  7. }
  8. local throwing_shoot_arrow = function(itemstack, player)
  9. for _,arrow in ipairs(arrows) do
  10. if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
  11. if not minetest.setting_getbool("creative_mode") then
  12. player:get_inventory():remove_item("main", arrow[1])
  13. end
  14. local playerpos = player:getpos()
  15. local obj = minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2])
  16. local dir = player:get_look_dir()
  17. obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
  18. obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3})
  19. obj:setyaw(player:get_look_yaw()+math.pi)
  20. minetest.sound_play("throwing_sound", {pos=playerpos})
  21. if obj:get_luaentity().player == "" then
  22. obj:get_luaentity().player = player
  23. end
  24. obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
  25. return true
  26. end
  27. end
  28. return false
  29. end
  30. minetest.register_tool("throwing:bow_wood", {
  31. description = "Wood Bow",
  32. inventory_image = "throwing_bow_wood.png",
  33. stack_max = 1,
  34. on_use = function(itemstack, user, pointed_thing)
  35. if throwing_shoot_arrow(itemstack, user, pointed_thing) then
  36. if not minetest.setting_getbool("creative_mode") then
  37. itemstack:add_wear(65535/50)
  38. end
  39. end
  40. return itemstack
  41. end,
  42. })
  43. minetest.register_craft({
  44. output = 'throwing:bow_wood',
  45. recipe = {
  46. {'farming:string', 'group:wood', ''},
  47. {'farming:string', '', 'group:wood'},
  48. {'farming:string', 'group:wood', ''},
  49. }
  50. })
  51. minetest.register_tool("throwing:bow_stone", {
  52. description = "Stone Bow",
  53. inventory_image = "throwing_bow_stone.png",
  54. stack_max = 1,
  55. on_use = function(itemstack, user, pointed_thing)
  56. if throwing_shoot_arrow(item, user, pointed_thing) then
  57. if not minetest.setting_getbool("creative_mode") then
  58. itemstack:add_wear(65535/100)
  59. end
  60. end
  61. return itemstack
  62. end,
  63. })
  64. minetest.register_craft({
  65. output = 'throwing:bow_stone',
  66. recipe = {
  67. {'farming:string', 'default:cobble', ''},
  68. {'farming:string', '', 'default:cobble'},
  69. {'farming:string', 'default:cobble', ''},
  70. }
  71. })
  72. minetest.register_tool("throwing:bow_glass", {
  73. description = "Glass Bow",
  74. inventory_image = "throwing_bow_glass.png",
  75. stack_max = 2,
  76. on_use = function(itemstack, user, pointed_thing)
  77. if throwing_shoot_arrow(item, user, pointed_thing) then
  78. if not minetest.setting_getbool("creative_mode") then
  79. itemstack:add_wear(65535/75)
  80. end
  81. end
  82. return itemstack
  83. end,
  84. })
  85. minetest.register_craft({
  86. output = 'throwing:bow_glass',
  87. recipe = {
  88. {'farming:string', 'default:glass', ''},
  89. {'farming:string', '', 'default:glass'},
  90. {'farming:string', 'default:glass', ''},
  91. }
  92. })
  93. minetest.register_tool("throwing:bow_steel", {
  94. description = "Steel Bow",
  95. inventory_image = "throwing_bow_steel.png",
  96. stack_max = 1,
  97. on_use = function(itemstack, user, pointed_thing)
  98. if throwing_shoot_arrow(item, user, pointed_thing) then
  99. if not minetest.setting_getbool("creative_mode") then
  100. itemstack:add_wear(65535/200)
  101. end
  102. end
  103. return itemstack
  104. end,
  105. })
  106. minetest.register_craft({
  107. output = 'throwing:bow_steel',
  108. recipe = {
  109. {'farming:string', 'default:steel_ingot', ''},
  110. {'farming:string', '', 'default:steel_ingot'},
  111. {'farming:string', 'default:steel_ingot', ''},
  112. }
  113. })
  114. minetest.register_tool("throwing:bow_bronze", {
  115. description = "Bronze Bow",
  116. inventory_image = "throwing_bow_bronze.png",
  117. stack_max = 1,
  118. on_use = function(itemstack, user, pointed_thing)
  119. if throwing_shoot_arrow(item, user, pointed_thing) then
  120. if not minetest.setting_getbool("creative_mode") then
  121. itemstack:add_wear(65535/250)
  122. end
  123. end
  124. return itemstack
  125. end,
  126. })
  127. minetest.register_craft({
  128. output = 'throwing:bow_bronze',
  129. recipe = {
  130. {'farming:string', 'default:bronze_ingot', ''},
  131. {'farming:string', '', 'default:bronze_ingot'},
  132. {'farming:string', 'default:bronze_ingot', ''},
  133. }
  134. })
  135. dofile(minetest.get_modpath("throwing").."/arrow.lua")
  136. dofile(minetest.get_modpath("throwing").."/fire_arrow.lua")
  137. dofile(minetest.get_modpath("throwing").."/teleport_arrow.lua")
  138. dofile(minetest.get_modpath("throwing").."/dig_arrow.lua")
  139. dofile(minetest.get_modpath("throwing").."/build_arrow.lua")
  140. if minetest.setting_get("log_mods") then
  141. minetest.log("action", "throwing loaded")
  142. end