Launch Fishing Bobber

Discussion in 'Plugin Development' started by xWatermelon, Sep 10, 2013.

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

    xWatermelon

    How can I launch a fishing bobber from a player when they aren't holding a fishing rod (via a command, specifically)? I tried player.launchProjectile(Fish.class), however it is giving me errors in console saying "Projectile not supported." Anyone know how I can fix this?
     
  2. Offline

    chasechocolate

    Maybe try spawning it into the world and setting the velocity and the shooter?
     
  3. Offline

    The_Doctor_123

    Hmm.. I've briefly looked up fishing hooks and they like don't seem to exist.. Well, a workaround to this issue would be to spawn the entity in the world:

    Code:
    Entity hook = player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.FISHING_HOOK);
    hook.setVelocity(new Vector(player.getDirection()).multiply(2)); // Sets the velocity to where the player is looking and multiplies that by 2, because it may be too slow. You can fiddle around with that number to your liking.
    
     
  4. Offline

    chasechocolate

  5. Offline

    The_Doctor_123

    chasechocolate

    They're called "Fish"?! That's kind of stupid.. they should be called Fishing Hooks..
     
    WauloK likes this.
  6. Offline

    uyuyuy99

  7. Offline

    chasechocolate

    xWatermelon
    Code:java
    1. net.minecraft.server.v1_6_R2.World nmsWorld = ((CraftWorld) player.getWorld()).getHandle();
    2. EntityFishingHook nmsHook = new EntityFishingHook(nmsWorld, ((CraftPlayer) player).getHandle());
    3.  
    4. nmsWorld.addEntity(nmsHook);

    However, the bobber disappears after being launched. Perhaps someone knows how to fix this?
     
  8. Offline

    dillyg10

    In the default fishing rod code, this line:

    Code:java
    1.  
    2. if (this.owner.dead || !this.owner.isAlive() || itemstack == null || itemstack.getItem() != Item.FISHING_ROD || this.e(this.owner) > 1024.0D) {
    3. this.die();
    4. this.owner.hookedFish = null;
    5. return;
    6. }
    7.  


    prevents a fishing hook from existing when a player's item in hand is not a fishing rod...
    however.... you can override the l_() method, just copy and paste the code from

    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/EntityFishingHook.java

    and remove
    Code:java
    1. itemstack.getItem() != Item.FISHING_ROD
    from the if statement :).
     
    bobacadodl likes this.
  9. Offline

    chasechocolate

    dillyg10 yeah, I figured it out a few hours ago, (I just created a custom class that extends EntityFishingHook), I'll post it when I get back on my computer.

    xWatermelon dillyg10 here's how I did it:
    Code:java
    1. public class FishingLine extends EntityFishingHook {
    2. private Item item;
    3.  
    4. public FishingLine(Player player, Item item){
    5. super(((CraftWorld) player.getWorld()).getHandle(), ((CraftPlayer) player).getHandle());
    6.  
    7. this.item = item;
    8. }
    9.  
    10. @Override
    11. public void l_(){
    12. if(item != null){
    13. ItemStack hand = this.owner.bx();
    14. boolean shouldRemove = false;
    15.  
    16. if(this.owner.dead || !(this.owner.isAlive())){
    17. shouldRemove = true;
    18. }
    19.  
    20. if(hand == null){
    21. shouldRemove = true;
    22. } else {
    23. if(hand.getItem() != item){
    24. shouldRemove = true;
    25. }
    26. }
    27.  
    28. if(this.e(this.owner) > 1024.0D){
    29. shouldRemove = true;
    30. }
    31.  
    32. if(shouldRemove){
    33. super.die();
    34. super.owner.hookedFish = null;
    35. }
    36. }
    37. }
    38.  
    39. public void spawn(Location loc){
    40. net.minecraft.server.v1_6_R2.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
    41.  
    42. nmsWorld.addEntity(this);
    43. this.setPosition(loc.getX(), loc.getY(), loc.getZ());
    44. }
    45. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    xWatermelon likes this.
  10. Offline

    Eexar

    Entity hook = player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.FISHING_HOOK);
    hook.setVelocity(new Vector(player.getDirection()).multiply(2)); // Sets the velocity to where the player is looking and multiplies that by 2, because it may be too slow. You can fiddle around with that number to your liking.

    Dosen't work because you cant just get a player's velocity. You have to get their location and then their velocity.
    player.getLocation().getVelovity();
     
  11. Offline

    naorpeled

    It gives me an error on this lines:
    Code:Java
    1.  
    2. ItemStack hand = this.owner.bx();
    3. if(hand.getItem() != item){
    4.  

    chasechocolate
     
  12. Offline

    Garris0n

    naorpeled Are you including Craftbukkit and I believe it's .by(), however that's going off my memory from earlier today.
     
  13. Offline

    naorpeled

    Yes, I do include Craftbukkit and BukkitAPI.
    Edit: I fixed it.
    but now, how do I use it to launch a fishing hook?
     
  14. Offline

    Plo124

    How about trying this:
    Player launches fishing rod
    You get nearby entities (the bobber)
    You set the velocity of the bobber
     
Thread Status:
Not open for further replies.

Share This Page