Custom Effects with Packet 0x3F

Discussion in 'Resources' started by MCForger, Mar 30, 2013.

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

    MCForger

    Hello,
    So today alkarin and I were playing around with this new Packet and we found out how to create effects that I thought was client side so here you go!
    Code:
    import java.lang.reflect.Field;
     
    import net.minecraft.server.v1_5_R2.Packet63WorldParticles;
     
    import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
     
    public class CustomEffect
    {
        public CustomEffect()
        {
     
        }
     
        public void createEffect(CraftPlayer player, String nameOfEffect, float playersX,
                float playersY, float playersZ, float xOffset, float yOffset,
                float zOffset, float effectSpeed, int amountOfParticles)
        {
            // Make an instance of the packet!
            Packet63WorldParticles sPacket = new Packet63WorldParticles();
            for (Field field : sPacket.getClass().getDeclaredFields())
            {
                try
                {
                    // Get those fields we need to be accessible!
                    field.setAccessible(true);
                    String fieldName = field.getName();
                    // Set them to what we want!
                    switch (fieldName)
                    {
                    case "a":
                        field.set(sPacket, name);
                        break;
                    case "b":
                        field.setFloat(sPacket, playersX);
                        break;
                    case "c":
                        field.setFloat(sPacket, playersY);
                        break;
                    case "d":
                        field.setFloat(sPacket, playersZ);
                        break;
                    case "e":
                        field.setFloat(sPacket, xOffset);
                        break;
                    case "f":
                        field.setFloat(sPacket, yOffset);
                        break;
                    case "g":
                        field.setFloat(sPacket, zOffset);
                        break;
                    case "h":
                        field.setFloat(sPacket, effectSpeed);
                        break;
                    case "i":
                        field.setInt(sPacket, amountOfParticles);
                        break;
                    }
                } catch (Exception e)
                {
                    player.sendMessage("Something went wrong....");
                    System.out.println(e.getMessage());
                }
            }
            player.getHandle().playerConnection.sendPacket(sPacket);
        }
    }
    The name of effects can be found here!
    My personal favorite effect is the "happyVillager". I like the emerald stars above a villager's head a lot!
     
    fromgate, iKeirNez, MehrPvM and 3 others like this.
  2. Offline

    DSH105

    +1 from me :D
    EDIT: Question. How would you set the data value of some of these effects? For example, "tilecrack_" or "iconcrack_". Would it be like "iconcrack_id"?
     
    MCForger likes this.
  3. Offline

    MCForger

    _DSH105_
    Have not played around with that a lot but I believe so.
    EDIT: Just tested it and yes that is how it works.
     
  4. Offline

    DSH105

    MCForger
    Alright. Seems easy enough. I'll have a play around with it.
     
  5. Offline

    stirante

    Some particles can also have diffrent colors. I haven't tested it yet but I think that speed in note particle is color.

    EDIT: I can confirm it in particles mob spell and mob spell ambient

    EDIT2: Class looks good but I think using Location instead of seperate x, y and z would be much better. I also would use vector instead of offset x, y and z but with seperate parameters it's ok. Remembering all particle names is kinda hard so I would use enum:
    Code:
    package com.stirante.ParticlesAPI;
     
    public enum ParticleType {
    LARGE_EXPLOSION("largeexplode"),
    FIREWORK_SPARK("fireworksSpark"),
    BUBBLE("bubble"),
    SUSPENDED("suspended"),
    DEPTH_SUSPEND("depthsuspend"),
    TOWN_AURA("townaura"),
    CRITICAL_HIT("crit"),
    MAGICAL_CRITICAL_HIT("magicCrit"),
    SMOKE("smoke"),
    MOB_SPELL("mobSpell"),
    MOB_SPELL_AMBIENT("mobSpellAmbient"),
    SPELL("spell"),
    INSTANT_SPELL("instantSpell"),
    WITCH_MAGIC("witchMagic"),
    NOTE("note"),
    PORTAL("portal"),
    ENCHANTMENT_TABLE("enchantmenttable"),
    EXPLODE("explode"),
    FLAME("flame"),
    LAVA("lava"),
    FOOTSTEP("footstep"),
    SPLASH("splash"),
    LARGE_SMOKE("largesmoke"),
    CLOUD("cloud"),
    REDSTONE("reddust"),
    SNOWBALL_POOF("snowballpoof"),
    DROP_WATER("dripWater"),
    DROP_LAVA("dripLava"),
    SNOW_SHOVEL("snowshovel"),
    SLIME("slime"),
    HEART("heart"),
    ANGRY_VILLAGER("angryVillager"),
    HAPPY_VILLAGER("happyVillager"),
    HUGE_EXPLOSION("hugeexplosion");
     
    private Stringid;
     
    private ParticleType(String name) {
    id = name;
    }
    public String getParticleName() {
    return id;
    }
    }
    I think method which sends this packet to all players in world or near players would be better than to 1 player becouse if you make loop wich will execute method for 1 player it will create soo many same packets. These are only my thougts. Feel free to ignore them xD

    EDIT3:I think i do too many edits. In tilecrack and itemcrack it's tilecrack_blockId_metadata and itemcrack_itemId
     
  6. What is the diffrence between the crit and the magicCrit (totally not offtopic :D)?
     
  7. Offline

    MCForger

    mncat77
    Honestly I don't see a difference =P
    stirante
    I actually made some of these changes before you posted and forgot to update it =P. We are making an effect library for BattleArena and such.
     
  8. Offline

    stirante

    Crit is normal particles when you do critical hit and magicCrit is when you do critical hit with enchanted sword. Particles are more blue.

    EDIT:I know it's annoying, but isn't it better when you'll use static methods? Otherwise many inexperienced devs will create a lot of instances.
     
    mncat77 likes this.
  9. Offline

    MCForger

    stirante
    I would not think an inexperienced dev would jump right into packets and reflection but of course I am most likely wrong =P. I hate using static methods so I make all my instances in my main class then get them through the main class like plugin.getCustomEffects() just a preference I have. Also this just shows an example of how to implement it in your own plugin and doesn't mean it has to have its own class.
     
  10. Offline

    danielmiles

    import net.minecraft.server.v1_5_R2.Packet63WorldParticles;
    where is the v1_5_R2 craftbukkit download? all i can find is v1_5_R1
     
  11. Offline

    MCForger

    danielmiles
    If your not experienced with packets do not try this and this build i was using was a beta build not a recommended.
     
  12. Offline

    stirante

    Haha, I was right xD
     
  13. Offline

    MCForger

    stirante
    I'm in disney world happiest place on earth and will ignore that lol. Good thing I did not make a bet with you :p
     
    stirante likes this.
  14. Offline

    danielmiles

    i am experienced enough to use packets but can i just get a link? all i was asking for. not to be judged...

    i just wanted a link -.-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  15. Offline

    MCForger

    Aengo likes this.
  16. Offline

    danielmiles

    Well thats kinda my bad... the download reads craftbukkit-1.5.1-R0.1
    so i assumed that would show "org.bukkit.craftbukkit.v1_5_R1.entity.CraftPlayer"
    but in reality when you go and look it has "org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer"

    which confused me, i thought u had a craftbukkit-1.5.1-R0.2
     
  17. Offline

    microgeek

    Heads up, this requires Java 7, as it uses String switch-case statements. =P
     
  18. Offline

    MCForger

    microgeek
    Can always change them to if statements as this was meant not to be a library rather a this is how you can do it.
     
  19. Offline

    DSH105

    Yep. Experienced devs should know how to change it anyway =P
     
    MCForger likes this.
  20. Offline

    microgeek

    Just stating a fact. =)
     
  21. Offline

    Shiny Quagsire

    There's actually a pull request that adds the ability to spawn these particles, however it hasn't been accepted yet. For now, this solution may provide the same effect as the pull request and is probably our best bet for spawning particles for now.
     
  22. Offline

    Ice3ider4

    Hey there I need some help with this Packet :S I'm really new to bukkit but I hope you still help me :)
    Code:java
    1.  
    2. Player p = (Player) cs;
    3. Location loc = (Location) p.getLocation();
    4. String effekt = "happyVillager";
    5. Float speed = (float) 100;
    6. int amount = 100;
    7.  
    8. float x = (float) p.getLocation().getX();
    9. float y = (float) p.getLocation().getY();
    10. float z = (float) p.getLocation().getZ();
    11.  
    12. createEffect((CraftPlayer) p, effekt, x, y, z, x, y, z, speed, amount);

    I know that there's something wrong with the coordinates. Thank you for your help :3
     
  23. Offline

    Nosliw

    I haven't looked to much into this, but looking at the variable names in the first post, the second x, y and z are an offset, this should be where you want the effect to be played relative to the player? I think that if you wanted to play the effect on the player you would do something like this:
    Code:java
    1. createEffect((CraftPlayer) p, effekt, x, y, z, 0, 0, 0, speed, amount);
     
    Ice3ider4 likes this.
  24. Offline

    Ice3ider4

    I still get an error:
    Code:
    22:59:55 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'effe
    kt' in plugin Effect v0.0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerCon
    nection.java:964)
            at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.j
    ava:882)
            at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    :839)
            at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
            at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    :118)
            at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    90)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.ClassCastException: org.bukkit.Location cannot be cast to j
    avax.tools.JavaFileManager$Location
            at de.Ice3ider4.Effect.Effect.onCommand(Effect.java:32)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more
    I think the X/Y/Z coordinates can't be casted to the float type but I'm not sure ): Thank you for your help
     
  25. Offline

    SoThatsIt

    you are right, you cannot use floats, instead you need to cast them to ints and times them by 32, not positive on 32 though may have to mess around with that, maybe 20
     
  26. Offline

    DSH105

    Ice3ider4
    Post your import list. According to the stacktrace there's an incorrect cast at line 32.
     
  27. Offline

    SoThatsIt

    yes, on the client side because he is sending a float instead of an integer
     
Thread Status:
Not open for further replies.

Share This Page