Tutorial Creating a helix / 3d spiral out of particles

Discussion in 'Resources' started by Skionz, Sep 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Skionz

  2. Offline

    ChipDev

    Pretty long post, but lets show this off.
    Using ParticleEffect lib by DarkBladee12 , You are able to spawn particles but not in a helix (Because some may not want any Y change) - But that would not let the cosine/sin change due to the Y not changing.

    The solution is having a double as *Hight* and putting a runnable that does it every x ticks.
    (The runnable and on-enable is totally just an example!)
    Code:java
    1. public void onEnable() {
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. @Override
    4. public void run() {
    5. for(Double y = player.getEyeLocation().getY();
    6. // ^ start of loop is at the eye location.
    7. y < player.getEyeLocation().getY() + 6.0;
    8. //^ Y loops up 6 blocks above (We will subtract later)
    9. y+= 0.06) {
    10. //^ Up Y by 0.06 for a good amount of particles. Do some math and this is 100 particles. (6 / 0.06)
    11. }
    12. }
    13. },(long) 0, (long)2);
    14. }

    Now that we have that double, we will get some basic cosine (X) and sin (Z) features.
    Code:java
    1. public void onEnable() {
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. @Override
    4. public void run() {
    5. for(Double y = player.getEyeLocation().getY();
    6. y < player.getEyeLocation().getY() + 6.0;
    7. y+= 0.06) {
    8. Double xcos = Math.cos(y) * 0.8;
    9. // ^ Getting the X coordinate (well, adding it)
    10. Double zcos = Math.sin(y) * 0.8;
    11. // ^ Z coord
    12. }
    13. }
    14. },(long) 0, (long)2);
    15. }

    Then...
    Code:java
    1. public void onEnable() {
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. @Override
    4. public void run() {
    5. for(Double y = player.getEyeLocation().getY();
    6. y < player.getEyeLocation().getY() + 6.0;
    7. y+= 0.06) {
    8. Double xcos = Math.cos(y) * 0.6;
    9. Double zcos = Math.sin(y) * 0.6;
    10. this.newloc = new Location(player.getWorld(), player.getLocation().getX() + xcos, y - diff + 0.7, player.getLocation().getZ() + zcos);
    11. //We added a static variable at the start of the code
    12. //So now we can store and edit the variable from other
    13. //classes!
    14. //NOTE: why + 0.7? Its just adding a little Y to the location,
    15. // so it Isn't blocking the player's eyes.
    16. ParticleEffect.FIREWORKS_SPARK.display((float) 0.0, (float)0.0, (float)0.0, (float)0.0, 1, newloc, 16);
    17. //Spawns particle effects
    18. }
    19. }
    20. },(long) 0, (long)2);
    21. }

    That adds cos + X and sin + Z and subtracts Y to its regular amount, Yes java, you just got loopholed!
    And theres it. we have this really nice hula effect you can probably sell for $5, and it looks awesome. Heres what it looks like!:
    [​IMG]

    And then, you can change some raidus stuff Z = * 0.4 and X = * 0.8 (With flame) and it will look like a oval!
    [​IMG]
    Dat style! And then... *Drumrole... - And all the possibilities with randoms..
    Havin a bad day?

    2014-11-01_14.20.42.png
    These are some ideas for particles; the ideas are endless!
    Thanks for reading. and always thank Skionz!
     
  3. Offline

    BurnerDiamond

    @Skionz

    is it possibile to check if an arrow, hits your helix?

    If so with a couple a randoms and a couple of teams, a grat mini game is born!

    //////////////////////////////

    Even better can you imagine a space invaders game with these helix's pulling you up to the sky?
     
    Last edited: Mar 1, 2015
  4. Offline

    Skionz

    You would have to store each particle's location and constantly check the arrow's location so it would probably be bad idea.
     
  5. Offline

    BurnerDiamond

    Damn, oh well maybe particles are just made to look nice!
     
    Skionz likes this.
  6. Offline

    Finn_Bueno_

    Could you tell me how to make it into a tornado ? :D
     
  7. Offline

    Skionz

    Increase the radius.
     
  8. Offline

    Finn_Bueno_

    The way you did it, didn't work for me =/
    I did what @ChipDev did, but I would like to know how to make a tornado using That code. :)
    (Nothing against the way you did it, it just didn't work :p)
     
    ChipDev likes this.
  9. Offline

    Msrules123

    EDIT: Nevermind. Wrong information on my part.
     
    Last edited: Mar 25, 2015
  10. Offline

    Concar123

    um im a derp and i need help doing this....... im using IntelliJ and half of the things you guys put in your code, dont work for me....
     
  11. Offline

    ChipDev

    Show me some errors or a screenshot please.. Did you import the ParticleEffect LIB?
     
  12. Offline

    teej107

    @ChipDev Hey, you're back!

    @Concar123 We can't help you without a more detailed description of why it doesn't work.
     
  13. Offline

    ChipDev

    Hey, I am back :) Thanks!
     
  14. Offline

    Concar123

    im sorry xD when im on ubuntu my internet jacks up hang on xD ill post a screenshot as soon as i can fricking get my ubuntu to stop being a bunghole xD
     
  15. Code:
                PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles("fireworksSpark", (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
    Error: http://prntscr.com/6t2zcj
     
  16. Offline

    Skionz

    That constructor does not exist. Use the correct one corresponding to the version of CraftBukkit you are using.
     
  17. Offline

    plisov

    Does this still work? When I try to code this, the new PacketPlayOutWorldParticles("fireworksSpark", (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1); becomes red and asks me to remove everything BUT new PacketPlayOutWorldParticles(). I have ProtocolLib in my build path. Please help
     
  18. Offline

    Skionz

    ProtocolLib is not required. Use the correct constructor corresponding to the version of CraftBukkit you are using.
     
  19. Offline

    Concar123

    Um... I figured out my problem but can anyone show me code for like an item that would activate it? like a gadget xD and also to make the firework spark a different color... how would i do that? im sort of new to bukkit xD
     
  20. Offline

    ChipDev

    Why overuse xD?These basics should be learned before trying that.
     
  21. Offline

    Jimfutsu

    Hey, just a quick question, how would you go about compacting the helix?
     
  22. Invisible

    nverdier

    Last edited by a moderator: Jun 26, 2015
  23. Offline

    MCTV

    guys how would i make the helix shoot in a direction? im having trouble using the direction vector ;( and where to put it
     
  24. Offline

    Misteroid

    @Skionz will this work with 1.8.7
     
  25. Offline

    Skionz

    Yes, assuming you use the new PacketPlayOutWorldParticles constructor.
     
  26. Offline

    Misteroid

    Do u know how to use it? I dont :/
     
  27. Offline

    Skionz

    Create an instance of it, and invoke PlayerConnection#sendPacket(Packet).
     
  28. Offline

    xXCapzXx

    ^^
    I need this...

    This code makes 1 swirl around my body, but how do I make it like @ChipDev tornado?
    Code:
    package me.capz.helix;
    
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    import de.slikey.effectlib.EffectLib;
    import de.slikey.effectlib.EffectManager;
    import de.slikey.effectlib.effect.AnimatedBallEffect;
    import de.slikey.effectlib.util.ParticleEffect;
    
    public class version2 extends JavaPlugin {
    
        EffectManager em;
    
        public void onEnable() {
             
               EffectLib lib = EffectLib.instance();
               em = new EffectManager(lib);
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
            if(cmd.getLabel().equalsIgnoreCase("flamey")) {
                    Player player= (Player)sender;
                    flamey(player);
           
                   
            }
            return true;
        }
       
        private void flamey(Player player) {
            Location l = player.getLocation();
            Vector vector = new Vector();
            double radius = Math.PI;
            double maxHeight = 10;
            for(int i1 = 0; i1 < 1; i1++) {
                for(Double y = player.getEyeLocation().getY(); y >= 20; y += 0.06) {
               double x = 2 *  Math.cos(y) * 0.8; // Basically it is saying 3 * Math.cosine and sine, to make a helix around eachother.
               double z = 2 * Math.sin(y) * 0.4;   
           
            net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles packet = new net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles("flame",
                                ((float) (l.getX() + x)), 
                                ((float) (l.getY() + y)),
                                ((float) (l.getZ() + z)),
                                0, 0, 0, 0, 1);
           
           
           
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
        }
        }
       
    }
    
    
    I want it to be more compact so it can be a tornado

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  29. Offline

    ChipDev

    Can you send me a video or .gif of the effects?
     
  30. Offline

    xXCapzXx

    This is the proper code:
    Code:
    package me.capz.helix;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    
    import de.slikey.effectlib.EffectLib;
    import de.slikey.effectlib.EffectManager;
    import de.slikey.effectlib.effect.AnimatedBallEffect;
    import de.slikey.effectlib.util.ParticleEffect;
    
    public class version2 extends JavaPlugin implements Listener{
    
        
        public void onEnable() {
    
                }
      
        public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) {
            if(cmd.getLabel().equalsIgnoreCase("flamey")) {
                    Player player= (Player)sender;
                    flamey(player);
                  
    
                  
            }
            return true;
        }
      
        private void flamey(Player player) {
            Location l = player.getLocation();
            double radius = 2;
            for(int i1 = 0; i1 < 20; i1++) {
            for(double y = 0; y < 20; y+= 0.05) {
               double x =  Math.cos(y * radius);
               double z =  Math.sin(y * radius);  
          
            net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles packet = new net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles("flame",
                                ((float) (l.getX() + x)),
                                ((float) (l.getY() + y)),
                                ((float) (l.getZ() + z)),
                                0, 0, 0, 1, 0);
          
          
          
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
        }
          
          
          
            }
      
    
        }
    
    
    When you do /flamey it will create a helix that goes 20 blocks high, but I want it to be more compact and more like a tornado.

    It is the code from this video:
     
Thread Status:
Not open for further replies.

Share This Page