standard_arrows.lua 3.7 KB

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