Resource Helix Tutorial Particle Effect 1

Discussion in 'Spigot Plugin Development' started by HeroVerseWizard, May 27, 2017.

  1. Particle Lesson #1 (Helix)

    WARNING:
    This particle movement code is a little too advanced or intermediate, I recommend you learning plugin basics first or if you can handle through it, you can surely have a go!
    I normally use Darkblade12's Particle Lib but i used packets for these Ill ad the Library version soon as well"


    The Start of a new journey!

    So this is my first particle movement, tutorial, using maths to make cool effects!
    This is a basic helix created by sin and cos to make this effect. So there will be more of these tutorials so stay tuned ^-^ !!!

    [​IMG]
    As we can see the parametric equation is already there and we just need to manipulate it to suit our needs.

    1) We create a new method:
    Code (Java):
    public class SpiralHelix extends JavaPlugin {

            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

                if(cmd.getName().equalsIgnoreCase("particle")){
                    Player player= (Player) sender;
                             createHelix(player);
                }
    Explanation:
    So the class is called "SpiralHelix" but you can rename it to your favorable class name. We extended JavaPlugin to show Java and Bukkit that we are making a Java Plugin. the next Public Boolean.... and onward is the basic command sender such as "/kill <args>", after that we are creating a command called "particle" so whenever we give this command, we are gonna execute the plugin movement which we are gonna do next! The Player player = (Player) sender;" is there because it is checking the player who sends it!
    The "createHelix(player);" will be used for later purposes.
    There are many ways to trigger the particle method such as right clicking air or certain blocks, and there are tons of them. But as this being basic I'll go through this.



    2) We create a method which will get the player's coordinates:
    Code (Java):
    public void createHelix(Player player) {
                Location loc = player.getLocation();
    Explanation:
    So here we are getting the player Coordinates for spawning the particle and this will be the method where we are gonna span in the particles and send the players as packets.

    3) We create the equation!
    Code (Java):
     int radius = 2;
                for(double y = 0; y <= 50; y+=0.05) {
                    double x = radius * Math.cos(y);
                    double z = radius * Math.sin(y);
    Explanation:
    So this is the typical part... If you weren't smart or weren't bothered listening in the maths class this is gonna be your worst nightmare. As we can see maths can create awesome particle movements and Minecraft can execute it on the 3D plane! This will later get added in the "createHelix()" method.

    4) We send the players the packets!
    Code (Java):
     PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
                    for(Player online : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
                    }
    Explanation:
    So this is the packet sending code which will send the packets to all online players and also the part where you say, "EnumParticle.BARRIER" you can change the particle type. This code can be change just replacing "BARRIERS" with something else like "FLAME".

    5) The Finale!
    Code (Java):
    public class Core extends JavaPlugin {
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

                if(cmd.getName().equalsIgnoreCase("herowise")){
                    Player player= (Player) sender;
         
                    createHelix(player);
                }
     
            return false;}
            public void createHelix(Player player) {
                Location loc = player.getLocation();
                int radius = 2;
                for(double y = 0; y <= 50; y+=0.05) {
                    double x = radius * Math.cos(y);
                    double z = radius * Math.sin(y);
                    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
                    for(Player online : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
                    }
                }}
    Explanation:
    Nothing to explain here but this the class where we accumulated and summed up all the code we did earlier.

    If you find any errors you surely can tell me to fix them or if you want me to make it easier to explain them.

    If you enjoyed this or learned something you surely can comment ^-^ and it will be appreciated and I'm glad if I taught you something new!

    [​IMG]
    This is one of the maths and the reason behind the helix using 3D plane!



    Minecraft Screenshots:

    Helix : Barrier_Blocks:
    [​IMG]


    Helix : Flame (Radius is shortened to look a more aesthetic way):
    [​IMG]




    Nest Lesson (Comment on which one you wanna see first!):

    Butterfly Curve (How to implement it):
    [​IMG]
    or

    Flame wrapping effect (Mineplex+ has dank animations):

    [​IMG]

    I also recommend reading through @finnbon 's resources on these.




    TODO:
    Use DarkBlade12's Library for spawning particles, (RGB Model would be there as well)
     
    #1 HeroVerseWizard, May 27, 2017
    Last edited: May 28, 2017
    • Like x 8
    • Informative x 5
    • Winner x 1
    • Useful x 1
    • Creative x 1
  2. The colours though can seriously injure someone's eyes xd

    I will change the colours whn I wake up ;p


    UPDATE: Changed the colours of the resources so you all dont go to the hospital
     
    #2 HeroVerseWizard, May 27, 2017
    Last edited: May 28, 2017
    • Like Like x 2
    • Agree Agree x 2