marker.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. jumpdrive.show_marker = function(pos, radius, color, center_color)
  2. local entity = "jumpdrive:marker_" .. color
  3. local center_entity = "jumpdrive:marker_" .. (center_color or "blue")
  4. minetest.add_entity(pos, center_entity)
  5. minetest.add_entity({x=pos.x+radius, y=pos.y+radius, z=pos.z+radius}, entity)
  6. minetest.add_entity({x=pos.x-radius, y=pos.y+radius, z=pos.z+radius}, entity)
  7. minetest.add_entity({x=pos.x+radius, y=pos.y+radius, z=pos.z-radius}, entity)
  8. minetest.add_entity({x=pos.x-radius, y=pos.y+radius, z=pos.z-radius}, entity)
  9. minetest.add_entity({x=pos.x+radius, y=pos.y-radius, z=pos.z+radius}, entity)
  10. minetest.add_entity({x=pos.x-radius, y=pos.y-radius, z=pos.z+radius}, entity)
  11. minetest.add_entity({x=pos.x+radius, y=pos.y-radius, z=pos.z-radius}, entity)
  12. minetest.add_entity({x=pos.x-radius, y=pos.y-radius, z=pos.z-radius}, entity)
  13. end
  14. local register_marker = function(color)
  15. local texture = "marker_" .. color .. ".png"
  16. minetest.register_entity("jumpdrive:marker_" .. color, {
  17. initial_properties = {
  18. visual = "cube",
  19. visual_size = {x=1.05, y=1.05},
  20. static_save = false,
  21. textures = {
  22. texture,
  23. texture,
  24. texture,
  25. texture,
  26. texture,
  27. texture
  28. },
  29. collisionbox = {-0.525, -0.525, -0.525, 0.525, 0.525, 0.525},
  30. physical = false,
  31. },
  32. on_activate = function(self, staticdata)
  33. minetest.after(8.0, function() self.object:remove() end)
  34. end,
  35. on_rightclick=function(self, clicker)
  36. self.object:remove()
  37. end,
  38. on_punch = function(self, hitter)
  39. self.object:remove()
  40. end,
  41. })
  42. end
  43. register_marker("red")
  44. register_marker("green")
  45. register_marker("blue")