ParticleCommands.java 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package me.km.snuviscript.commands;
  2. import me.hammerle.snuviscript.code.ScriptManager;
  3. import me.km.utils.Location;
  4. import me.km.utils.Mapper;
  5. import net.minecraft.item.ItemStack;
  6. import net.minecraft.particles.*;
  7. import net.minecraft.world.server.ServerWorld;
  8. public class ParticleCommands {
  9. public static void registerFunctions(ScriptManager sm) {
  10. sm.registerFunction("particle.get", (sc, in) -> {
  11. IParticleData data = Mapper.getParticle(in[0].getString(sc));
  12. if(data == ParticleTypes.BLOCK || data == ParticleTypes.FALLING_DUST) {
  13. data = new BlockParticleData((ParticleType<BlockParticleData>) data, Mapper.getBlock(in[1].getString(sc)).getDefaultState());
  14. } else if(data == ParticleTypes.DUST) {
  15. data = new RedstoneParticleData(in[1].getFloat(sc), in[2].getFloat(sc), in[3].getFloat(sc), in[4].getFloat(sc));
  16. } else if(data == ParticleTypes.ITEM) {
  17. data = new ItemParticleData((ParticleType<ItemParticleData>) data, new ItemStack(Mapper.getItem(in[1].getString(sc))));
  18. }
  19. return data;
  20. });
  21. sm.registerConsumer("particle.spawn", (sc, in) -> {
  22. Location l = ((Location) in[0].get(sc));
  23. IParticleData data = ((IParticleData) in[1].get(sc));
  24. int count = in.length >= 3 ? in[2].getInt(sc) : 1;
  25. double speed = in.length >= 4 ? in[3].getDouble(sc) : 0.0;
  26. double offX = in.length >= 5 ? in[4].getDouble(sc) : 0.0;
  27. double offY = in.length >= 6 ? in[5].getDouble(sc) : 0.0;
  28. double offZ = in.length >= 7 ? in[6].getDouble(sc) : 0.0;
  29. ((ServerWorld) l.getWorld()).spawnParticle(data, l.getX(), l.getY(), l.getZ(), count, offX, offY, offZ, speed);
  30. });
  31. sm.registerConsumer("particle.spawncircle", (sc, in) -> {
  32. Location l = ((Location) in[0].get(sc));
  33. IParticleData data = ((IParticleData) in[1].get(sc));
  34. int instances = in[2].getInt(sc);
  35. double radius = in[3].getDouble(sc);
  36. int count = in.length >= 5 ? in[4].getInt(sc) : 1;
  37. double speed = in.length >= 6 ? in[5].getDouble(sc) : 0.0;
  38. double offX = in.length >= 7 ? in[6].getDouble(sc) : 0.0;
  39. double offY = in.length >= 8 ? in[7].getDouble(sc) : 0.0;
  40. double offZ = in.length >= 9 ? in[8].getDouble(sc) : 0.0;
  41. double x = l.getX();
  42. double y = l.getY();
  43. double z = l.getZ();
  44. ServerWorld sw = (ServerWorld) l.getWorld();
  45. double angle = 2 * Math.PI / instances;
  46. for(int i = 0; i < instances; i++) {
  47. sw.spawnParticle(data, x + Math.cos(i * angle) * radius, y, z + Math.sin(i * angle) * radius, count, offX, offY, offZ, speed);
  48. }
  49. });
  50. sm.registerConsumer("particle.spawnline", (sc, in) -> {
  51. Location l = ((Location) in[0].get(sc));
  52. IParticleData data = ((IParticleData) in[1].get(sc));
  53. int instances = in[2].getInt(sc);
  54. double stepX = in[3].getDouble(sc);
  55. double stepY = in[4].getDouble(sc);
  56. double stepZ = in[5].getDouble(sc);
  57. int count = in.length >= 7 ? in[6].getInt(sc) : 1;
  58. double speed = in.length >= 8 ? in[7].getDouble(sc) : 0.0;
  59. double offX = in.length >= 9 ? in[8].getDouble(sc) : 0.0;
  60. double offY = in.length >= 10 ? in[9].getDouble(sc) : 0.0;
  61. double offZ = in.length >= 11 ? in[10].getDouble(sc) : 0.0;
  62. double x = l.getX();
  63. double y = l.getY();
  64. double z = l.getZ();
  65. ServerWorld sw = (ServerWorld) l.getWorld();
  66. for(int i = 0; i < instances; i++) {
  67. sw.spawnParticle(data, x + i * stepX, y + i * stepY, z + i * stepZ, count, offX, offY, offZ, speed);
  68. }
  69. });
  70. }
  71. }