[UNSOLVED] Anyone think they can solve this problem with grappler help

Discussion in 'Plugin Development' started by ResultStatic, Jan 4, 2014.

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

    ResultStatic

    I posted another post about updating the code that lets you shoot fishing hooks from a leash like in mcpvp. now im having some issues with it. First you can keep shooting hooks instead of it retracting each time and i cant get the location to change the players velocity it just shoots you in a random direction. it also shoots the hooks on right click for some reason even though they are spawn on left click. i need to also set the location when its on the ground to where its underground like on mcpvp, lastly the hooks dont actually hook onto people, they just float past them. any help is appreciated. Grappler class:
    Code:
    @EventHandler
          public void onInteract(PlayerInteractEvent event)
          {
         
            Player player = event.getPlayer();
            Item item = (Item) net.minecraft.server.v1_7_R1.Items.LEASH;
      if (UserUtil.getInstance().getKit(player).equals("grappler")) {
          FishingLine fish = new FishingLine(player, item);
       
            if ((event.getAction() == Action.LEFT_CLICK_AIR) && (event.getMaterial() == Material.LEASH) || ((event.getAction() == Action.LEFT_CLICK_BLOCK) && (event.getMaterial() == Material.LEASH)))
              player.sendMessage("Leftclick has worked");
              Location location = player.getLocation();
              fish.spawn(player, location);{
              if ((event.getAction() == Action.RIGHT_CLICK_AIR) && (event.getMaterial() == Material.LEASH) || ((event.getAction() == Action.RIGHT_CLICK_BLOCK) && (event.getMaterial() == Material.LEASH))) {
              fish.die();
            World world = (World) fish.owner.getWorld();
              player.sendMessage("Rightclick has worked");
            double x = fish.locX;
            double y = fish.locY;
            double z = fish.locZ;
            float p = fish.pitch;
            float yaw = fish.yaw;
            Location to = new Location(player.getWorld(),x,y,z,yaw,p);
            Location lc = player.getLocation();
                double d = to.distance(lc);
                double t = d;
                double g = -0.08D;
                double vx = (1.0D + 0.07000000000000001D * t) * (to.getX() - lc.getX()) / t;
                double vz = (1.0D + 0.07000000000000001D * t) * (to.getZ() - lc.getZ()) / t;
                Vector v = player.getVelocity();
                v.setX(vx);
                v.setZ(vz);
                player.setVelocity(v);
            }
         
            }
      }
    }
    Here is the overider to let you shoot hooks from the leash
    Code:
     public class FishingLine extends EntityFishingHook {
            private Item item;
            Kitevents3 kit = new Kitevents3();
            public FishingLine(Player player, Item item2){
                super(((CraftWorld) player.getWorld()).getHandle(), ((CraftPlayer) player).getHandle());
                item2 =
                this.item = item2;
             
            }
            @Override
            public void h(){
                if(item != null){
                    ItemStack hand = this.owner.bD();
                    boolean shouldRemove = false;
     
                    if(this.owner.dead || !(this.owner.isAlive())){
                        shouldRemove = true;
                    }
     
                    if(hand == null){
                        shouldRemove = true;
                    } else {
                        if(hand.getItem() != item){
                            shouldRemove = true;
                        }
                    }
     
                    if(this.e(this.owner) > 1024.0D){
                        shouldRemove = true;
                    }
     
                    if(shouldRemove){
                        super.die();
                        super.owner.hookedFish = null;
                    }
                }
            }
     
            public void spawn(Player player, Location loc){
                net.minecraft.server.v1_7_R1.World nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
                nmsWorld.addEntity(this);
                this.setPosition(loc.getX() + 5, loc.getY(), loc.getZ()+ 5);
                Vector v = this.getBukkitEntity().getMomentum();
                v.multiply(2);
                this.getBukkitEntity().setVelocity(v);
                this.getBukkitEntity().getLocation().setY(getBukkitEntity().getLocation().getY() - 10); // this doesnt work either
             
             
            }
        }
    does no one know how?

    i know it hasnt been 24 hours but i need to bump

    help D:

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

    dillyg10

    A: You forgot your brackets on the If left/right click.. might wanna fix that ;)
    B: They don't hook onto people because you override h()... you'll need to call super.h() or write your own code to make it work

    I'm not sure what your other problems are, if you are not a native english speaker please let me know and I will try harder, otherwise please reword what you are trying to say in a more fluent matter.
     
  3. Offline

    ResultStatic

    dillyg10 see thats the problem, the source code is so confusing i cant really find the code where it hooks onto people, its like the hook isnt even there and its impossible to get the location of it.
     
  4. Offline

    dillyg10

    You need to call super.h() in your h() method... if you don't understand the fishinglure code, then don't use it.
     
Thread Status:
Not open for further replies.

Share This Page