Listing nearby mobs

Discussion in 'Plugin Development' started by Petomatick, Oct 22, 2015.

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


    Heyo, I want to try to update ProtectingWolf, or atleast make a similar mod for my own use if Haruka dislikes the idea. It's currently not able to load, which I suspect is because it tries to import several bukkit packages. Understandably those have either been renamed/merged/removed since 2011, and since I've only done python and some simple c++ until now, there's no way I can read what he's done so I'm starting from scratch.

    So I'd like to start with detecting nearby monsters. I've given it a little search here on the forums but the best thread was from 2012. My Google Fu isn't giving me much either, so if someone can briefly explain/ me to appropriate page I'd be really thankful!

    Thanks in advance
  2. Offline


    Use the method "get earbyEntities(X,y,z)" from the Entity class, the arguments are the distance Arround the player in the X y or z axis. Read more about it in the docs.
  3. Offline


    Thank you! Any idea where I can find the function for making wolfs attack an entity?
  4. Offline


    The Bukkit JavaDocs.
  5. Offline


    I'm searching in there but I can't find the nearbyEntities method in Entity class.

    I managed to find
    public void setTarget(Entity target), but how does it know which entity to .setTarget?
  6. Offline


  7. Offline


    Thank you! That was exactly what I needed! It probably would've answered the question perfectly if I could've figured out what prefix to give .setTarget. Sadly though, I don't understand how to use the "public void setTarget(Entity target)" line in practice. I'm guessing somewhere along the lines of wolf.setTarget(list[1]) where list = getNerabyEntities(double,double,double).

    But how would I specify wolf in that case? From what I see in the source of ProtectingWolf,
        public static List<Wolf> getNearByWolves(Player player) {
            List<Wolf> wolves = new ArrayList<Wolf>();
            for (LivingEntity entity : player.getWorld().getLivingEntities()) {
                if (entity instanceof Wolf) {
                    Wolf wolf = (Wolf) entity;
                    if (wolf.isTamed() && player.getName().equals(getWolfOwnerName(wolf))) {
                        boolean found = false;
                        List<Entity> nearBy = wolf.getNearbyEntities(40, 10, 20);
                        if (nearBy.size() > 0) {
                            for (Entity nearByEntity : nearBy) {
                                if (nearByEntity.getEntityId() == player.getEntityId()) {
                                    found = true;
                            if (found) {
    Which I guess means it "int getEntityId()"s the wolf, and then you use that specific EntitiyId as prefix to the .setTarget?

    EDIT: Programming plugins for bukkit surely isn't a walk in the park! Mad respect to you developers.
    Last edited: Oct 22, 2015
  8. Offline


    You would loop through the list and make sure the Entity is a wolf and then do stuff based on that.
Thread Status:
Not open for further replies.

Share This Page