Grapple Pull

Discussion in 'Plugin Development' started by HeavyMine13, Jan 18, 2016.

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

    HeavyMine13

    Hey! So I am trying to make a grapple rod, and this is what I have atm:
    Code:
     public void grapple(PlayerFishEvent event) {
            final Player player = event.getPlayer();
            event.getHook().setBounce(false);
            //event.getHook().getVelocity().multiply(2);
            if (grappler.contains(player.getUniqueId())) {
                if (event.getState() == PlayerFishEvent.State.IN_GROUND) {
                    if (player.getItemInHand().getType().equals(Material.FISHING_ROD)) {
                        //event.setCancelled(true);
                        pullTo(player, event.getHook().getLocation());
                    }
    
                }
            }
        }
    
    
    
    
        public static void pullTo(Entity e, Location loc) {
            // This code written by [USER=90696604]SnowGears[/USER]
            Location l = e.getLocation();
    
            if (l.distanceSquared(loc) < 9) {
                if (loc.getY() > l.getY()) {
                    e.setVelocity(new Vector(0, 0.25, 0));
                    return;
                }
                Vector v = loc.toVector().subtract(l.toVector());
                e.setVelocity(v);
                return;
            }
    
            l.setY(l.getY() + 0.5);
            e.teleport(l);
    
            double d = loc.distance(l);
            double g = -0.08;
            double x = (1.0 + 0.07 * d) * (loc.getX() - l.getX()) / d;
            double y = (1.0 + 0.03 * d) * (loc.getY() - l.getY()) / d - 0.5 * g * d;
            double z = (1.0 + 0.07 * d) * (loc.getZ() - l.getZ()) / d;
    
            Vector v = e.getVelocity();
            v.setX(x);
            v.setY(y);
            v.setZ(z);
            e.setVelocity(v);
        }
    So 2 questions:
    1) It is not always detecting when the bobber lands, is there a way to tweak/fix this?

    2) Is there a better way to do the pull mechanism than what I have?

    Thanks!
     
  2. Offline

    87pen

    @HeavyMine13 Is the fishing state returning a state other than In_Ground?
     
  3. Offline

    HeavyMine13

    It is not always detecting it IN_GROUND. You need to wait until it fully stops inside the block, but you can't wait too long :/
     
Thread Status:
Not open for further replies.

Share This Page