dig_arrow.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. minetest.register_craftitem("throwing:arrow_dig", {
  2. description = "Dig Arrow",
  3. inventory_image = "throwing_arrow_dig.png",
  4. })
  5. minetest.register_node("throwing:arrow_dig_box", {
  6. drawtype = "nodebox",
  7. node_box = {
  8. type = "fixed",
  9. fixed = {
  10. -- Shaft
  11. {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
  12. --Spitze
  13. {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
  14. {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
  15. --Federn
  16. {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
  17. {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
  18. {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
  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, 8.5/17, 3.5/17, 3.5/17},
  21. {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
  22. {8.5/17, 3.5/17, -3.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. }
  25. },
  26. tiles = {"throwing_arrow_dig.png", "throwing_arrow_dig.png", "throwing_arrow_dig_back.png", "throwing_arrow_dig_front.png", "throwing_arrow_dig_2.png", "throwing_arrow_dig.png"},
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local THROWING_ARROW_ENTITY={
  30. physical = false,
  31. timer=0,
  32. visual = "wielditem",
  33. visual_size = {x=0.1, y=0.1},
  34. textures = {"throwing:arrow_dig_box"},
  35. lastpos={},
  36. collisionbox = {0,0,0,0,0,0},
  37. }
  38. THROWING_ARROW_ENTITY.on_step = function(self, dtime)
  39. self.timer=self.timer+dtime
  40. local pos = self.object:getpos()
  41. local node = minetest.env:get_node(pos)
  42. if self.timer>0.2 then
  43. local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
  44. for k, obj in pairs(objs) do
  45. if obj:get_luaentity() ~= nil then
  46. if obj:get_luaentity().name ~= "throwing:arrow_dig_entity" and obj:get_luaentity().name ~= "__builtin:item" then
  47. minetest.env:add_item(pos, 'throwing:arrow_dig')
  48. minetest.env:remove_node(pos)
  49. self.object:remove()
  50. end
  51. else
  52. minetest.env:add_item(pos, 'throwing:arrow_dig')
  53. minetest.env:remove_node(pos)
  54. self.object:remove()
  55. end
  56. end
  57. end
  58. if self.lastpos.x~=nil then
  59. if node.name ~= "air" then
  60. minetest.env:add_item(self.lastpos, 'throwing:arrow_dig')
  61. minetest.env:remove_node(pos)
  62. self.object:remove()
  63. end
  64. end
  65. self.lastpos={x=pos.x, y=pos.y, z=pos.z}
  66. end
  67. minetest.register_entity("throwing:arrow_dig_entity", THROWING_ARROW_ENTITY)
  68. minetest.register_craft({
  69. output = 'throwing:arrow_dig',
  70. recipe = {
  71. {'default:stick', 'default:stick', 'default:pick_steel'},
  72. }
  73. })