standard_arrows.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. -- Localize for performance.
  2. local math_random = math.random
  3. function throwing_register_arrow_standard (kind, desc, eq, toughness, craft, craftcount)
  4. minetest.register_craftitem("throwing:arrow_" .. kind, {
  5. description = desc .. " Arrow",
  6. inventory_image = "throwing_arrow_" .. kind .. ".png",
  7. })
  8. minetest.register_node("throwing:arrow_" .. kind .. "_box", {
  9. drawtype = "nodebox",
  10. node_box = {
  11. type = "fixed",
  12. fixed = {
  13. -- Shaft
  14. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  15. --Spitze
  16. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  17. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  18. --Federn
  19. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  20. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  21. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  22. {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
  23. {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
  24. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  25. {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
  26. {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
  27. }
  28. },
  29. tiles = {"throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. ".png", "throwing_arrow_" .. kind .. "_back.png", "throwing_arrow_" .. kind .. "_front.png", "throwing_arrow_" .. kind .. "_2.png", "throwing_arrow_" .. kind .. ".png"},
  30. groups = {not_in_creative_inventory=1},
  31. })
  32. local THROWING_ARROW_ENTITY = {
  33. _name = "throwing:arrow_" .. kind,
  34. physical = false,
  35. timer=0,
  36. visual = "wielditem",
  37. visual_size = {x=0.1, y=0.1},
  38. textures = {"throwing:arrow_" .. kind .. "_box"},
  39. lastpos={},
  40. collisionbox = {0,0,0,0,0,0},
  41. }
  42. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  43. self.timer=self.timer+dtime
  44. local pos = self.object:get_pos()
  45. local node = minetest.get_node(pos)
  46. if self.timer>0.2 then
  47. local vel = self.object:get_velocity()
  48. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  49. for k, obj in pairs(objs) do
  50. if obj:get_luaentity() ~= nil then
  51. local oname = obj:get_luaentity().name
  52. if not throwing.entity_blocks_arrow(oname) then
  53. local speed = vector.length(vel)
  54. local damage = ((speed + eq)^1.2)/10
  55. throwing_arrow_punch_entity(obj, self, damage)
  56. self.object:remove()
  57. end
  58. elseif obj:is_player() then
  59. local speed = vector.length(vel)
  60. local damage = ((speed + eq)^1.2)/10
  61. throwing_arrow_punch_entity(obj, self, damage)
  62. self.object:remove()
  63. end
  64. end
  65. end
  66. if self.lastpos.x~=nil then
  67. if throwing_node_should_block_arrow(node.name) then
  68. self.object:remove()
  69. if math_random() < toughness then
  70. minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
  71. else
  72. minetest.add_item(self.lastpos, 'default:stick')
  73. end
  74. end
  75. end
  76. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  77. end
  78. minetest.register_entity("throwing:arrow_" .. kind .. "_entity", THROWING_ARROW_ENTITY)
  79. if not craftcount then
  80. craftcount = 16
  81. end
  82. minetest.register_craft({
  83. output = 'throwing:arrow_' .. kind .. ' ' .. craftcount,
  84. recipe = {
  85. {'default:stick', 'default:stick', craft},
  86. }
  87. })
  88. minetest.register_craft({
  89. output = 'throwing:arrow_' .. kind .. ' ' .. craftcount,
  90. recipe = {
  91. {craft, 'default:stick', 'default:stick'},
  92. }
  93. })
  94. end
  95. if not DISABLE_STONE_ARROW then
  96. throwing_register_arrow_standard ('stone', 'Stone', 5, 0.88, 'default:cobble')
  97. end
  98. if not DISABLE_STEEL_ARROW then
  99. throwing_register_arrow_standard ('steel', 'Steel', 15, 0.94, 'default:steel_ingot')
  100. end
  101. if not DISABLE_DIAMOND_ARROW then
  102. throwing_register_arrow_standard ('diamond', 'Diamond', 25, 0.97, 'dusts:diamond_shard', 2)
  103. end
  104. if not DISABLE_OBSIDIAN_ARROW then
  105. throwing_register_arrow_standard ('obsidian', 'Obsidian', 20, 0.88, 'default:obsidian_shard', 2)
  106. end