Making a item a projectile?

Discussion in 'Plugin Development' started by TrollTaylor, Sep 14, 2013.

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

    TrollTaylor

    Hello i wanted to know how would i make a item a projectile like on the popular server "Super craft bros" where they have when you right click with a mob egg in your hand it shoots it and on impact it spawns the mob. How would i do that with fire and burn a mob on impact?
     
  2. Offline

    The_Doctor_123

    I'm decently sure it's impossible to create a projectile with items. But you can make it look like a projectile. Use the Item entity and set its pickup delay to something absurd and set it's velocity. Bam! You got yourself a projectile-like item.
     
  3. Offline

    TrollTaylor

    Thats what im looking for. But how would i use the item entity? And how would i make it burn a mob on impact?
     
  4. Offline

    The_Doctor_123

    TrollTaylor
    Hmm.. this is actually harder than I thought, there's no event for items hitting the ground. Here's what I think you can do, though:

    Code:java
    1. final Item item = (Item) player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.DROPPED_ITEM);
    2. item.setVelocity(player.getLocation().getDirection().multiply(2.5));
    3.  
    4. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(<Your Plugin Instance>, new Runnable()
    5. {
    6. @Override
    7. public void run()
    8. {
    9. boolean Cancelled = false;
    10. if (!Cancelled)
    11. {
    12. List<Entity> Entities = item.getNearbyEntities(1, 1, 1);
    13. for (Entity entity : Entities)
    14. {
    15. if (entity instanceof LivingEntity)
    16. {
    17. entity.setFireTicks(60); // Set fire for 3 sec
    18. Cancelled = true;
    19. break;
    20. }
    21. else if (entity.isOnGround())
    22. {
    23. Cancelled = true;
    24. break;
    25. }
    26. }
    27. }
    28. }
    29. }, 1, 1);


    I'm assuming the garbage collector will pick up those tasks when they are "cancelled," but if not, that will cause a memory leak.
     
  5. Offline

    MisterErwin

    Just search the forums: More Projectiles...

    Or use google: <Edit by Moderator: Redacted bit url>
     
    Last edited by a moderator: Feb 15, 2017
    Cycryl likes this.
  6. Offline

    TrollTaylor

    The_Doctor_123
    Doesnt seem to work heres my code

    Code:java
    1. @EventHandler
    2. public void onSneak(PlayerToggleSneakEvent event){
    3. if(this.wizard == event.getPlayer().getName()){
    4. if(this.wmana > 50){
    5. if(event.getPlayer().isSneaking() == true){
    6. event.getPlayer().getServer().broadcastMessage("Working");
    7. this.wmana = this.wmana - 25;
    8. final Item item = (Item) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getEyeLocation(), EntityType.DROPPED_ITEM);
    9. ((Entity) item).setVelocity(event.getPlayer().getLocation().getDirection().multiply(2.5)); //Added The ((Entity) Cause eclipse gave me a error
    10.  
    11. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    12. {
    13. @Override
    14. public void run()
    15. {
    16. boolean Cancelled = false;
    17. if (!Cancelled)
    18. {
    19. List<Entity> Entities = ((Entity) item).getNearbyEntities(1, 1, 1); //Added The ((Entity) Cause eclipse gave me a error
    20. for (Entity entity : Entities)
    21. {
    22. if (entity instanceof LivingEntity)
    23. {
    24. entity.setFireTicks(60); // Set fire for 3 sec
    25. Cancelled = true;
    26. break;
    27. }
    28. else if (entity.isOnGround())
    29. {
    30. Cancelled = true;
    31. break;
    32. }
    33. }
    34. }
    35. }
    36. }, 1, 1);
    37.  
    38.  
    39.  
    40.  
    41.  
    42. }
    43. }else{
    44. event.getPlayer().sendMessage(ChatColor.AQUA + "Out of mana");
    45. this.pmana = 0;
    46. if(this.pmana < 0){
    47. this.pmana = 0;
    48. event.setCancelled(true);
    49. }
    50. }
    51. }
    52. }
     
  7. Offline

    The_Doctor_123

    I'm pretty sure you're using the wrong Item import. Make sure you're not using:

    Code:java
    1. import net.minecraft.server.v1_5_R3.Item;


    But use:

    Code:java
    1. import org.bukkit.entity.Item;
     
  8. Offline

    TrollTaylor

    I had the first one imported but i changed it and didnt fix anything. It gives me a error in the console heres the error
    http://pastebin.com/aV4VRzcR
     
  9. Offline

    bobacadodl

  10. Offline

    The_Doctor_123

    Best not to use a library for something relatively simple. I just realized an issue with my code, though. I never identified what item I'm spawning. I'm not exactly sure how to do that..
     
  11. Offline

    TrollTaylor

    bobacadodl I dont know how to use that library how do i use it?
     
  12. Offline

    bobacadodl

    It explains it right in the post...
    Code:
    new ItemProjectile("name", (Player) shooter, (ItemStack) item, (double) power);
    That shoots the projectile

    Then to do something when it hits an entity:
    Code:
        @EventHandler
        public void onHit(CustomProjectileHitEvent e){
            if (e.getHitType() == HitType.ENTITY){
                if (e.getName().equalsIgnoreCase("name")){
                    e.getHitEntity().damage(3D, e.getProjectile().getShooter());
                }
            }
        }
     
  13. Offline

    1Achmed1

  14. Offline

    TrollTaylor

    I did that and it didnt work heres what i put
    Code:
    new ItemProjectile("name", event.getPlayer(), new ItemStack(Material.FIRE, 10); //I used this in a event
     
Thread Status:
Not open for further replies.

Share This Page