Replace fishing rod with custom entity

Discussion in 'Plugin Development' started by epicfacecreeper, Jul 10, 2013.

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

    epicfacecreeper

    I'm trying to make a grappling hook, but need it to be a custom entity to preserve velocity and stuff. I have the custom entity set up, I just need to replace it when the player launches it. I currently have a PlayerFishEvent set up to handle grappling.
    Code:java
    1. public void onPlayerFishingEvent(PlayerFishEvent event){
    2. Player p = event.getPlayer();
    3. Material item = p.getItemInHand().getType();
    4. if(item == Material.FISHING_ROD){
    5. java.util.List<Entity> nearby = p.getNearbyEntities(50,50,50); // searches in a 100*100*100 radius around the player for other entities
    6. Entity hook = null; // holds the future hook
    7. for (Entity e : nearby) { // loop through entities
    8.  
    9. if (e.getType() == EntityType.FISHING_HOOK && ((Player) ((Fish) e).getShooter()).getName().equals(event.getPlayer().getName())) { // it is a hook!
    10. hook = e;
    11. break;
    12. }
    13. }
    14. if (hook != null && isGrappleValid(((Fish) hook))) {
    15. Location hookLocation = hook.getLocation(); // the location of the hook
    16. Vector vector = hookLocation.toVector().subtract(p.getLocation().toVector());
    17. p.setVelocity(vector.multiply(0.3));
    18. }
    19. else {
    20.  
    21. }
    22. }
    23. }
     
Thread Status:
Not open for further replies.

Share This Page