Find a the mob a mob is riding.

Discussion in 'Plugin Development' started by Rockon999, Jun 8, 2013.

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

    Rockon999

    Okay... after much figuring in the old brain... I can't figure this out... I've got a Zombie and I'm trying to figure out if its riding a spider. getVehicle only works on Minecart, Pigs, Boats, and PoweredMinearts... so I was out of luck there, so I tried looping through the world's entities and seeing if any were close to my zombie, then seeing if that entity was a spider, and if a zombie was riding it. The code below is what I tried... all it does is create endless spamming of the console, and lots of arrows. Thanx in advance... Rock :)

    HTML:
                for (Entity e : Bukkit.getWorld(event.getEntity().getWorld().getName()).getEntities()) {
                    if ((e.getLocation().getX() > event.getEntity().getLocation().getX() - 0.4) && (e.getLocation().getX() < event.getEntity().getLocation().getX() + 0.4)) {
                        if ((e.getLocation().getX() > event.getEntity().getLocation().getX() - 0.4) && (e.getLocation().getX() < event.getEntity().getLocation().getX() + 0.4)) {
                            if ((e.getLocation().getY() < event.getEntity().getLocation().getY() + 0.4) && (e.getLocation().getY() > event.getEntity().getLocation().getY() - 0.4)) {
                                if (e.getType() == EntityType.SPIDER) {
                                    Spider s = (Spider) e;
                                    if (s.getPassenger() != null) {
                                        if (s.getPassenger().getType() == EntityType.ZOMBIE) {
                                            Zombie zombie = (Zombie) event.getEntity();
                                            Arrow a = zombie.getWorld().spawn(zombie.getLocation().add(0, 1, 0), Arrow.class);
                                            a.setVelocity(zombie.getLocation().getDirection().multiply(2));
                                            Bukkit.getLogger().info("Testing 1,, 2,, 3,,");
                                        }
                                    }
     
                                }
                            }
                        }
                    }
                }
     
  2. Though it's not the best method, I would try using this:
    Code:java
    1. Zombie zombie;
    2.  
    3. for (Entity entity : zombie.getNearbyEntities(1, 1, 1))
    4. {
    5. if (entity instanceof Spider)
    6. {
    7. // No need to cast here, since we know it's a spider, but this is just an example
    8. Spider spider = (Spider) entity;
    9.  
    10. if (spider.getPassenger() != null && spider.getPassenger().equals(zombie))
    11. {
    12. // Here you have your spider-zombie-thing...
    13.  
    14. return;
    15. }
    16. }
    17. }
     
Thread Status:
Not open for further replies.

Share This Page