Spawning in a fishinghook when left clicking a certain item?

Discussion in 'Plugin Development' started by Tommy Raids, Dec 13, 2013.

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

    Tommy Raids

    Ok guys so basically I want to make a grappler kit. I made it with a fishing rod, but I want to make It so when I left click a lead it shoots out a fishingrod bobber thingy :p please help me as much as you can! Thanks :D Here is my code so far:

    Code:
    ArrayList<String> grappler = new ArrayList<String>();
    @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)     
    public void onPlayerFish(PlayerFishEvent event)     
    {        final Player player = event.getPlayer();         
    if (event.getState().equals(PlayerFishEvent.State.IN_GROUND))       
    {            Location lc = player.getLocation();           
    Location to = event.getHook().getLocation();           
    lc.setY(lc.getY() + 0.5D);           
    player.teleport(lc);           
    double g = -0.08D;           
    double d = to.distance(lc);       
    double t = d;         
    double v_x = (1.0D + 0.07000000000000001D * t) * (to.getX() - lc.getX()) / t; 
    double v_y = (1.0D + 0.03D * t) * (to.getY() - lc.getY()) / t - 0.5D * g * t;       
    double v_z = (1.0D + 0.07000000000000001D * t) * (to.getZ() - lc.getZ()) / t;   
    Vector v = player.getVelocity();            v.setX(v_x);            v.setY(v_y);            v.setZ(v_z);     
    player.setVelocity(v);         
    grappler.add(player.getName());              }
    else if (event.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY))   
    {            Location lc = player.getLocation();       
    Location to = event.getHook().getLocation();           
    lc.setY(lc.getY() + 0.5D);            player.teleport(lc);           
    double g = -0.08D;            double d = to.distance(lc);         
    double t = d;            double v_x = (1.0D + 0.07000000000000001D * t) * (to.getX() - lc.getX()) / t;     
    double v_y = (1.0D + 0.03D * t) * (to.getY() - lc.getY()) / t - 0.5D * g * t;         
    double v_z = (1.0D + 0.07000000000000001D * t) * (to.getZ() - lc.getZ()) / t;         
    Vector v = player.getVelocity();            v.setX(v_x);            v.setY(v_y);            v.setZ(v_z); 
    player.setVelocity(v);            this.grappler.add(player.getName());   
    }
    }
    
     
  2. Offline

    Harmings

  3. Offline

    JRL1004

    Harmings What do you mean by
     
  4. Offline

    Harmings

  5. Offline

    Tommy Raids

    Harmings What do you mean? I coded this by my self, I used that as a guide kinda.
     
  6. Offline

    boysnnoco

    'As a guide' I got you ;)
     
  7. Offline

    Tommy Raids

    JRL1004 Harmings With a little research of my own, I found out to spawn an entity. But for some reason it won't spawn the fishing hook when I left click the leash. Take a look. Its my (OWN) code:

    Code:
    @EventHandler
    public void onGrapplerthingy(PlayerInteractEvent e){
        Player p = e.getPlayer();
        Action a = e.getAction();
        Vector vector = p.getEyeLocation().getDirection().multiply(3);
        List<Entity> nearbyEntities = p.getNearbyEntities(10, 10, 10);
        for(Entity entity : nearbyEntities){
            entity.setVelocity(vector);
            Entity hook = p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.FISHING_HOOK);
            if(a == Action.LEFT_CLICK_BLOCK || a == Action.LEFT_CLICK_AIR && p.getItemInHand().getType() == Material.LEASH){
                hook.setVelocity(vector);
            }
        }
    }
    chasechocolate boysnnoco Could you help me? I am trying to spawn In a fishhook entity but it doesn't work. what is wrong with my code? Thanks :)

    Code:
    @EventHandler
    public void onGrapplerthingy(PlayerInteractEvent e){
        Player p = e.getPlayer();
        Action a = e.getAction();
        if(grappler.contains(p.getName()) && p.getItemInHand().getType() == Material.LEASH){
            if(a == Action.LEFT_CLICK_AIR || a == Action.LEFT_CLICK_BLOCK){
        Vector vector = p.getEyeLocation().getDirection().multiply(3);
        p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.FISHING_HOOK);
        List<Entity> nearbyEntities = p.getNearbyEntities(1, 1, 1);
        for(Entity entity : nearbyEntities){
                entity.setVelocity(vector);
        }
        }
    }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  8. Offline

    ResultStatic

    TheAnswerIsMinecraft you have to change nms code in the Fishing hooks class. there is a void h() that you must override. it has a checker that makes sure you have a fishing rod in your hand. i spent hours looking at that obfuscated code and i figured it out and finally got everything working.
     
Thread Status:
Not open for further replies.

Share This Page