NpcSpawner lib - spawn basic NPCs

Discussion in 'Resources' started by Redecouverte, Feb 3, 2011.

Thread Status:
Not open for further replies.
  1. Well but it is possible. Ok. Thanks. I'll try it out!
  2. Same problem...
    the EntityDamageByEntityEvent is not triggered when a HumanNPC gets attacked by a player. Nothing happens to the NPC...
  3. It works for me. You have to monitor the EntityDamageByEntityEvent event and then make the npc act hurt.

    2. getHumanNPC().actAsHurt();
  4. With my code the EntityTargetEvent or EntityDamageByEntityEvent is not even fired when I am hitting/rightclicking a NPC... I am using the main part of this code.

    Finally fixed it!
  5. Offline


    Could you tell me how you fixed it? My EntityDamageByEntityEvents are not fired either.
  6. Well the event was called all the time. You could just check at the top of your listener if the entity is instance of a HumanEntity. Then you could continue with your code. Just check with something like "bukkit.broadcastMessage("1"); etc. if the part of the line was even triggered.
  7. Offline



    Neodork and all others
    So should I make a BukkitDev page? Do I have permission?
  8. Offline


    The library was not released by me, so I cannot make decisions for it. If you want to create a BukkitDev page for it you should talk to Top_Cat. I prefer to keep this hard-coded into my plugin to prevent adding any unnecessary dependencies.
  9. Offline


    Anyone have this lib for 1.4.7?
  10. Offline


    I tried that, but my events are not even triggered. I had a line at the top of my method and it said
    Logger.getLogger("Minecraft").info("EntityDamageByEntityEvent - wasNPC:" + plugin.manager.isNPC(event.getEntity()));
    The line was never shown when I hit the NPC, but it did pop up when a pig died and it said "EntityDamageByEntityEvent - wasNPC:false" I can't figure this out!
  11. Offline


  12. Offline


    Yes. This is the constructor:

    public NPCManager(JavaPlugin plugin) {
            server = BServer.getInstance();
            try {
                npcNetworkManager = new NPCNetworkManager();
            } catch (IOException e) {
            NPCManager.plugin = plugin;
            taskid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                    HashSet<String> toRemove = new HashSet<String>();
                    for (String i : npcs.keySet()) {
                        Entity j = npcs.get(i).getEntity();
                        j.y(); //jeremytrains: z -> y
                        if (j.dead) {
                    for (String n : toRemove) {
            }, 1L, 1L);
            Bukkit.getServer().getPluginManager().registerEvents(new SL(), plugin);
            Bukkit.getServer().getPluginManager().registerEvents(new WL(), plugin);
  13. Offline


    Neodork Any other suggestions?
  14. Offline


    I'll be looking into it once I have some time.
  15. Offline


    If it helps, I am making guards. When a wolf is in range of the NPC, I call the damageEntity() method, and then send an arm movement packet to nearby players. If the wolf is hurt by the damageEntity() method, then the wolf will attack the NPC, the NPC will blink red (like it is hurt), and then once it is attacked enough the NPC will die and an EntityDeathEvent will be fired. So, the problem is - what is the difference between a player damaging an NPC and a wolf? Is there any way for me to listen for PlayerLeftClickEntity or something? If so, I will manually call the Player.damageEntity(HumanNPC.getBukkitEntity()) method. Thanks!
  16. jeremytrains
    Yes, for the NPC you will have to implement your own health tracking system, it's what I have had to do for my plugin.
  17. Offline


    Adamki11s Neodork
    Sorry for the trouble. It is actually fine. I made a stupid mistake - I had pvp set to false in my *facepalm*
  18. Offline


    Where can I download this?
  19. Does somebody know how to compare the locations two objects are looking at? Well what I want to do is to check if a npc sees the player/faces him/looks close to his direction. I've tried to figure that out at my own but didn't succeed yet.

    Help is welcome!
  20. Offline


    Get the locations from the objects and compare them? Did you try to use entity.getNearbyEntities?
  21. Offline


    Hi everyone
    I need some help:
    So, I want to hit an NPC (EntityDamageByEntityEvent)
        public void onEntityDamageByEntity(EntityDamageByEntityEvent evt) {
            Player damager = (Player) evt.getDamager();
            NPCManager NPCMan = new NPCManager(plugin);
            if(NPCMan.isNPC(evt.getEntity())) {
                String npcID = NPCMan.getNPCIdFromEntity(evt.getEntity());
                plugin.getLogger().info("Is NPC!");
                plugin.getLogger().info("NPC: " + npcID);
                NPC npc = NPCMan.getNPC(npcID);
                HumanNPC hNPC = new HumanNPC(((NPCEntity) npc.getEntity()));
                if ((npc != null) && (damager instanceof Player)) {
                    damager.sendMessage("<" + hNPC.getName() + "> Don't hit me so much!");
    But, the String "npcID" is always null.

    Console says:
    ]Is NPC!
    ]NPC: null

  22. Does somebody has updated the lib to 1.5?

    How to get the IConsoleLogManager? I need it for the NPCNetworkManager...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 8, 2016
  23. Offline


    I have already found it. ;)
    Der_Udo likes this.
  24. Thanks!
  25. I just found out that my npcs look to the wrong location when they walk. This is my recent code:
        private void pathStep() {
            if (pathIterator.hasNext()) {
                final Node n =;
                if (n.b.getWorld() != getBukkitEntity().getWorld()) {
                } else {
                    float angle = getEntity().yaw;
                    float look = getEntity().pitch;
                    if (last == null || runningPath.checkPath(n, last, true)) {
                        if (last != null) {
                            angle = (float) Math.toDegrees(Math.atan2(last.b.getX() - n.b.getX(), n.b.getZ() - last.b.getZ()));
                            look = (float) (Math.toDegrees(Math.asin(last.b.getY() - n.b.getY())) / 2);
                        getEntity().setPositionRotation(n.b.getX() + 0.5, n.b.getY(), n.b.getZ() + 0.5, angle, look);
                        ((EntityPlayer) getEntity()).az = angle;
                    } else {
                last = n;
            } else {
                getEntity().setPositionRotation(runningPath.getEnd().getX(), runningPath.getEnd().getY(), runningPath.getEnd().getZ(), runningPath.getEnd().getYaw(), runningPath.getEnd().getPitch());
                ((EntityPlayer) getEntity()).az = runningPath.getEnd().getYaw();
                taskid = 0;

    And to be honest I can't figure out how to prevent them from teleporting when the amount of iterations is not enough to get them to the "goal" location. I want them to just stop then...

    Help is much welcome!
  26. Offline


    Where you have
     ((EntityPlayer) getEntity()).az = angle; 
    Try changing it to...
     ((EntityPlayer) getEntity()).aA = angle; 
    Der_Udo likes this.
  27. Thanks :D

    Just one thing left: My npcs dissappear when they get attacked by an explosion. Does this happen to you too? And did you fix it?

    Well the npc is still there and is able to walk and attack etc. just like normal but it becomes invisible...
  28. Is there an updated version of the full npc lib ?
    Does someone know a internet page or something where you can see how the new names of the old methods is ?
    And who is the creator or developer of this lib ? I would like to help to update it and to fix bugs etc.
  29. Offline


    To get new method names, try searching around on The only method that I can't fix (compiler error wise) is the following line:
    AxisAlignedBB box = net.minecraft.server.v1_5_R2.Block.byId[b.getTypeId()].e(((CraftWorld) b.getWorld()).getHandle(), b.getX(), b.getY(), b.getZ());
    Does anybody else have a fix? I am updating from 1.4.7 to 1.5.1. The problem is that the method "e" no longer exists. The website above suggests it was renamed to "g", but the method "g" is void and does not return an AxisAlignedBB
  30. But its really hard to search around there..
    Can you tell me the new name of the c_(EntityHuman entity) function in
    And how did you manage the new super constructor in where you need a IConsoleLogManager object for the constructor of the NetworkManager ?
Thread Status:
Not open for further replies.

Share This Page