Solved Entity with leash

Discussion in 'Plugin Development' started by mrCookieSlime, Aug 4, 2013.

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

    mrCookieSlime

    Hey guys, I got an E-Mail with a suggestion for an item for my plugin Slimefun:
    http://dev.bukkit.org/bukkit-plugins/slimefun

    He suggested a grappling hook with a neat effect that it shoots an arrow with a lead to the Player, so that it looks like a grappling hook in real life. But here's my question: How can I do that? I know how to shoot arrows but how can i shoot them with a leash between the Player and the Arrow? And how can I do it that the leash disappears when you get pulled in this direction?
     
  2. Offline

    thecrystalflame

  3. Offline

    mrCookieSlime

    thecrystalflame
    Thank, you but I'm sorry I'm very bad in sending packets can you maybe paste some code to attach and remove the leash from the arrow and the player?
     
  4. Offline

    thecrystalflame

    I have been playing around with this and I am not finding it an easy task. if i can get it working i will let you know.
     
  5. Offline

    mrCookieSlime

    Ok, just good to see, that I'm not the only one who can't find a solution ^^

    But I really need this now, so I hope anyone else has some code for me :/
     
  6. Offline

    lycano

    I would simply use the fishing rod as grappling hook and ignore the arrow thing .. thats far more easier.

    If its even possible to do what you want "leash and arrow on entity" then it will take hours to even check if its possible.
     
  7. Offline

    mrCookieSlime

    lycano

    I don't want to check if it's possible, I know that it is possible, I just want to know, how?
    and I won't use a fishing rod I want that it looks fancy, so I will do it with leash and arrow, but I still need someone, who can tell me how :(
     
  8. Offline

    ZeusAllMighty11

    If you are asking for code, put this in the plugin requests section.
     
  9. Offline

    mrCookieSlime

    TheGreenGamerHD

    I thought "Plugin Requests" is for requests of plugins, but I'm not requesting a plugin, I'm just asking for help on my plugin. So, do I really have to move this in the "Plugin Requests" section?
     
  10. Offline

    Tarestudio

    mrCookieSlime
    If you asking for help, but are willing to work on your own, let it stay here. If you want to get a Plugin doing what you want, put it to the requests. If you want the full code of the plugin to use for your own... rethink our behaviour.

    As help:
    - http://jd.bukkit.org/beta/apidocs/ <- APIDocumentation of betareleases
    - http://jd.bukkit.org/dev/apidocs/<- APIDocumentation of devreleases
    There you can look for things that may help you with the leash. I saw some events and a 'Entity' that have something to do with leashes. Start there for your research.
     
  11. Offline

    mrCookieSlime

    Tarestudio
    First of all I just want help with my plugin, only a piece of code which can help me understand how I can do this, but I'm coding on my own, so it can stay. And I'll see if I can find something which can help me

    Alright, I found nothing :(. I looked through the apidocs, the source and even through the minecraft source itself, but didn't find what I want, please tell me if anyone finds a method to make a leash connection from the player to the arrow, so something like:

    public void attachLeash(Player p, Entity e) {
    //connect the leash
    }

    I would also be glad, if someon could maybe post a piece of code to attach the leash, if there's no such method in bukkit.

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

    toothplck1

    Unfortunately minecraft code only allows nonsentient living entities to be the leashee, although you should be able to leash just about any entity to a non sentient living entity.
     
  13. Offline

    mrCookieSlime

    toothplck1
    errrrrrrrrrr, so i can make a connection from a Player to an arrow???
     
  14. Offline

    Comphenix

    You're in luck - the latest development build of Bukkit now includes a leash API:
    https://github.com/Bukkit/Bukkit/commit/bf832ee9d60b348f0b003631c411c5f3fe23226c

    I haven't tried it myself, but the JavaDoc (and source) seems to suggest it should work with arrows. But you'll have to reapply it if the server restarts or the chunk reloads.
     
  15. Offline

    toothplck1

    No you cannot make a connection from a Player to an arrow :( sorry.
     
  16. Offline

    Comphenix

    That's true, but you could try creating an invisible entity (invisibility effect) and attach the leash to that.

    I just tried that with a bat, and it actually works fine. But you may need to use packets in order to synchronize the movements of the bat and the player, or at least if you want to disable its very annoying sound:
    Code:java
    1. Player player = (Player) sender;
    2. Block block = player.getTargetBlock(null, 120);
    3.  
    4. if (block == null)
    5. return true;
    6.  
    7. Bat bat = player.getWorld().spawn(
    8. block.getLocation().add(0, 1, 0), Bat.class);
    9. bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000, 1));
    10.  
    11. Arrow arrow = player.getWorld().spawn(
    12. block.getLocation().
    13. add(0, 4, 0).
    14. add(new Vector(0, 2, 0)),
    15. Arrow.class);
    16.  
    17. bat.setLeashHolder(arrow);
     
  17. Offline

    toothplck1

    Thats interesting in my testing I didn't see the visual leash on bats... I guess the javadoc needs to be amended.

    Also I wonder if you could make the Bat mount the player after leashing as to keep its movement synchronized through that....

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

    Comphenix

    You could try that, sure.

    I didn't get a chance to include it in my last post, but here's a short demonstration of leashing an entity to an arrow:


    Just to confirm that it is in fact possible.
     
  19. Offline

    toothplck1

    Thats so funny....
     
  20. Offline

    mrCookieSlime

    Ok, thanks I played a little bit with that and came to a solution. It looks awesome and works great. If you wanna see what I did, here's the code:
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent e) {
    4. Player p = e.getPlayer();
    5. if (p.getItemInHand().getType() == Material.LEASH && p.getItemInHand().getDurability == 1) {
    6. Action a = e.getAction();
    7. if ((a == Action.RIGHT_CLICK_AIR) || (a == Action.RIGHT_CLICK_BLOCK)) {
    8.  
    9. Vector direction = e.getPlayer().getEyeLocation().getDirection().multiply(4);
    10. Projectile projectile = (Projectile)e.getPlayer().getWorld().spawn(e.getPlayer().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
    11. projectile.setShooter(e.getPlayer());
    12. projectile.setVelocity(direction);
    13. Arrow arrow = (Arrow) projectile;
    14.  
    15. Bat bat = p.getWorld().spawn(
    16. p.getEyeLocation(), Bat.class);
    17. bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
    18. bat.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100000, 100000));
    19.  
    20. bat.setLeashHolder(arrow);
    21.  
    22. if(p.getTargetBlock(null, 400).getType() != Material.AIR) {
    23. Location l = p.getLocation();
    24. Vector d = l.getDirection();
    25. int flyspeed = 6;
    26. d.multiply(flyspeed);
    27. p.setVelocity(d);
    28.  
    29. p.teleport(new Location(p.getWorld(), arrow.getLocation().getX(), arrow.getLocation().getY(), arrow.getLocation().getZ(), p.getLocation().getYaw(), p.getLocation().getPitch()));
    30. }
    31. bat.setHealth((double)0);
    32. }
    33. }
    34. }
     
    Comphenix, lycano and Tarestudio like this.
  21. Offline

    Comphenix

    It's very fun to play with - you certainly got something awesome here. :)

    Getting propelled immediately is certainly more fun, but perhaps it would be better to wait until the arrow has collided with an actual block? You could listen for a ProjectileHitEvent and retrieve the coordinate of the arrow and launch the player toward that specific block (at that specific time). Perhaps also wait until then before killing the bat.
     
  22. Offline

    mrCookieSlime

    Comphenix
    Yea, sure, this would be even more realistic and would also look better, I'll do it
     
Thread Status:
Not open for further replies.

Share This Page