[Tutorial] How to make particle trails - (For wands/spells)

Discussion in 'Resources' started by Windy Day, Jan 3, 2014.

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

    Windy Day

    Alright, good luck.
     
  2. Offline

    terturlcraft

    This does not seem to work for me?
     
  3. Offline

    Windy Day

    Make sure you are using the correct craftbukkit version. Otherwise run through the tutorial again and double check you are doing stuff correctly. I can't help you much if you just say it doesn't work.
     
  4. Offline

    guitargun

    @Windy Day if I want to make a 3 block wide line how do I do that?
    I have this part of the code:
    Code:
        public void drawline(Player player) {
    
            //loc.getBlock().getRelative()
            Location location = player.getLocation();
            location.setPitch(0);
            BlockIterator blocksToAdd = new BlockIterator(location, 0, 10);
            Location blockToAdd;
                while(blocksToAdd.hasNext()) {
                    blockToAdd = blocksToAdd.next().getLocation();
                    ParticleEffect.CLOUD.display(0, 0, 0, 0, 100, blockToAdd, 50D);
                }
          }
     
  5. Offline

    Windy Day

    Getting a sphere of locations around each point as you iterate through and playing an effect would work well. Otherwise, calculating nine different block iterators and playing effects would work too.
     
  6. Offline

    guitargun

    @Windy Day thx. I completed it with this :
    Code:
            ArrayList<Location> alllocs = new ArrayList<Location>();
            while (blocksToAdd.hasNext()) {
                blockToAdd = blocksToAdd.next().getLocation();
                alllocs.add(blockToAdd);
                List<Location> neighbours = buildCircle(blockToAdd, 2);
                for (Location l : neighbours) {
                    if (l.distance(location) < 10) {
                        l.setY(location.getY());
                        if (!alllocs.contains(l)) {
                            alllocs.add(l);
                        }
                    }
                }
    
            }
     
  7. Offline

    20zinnm

    I'd highly recommend using Metadata. Take the burden off of the plugin. I'm working on something similar to this, and I'll definitely be adapting your particle effect system to fit it, but I'll be using Metadata to reduce overhead and increase reliability.
     
  8. Offline

    MrShnig

    Hey, I know this is a really, really old thread, but I just can't seem to get it to work properly for 1.8.8 bukkit. I know the tutorial was made for an older version, but it's so far the thing I'm looking for except isn't compatible.

    I have two problems in the "particle(PlayerInteractEvent e) { ... }"

    I don't know how to properly define the "player" variable, and it doesn't register the projectile in
    ... ||!shotprojectiledata.containsKey(projectile)) ...

    Please could you correct my code or tell me how to fix it?
    Here's my code:
    Code:
    package me.mrshnig;
    
    import java.util.HashMap;
    import java.util.WeakHashMap;
    
    import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSnowball;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.BlockIterator;
    
    public class TrailLobber extends JavaPlugin {
      
        public final static WeakHashMap<Entity, EntityData> shotprojectiledata = new WeakHashMap<Entity, EntityData>();
      
        public class EntityData {
          
            private Location firedfrom;
            private Integer range;
            private Double damage;
            //constructor
            public EntityData(Location loc, Integer range, Double damage) {
              
                this.firedfrom = loc;
                this.range = range;
                this.damage = damage;
              
            }
          
            public Location getFiredFrom() {
                return firedfrom;
              
            }
          
            public Integer getRange() {
                return range;
              
            }
          
            public Double getDamage() {
                return damage;
              
            }
          
        }
      
        public void onEnable() {
          
        }
      
        public void onDisable() {
          
          
        }
          
            @EventHandler
            public void onHit(EntityDamageByEntityEvent event) {
              
                if (event.getDamager() instanceof Snowball) {
                  
                    if (shotprojectiledata.containsKey(event.getDamager())) {
                      
                        EntityData eventdata = shotprojectiledata.get(event.getDamager());
                      
                        if (event.getEntity().getLocation().distance(eventdata.getFiredFrom())<=eventdata.getRange()) {
                            event.setDamage(eventdata.getDamage());
                            shotprojectiledata.remove(event.getDamager());
                        }
                    }
                }
            }
              
                @EventHandler
                public void particle(PlayerInteractEvent e) {
                  
                    Location location = player.getEyeLocation();
                    BlockIterator blocksToAdd = new BlockIterator(location, 0D, 15);
                    Location blockToAdd;
                    while(blocksToAdd.hasNext()) {
                            if (blockToAdd.getBlock().getType() != Material.AIR ||!shotprojectiledata.containsKey(projectile)) {
                                    break;
                            }
    
                            blockToAdd = blocksToAdd.next().getLocation();
                            player.getWorld().playEffect(blockToAdd, Effect.STEP_SOUND, Material.FIRE);
                    }
    
                    Snowball projectile = player.launchProjectile(Snowball.class);
                    EntityData data = new EntityData(projectile.getLocation(), 15, 5D);
                    shotprojectiledata.put(projectile, data);
                    for (Player p : Bukkit.getOnlinePlayers()) {
    
                        ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new  PacketPlayOutEntityDestroy(((CraftSnowball) projectile).getHandle().getId()));
    
                        }
                   }
            }
     
  9. Offline

    ChipDev

    Well, first- It seems as you copy pasted most of the code. Not good!
    Also, The player variable in this case (IM GUESSING) is "e.getPlayer()" as in the player from the PlayerInteractEvent (e)
     
  10. Offline

    MrShnig

    Well, I didn't copy-paste most of the code. I did my best to edit it to look nice and everything, but later on that didn't work so I tried copy-pasting it and that didn't work either, I really just followed the tutorial.

    Other than that, thanks for the advice, but it still doesn't quite work properly for me... When I added

    Player player = (Player) e.getPlayer();

    it started saying that there was an error in

    Location blockToAdd;

    so I changed it to

    Location blockToAdd = location;

    but that didn't help... The plugin doesn't do anything, what am I supposed to do to make it so that if they right-click, TnT for example, the trail appears?

    Here's that bit of code:


    Code:
                @EventHandler
                public void particle(PlayerInteractEvent e) {
                  
                    Player player = (Player) e.getPlayer();
                  
                    Location location = e.getPlayer().getEyeLocation();
                    BlockIterator blocksToAdd = new BlockIterator(location, 0D, 15);
                    Location blockToAdd = location;
    
                    Snowball projectile = player.launchProjectile(Snowball.class);
                  
                    while(blocksToAdd.hasNext()) {
                            if (blockToAdd.getBlock().getType() != Material.AIR ||!shotprojectiledata.containsKey(projectile)) {
                                    break;
                            }
                            blockToAdd = blocksToAdd.next().getLocation();
                            player.getWorld().playEffect(blockToAdd, Effect.STEP_SOUND, Material.FIRE);
                    }
                    EntityData data = new EntityData(projectile.getLocation(), 15, 5D);
                    shotprojectiledata.put(projectile, data);
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new  PacketPlayOutEntityDestroy(((CraftSnowball) projectile).getHandle().getId()));
                        }
                   }
            }
    Could you please send me the corrected code?
    Also, thanks for the help.
     
    ChipDev likes this.
  11. Offline

    ChipDev

    Did you include your plugin.yml, debug, check /pl, etc?
    (Check the console for errors)
     
  12. Offline

    MrShnig

    Pardon? /pl, debug?

    My plugin.yml is this:
    Code:
    name: TrailLobber
    main: me.mrshnig.TrailLobber
    version: 1.0
    Please keep in mind that I still am a newbie as far as it goes for programming in Bukkit and Java, I don't quite understand what you mean.

    Also, the console shows no errors or that anything is trying to happen.

    Thanks for trying to help!
     
  13. Offline

    timtower Administrator Administrator Moderator

  14. Offline

    MrShnig

  15. Offline

    timtower Administrator Administrator Moderator

    @MrShnig Could you also send it when somebody is on the server so the trail is actually active and throwing the errors you are talking about?
     
  16. Offline

    MrShnig

    Here it is:
    http://pastebin.com/95sYucpt
    The XXX.X.X.X:XXXXX part represents my IP address, I didn't want to put that in there.
     
  17. Offline

    timtower Administrator Administrator Moderator

    @MrShnig And did that user have a trail active? Because it didn't look like that.
     
  18. Offline

    MrShnig

    @timtower
    How do I do that? How do I activate a trail?
    The user's me...
     
    Last edited: May 21, 2016
Thread Status:
Not open for further replies.

Share This Page