rainbow_staff.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --rainbow!
  2. minetest.register_entity("nssm:rainbow", {
  3. textures = {"transparent.png"},
  4. velocity = 10,
  5. hp_max = 50,
  6. on_step = function (self, pos, node, dtime)
  7. self.timer = self.timer or os.time()
  8. local pos = self.object:get_pos()
  9. if minetest.is_protected(pos, "") then
  10. return
  11. end
  12. if os.time() - self.timer > 10 then
  13. minetest.set_node(pos, {name="nyancat:nyancat"})
  14. self.object:remove()
  15. end
  16. if minetest.get_node(pos) then
  17. local n = minetest.get_node(pos).name
  18. if n ~= "nyancat:nyancat_rainbow" then
  19. if n=="air" then
  20. minetest.set_node(pos, {name="nyancat:nyancat_rainbow"})
  21. else
  22. minetest.chat_send_all("Nome:"..n)
  23. minetest.set_node(pos, {name="nyancat:nyancat"})
  24. self.object:remove()
  25. end
  26. end
  27. end
  28. end
  29. })
  30. minetest.register_tool("nssm:rainbow_staff", {
  31. description = "Rainbow Staff",
  32. inventory_image = "rainbow_staff.png",
  33. on_use = function(itemstack, placer, pointed_thing)
  34. local dir = placer:get_look_dir();
  35. local playerpos = placer:get_pos();
  36. local obj = minetest.add_entity({x=playerpos.x+0+dir.x,y=playerpos.y+2+dir.y,z=playerpos.z+0+dir.z}, "nssm:rainbow")
  37. local vec = {x=dir.x*6,y=dir.y*6,z=dir.z*6}
  38. obj:set_velocity(vec)
  39. return itemstack
  40. end,
  41. groups = {not_in_creative_inventory=1,}
  42. })