arrows.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. lottpotion.register_arrow = function(potion_name, name, hname, potion_use_funct, desc, img)
  2. minetest.register_craftitem(potion_name.."_arrow", {
  3. description = "Potion Arrow: "..desc,
  4. inventory_image = img.."^lottthrowing_arrow.png",
  5. groups = {},
  6. })
  7. local THROWING_ARROW_ENTITY={
  8. physical = false,
  9. timer=0,
  10. visual = "wielditem",
  11. visual_size = {x=0.1, y=0.1},
  12. textures = {"lottthrowing:arrow_box"},
  13. lastpos={},
  14. collisionbox = {0,0,0,0,0,0},
  15. }
  16. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  17. self.timer=self.timer+dtime
  18. local pos = self.object:getpos()
  19. local node = minetest.get_node(pos)
  20. if self.timer>0.2 then
  21. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  22. for k, obj in pairs(objs) do
  23. if obj:get_luaentity() ~= nil then
  24. if obj:get_luaentity().name ~= potion_name.."_arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then
  25. local damage = 20
  26. obj:punch(self.player, 1.0, {
  27. full_punch_interval=1.0,
  28. damage_groups={fleshy=damage},
  29. }, nil)
  30. self.object:remove()
  31. end
  32. else
  33. potion_use_funct({take_item = function()end}, obj)
  34. self.object:remove()
  35. end
  36. end
  37. end
  38. if self.lastpos.x~=nil then
  39. if node.name ~= "air" then
  40. self.object:remove()
  41. end
  42. end
  43. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  44. end
  45. minetest.register_entity(potion_name.."_arrow_entity", THROWING_ARROW_ENTITY)
  46. minetest.register_craft({
  47. output = potion_name.."_arrow",
  48. recipe = {
  49. {'lottthrowing:arrow', potion_name},
  50. }
  51. })
  52. arrows[#arrows+1] = {potion_name.."_arrow", potion_name.."_arrow_entity"}
  53. end