particles.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local function spawn_clip_test_particle(pos)
  2. core.add_particle({
  3. pos = pos,
  4. size = 5,
  5. expirationtime = 10,
  6. texture = {
  7. name = "testtools_particle_clip.png",
  8. blend = "clip",
  9. },
  10. })
  11. end
  12. core.register_tool("testtools:particle_spawner", {
  13. description = table.concat({
  14. "Particle Spawner",
  15. "Punch: Spawn random test particle",
  16. "Place: Spawn clip test particle",
  17. }, "\n"),
  18. inventory_image = "testtools_particle_spawner.png",
  19. groups = { testtool = 1, disable_repair = 1 },
  20. on_use = function(itemstack, user, pointed_thing)
  21. local pos = core.get_pointed_thing_position(pointed_thing, true)
  22. if pos == nil then
  23. pos = assert(user):get_pos()
  24. end
  25. pos = vector.add(pos, {x=0, y=0.5, z=0})
  26. local tex, anim
  27. if math.random(0, 1) == 0 then
  28. tex = "testtools_particle_sheet.png"
  29. anim = {type="sheet_2d", frames_w=3, frames_h=2, frame_length=0.5}
  30. else
  31. tex = "testtools_particle_vertical.png"
  32. anim = {type="vertical_frames", aspect_w=16, aspect_h=16, length=3.3}
  33. end
  34. core.add_particle({
  35. pos = pos,
  36. velocity = {x=0, y=0, z=0},
  37. acceleration = {x=0, y=0.04, z=0},
  38. expirationtime = 6,
  39. collisiondetection = true,
  40. texture = tex,
  41. animation = anim,
  42. size = 4,
  43. glow = math.random(0, 5),
  44. })
  45. end,
  46. on_place = function(itemstack, user, pointed_thing)
  47. local pos = assert(core.get_pointed_thing_position(pointed_thing, true))
  48. spawn_clip_test_particle(pos)
  49. end,
  50. on_secondary_use = function(_, user)
  51. spawn_clip_test_particle(assert(user):get_pos())
  52. end,
  53. })