NpcSpawner lib - spawn basic NPCs

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

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

    lucasdidur

    There is a Bukkit 1.4 update?
     
    Canownueasy likes this.
  2. Offline

    Scizzr

    Pretty sure this should cover the update. It's working as far as I can tell. I'm using build #2415.
    https://dl.dropbox.com/u/12031543/gaming/minecraft/NPCLib/NPCLib#2415_1.zip

    If anything doesn't work, let me know and I'll take a look at it.

    Basically, a few things had to be fixed:
    • The obfuscated variable for yaw in net.minecraft.server.EntityPlayer changed.
    • There was a boolean variable added to the end of explode(...) in BWorld.

    Bug(s) found so far:
    • Updating the NPC's inventory doesn't reflect the changes on the model itself.
    ---- It still drops the item if you kill the NPC and will refresh if you relog.
    ---- Looks like Citizens had the same problem. Minecraft broke it.
    • If you use NoCheatPlus and attack the NPC, it triggers false GodMode warnings.
    [​IMG]

    ** Help squashing these would be appreciated! **

    Cheers!
     
  3. Offline

    Cue

    Does anyone know if there's a Maven Repo for this? I'm doing the much needed conversion to Jenkins-based building and it'd be really helpful if I could get a Maven repo for NPCLib.
     
  4. Offline

    Scizzr

    https://github.com/Top-Cat/NPCLib

    It's not updated for 1.4.2 though.
     
  5. Offline

    Cue

    Woah woah woah, you can use Github as a Maven Repo?

    Mind. Blown.
     
  6. Offline

    Scizzr

    Fixed the bug with gear not updating when you update it. You just have to call HumanNPC.updateEquipment() when you want to update it.

    (Thanks to fullwall for the code to fix this bug)

    Sample use:
    Code:
    Location loc = .....; //you need to provide this
    String name = "Notch";
    HumanNPC human = (HumanNPC)plugin.npcmanager.spawnHumanNPC(name, loc);
    human.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
    human.updateEquipment();
    
    Download: https://dl.dropbox.com/u/12031543/gaming/minecraft/NPCLib/NPCLib#2429_1.zip

    If anything else doesn't work, let me know and I'll take a look at it.

    Cheers!
     
  7. Offline

    fullwall

    Scizzr - there was a bug in the code I put up yesterday (getEquipment() returns only the armor, not including the item in hand). New commit should work better. Also note that the method is a temporary fix for what looks like an issue with EntityTracker.
     
    devilquak likes this.
  8. Offline

    Scizzr

    The code I am using seems to work. I'll do some more testing to be sure and edit this in awhile.

    Edit: Yeah, both the modified version of your previous code and your current code work. Here's what I have:
    Code:
    int changes = 0;
     
    for (int i = 0; i < previousEquipment.length; i++) {
        net.minecraft.server.ItemStack previous = previousEquipment[i];
        net.minecraft.server.ItemStack current = ((EntityPlayer)getEntity()).getEquipment(i);
        if (current == null) { continue; }
     
        if (!net.minecraft.server.ItemStack.equals(previous, current) || (previous != null && !previous.equals(current))) {
            NPCUtils.sendPacketNearby(getBukkitEntity().getLocation(), new Packet5EntityEquipment(getEntity().id, i, current));
            ++changes;
        }
    }
     
    if (changes > 0) {
        previousEquipment = Arrays.copyOf(((EntityPlayer)getEntity()).getEquipment(), previousEquipment.length);
    }
    
    I noticed that there was a strange bug when you updated the equipment (it's hard to explain) so I added || (previous != null && !previous.equals(current)) to the boolean check and it fixed it. I figured out that for some reason, previous was null and because of that, the equals() check was true even though it should not have been.[/I]

    tl;dr - I guess both sets of code work, however your updated code is indeed cleaner to read.

    Again, thanks for figuring out how to fix this and hopefully Bukkit'll fix it to pre-1.4 status (aka working properly).

    Cheers!
     
  9. Offline

    fullwall

    Scizzr - no, you misunderstand. The problem is
    Code:
    previousEquipment = Arrays.copyOf(((EntityPlayer)getEntity()).getEquipment(), previousEquipment.length);
    getEquipment() returns only the armour, not the item in hand, so you miss updating one piece of equipment and the rest are shifted to the left.
     
  10. Offline

    Scizzr

    Yes, I see. Oddly though, I didn't have that problem. I did testing with both sets of code and that never happened to me. :confused:
     
  11. Offline

    Neodork

    Code:
    public void updateEquipment() {
    	 public void updateEquipment() {
    		 for (int i = 0; i < previousEquipment.length; i++) {
    			 net.minecraft.server.ItemStack previous = previousEquipment[i];
    			 net.minecraft.server.ItemStack current = ((EntityPlayer)getEntity()).getEquipment(i);
    			 if(previous != current) {
    				 NPCUtils.sendPacketNearby(getBukkitEntity().getLocation(), new Packet5EntityEquipment(getEntity().id, i,current),range); 
    				 previousEquipment[i] = current;
    			 }
    		 }
    	 }
    
    Works like a charm, thanks guys.
     
  12. Offline

    bubbleguj

    Hey,
    I want a npc to attack a Player... How to set setTarget() or something like this?

    And npc.getBukkitEntity().getLocation().setYaw(yaw); doesn't works :(( PLEASE FIX THIS, or any other ways to do this? Lookat doesn't works for me :(

    And how to make Npcs damageable... I can't damage them -.- They just are red but nothing happens ...

    And attackLivingEntity() doesn't excist in this library or it just doesn't work...

    And ItemInHand doesn't work for me too.. :(
    Please fix this things :((
     
  13. Offline

    Uniclaw

    Just one question: How you have set the skins of the NPC's in the code :eek:?
     
  14. Offline

    Scizzr

  15. Offline

    bubbleguj

    Bugs still not fixed -.-
     
  16. Offline

    GuptaGuptapune

    Sorry, but am i missing something, on reload/restart all the npcs dissappear, is this meant to happen or is this just me?
     
  17. Offline

    jeremytrains

    This is meant to happen. My plugin, NPCWarehouse, saves all NPC data to a file on disable, and loads it on enable.
     
  18. Offline

    jeremytrains

    I have a bug. I don't know how to fix it. In 1.4.4, all NPCs' heads look the same way (Minecraft compass south). When I use the method lookAtPoint(Location loc), the body (stomach and legs) turn to the correct place, but the head faces the same way. How do I fix this? All of the users of my plugin have this problem.
     
  19. Thats this new line:
    Code:
    ((EntityPlayer) getEntity()).bS = (float) (newYaw - 90);
    In the lookAtPoint function. In version 1.3.2 (Craftbukkit) this bS was as .. Why do you have to set this ? And why do they call this variables so meaningless ??
     
  20. Offline

    jeremytrains

    caliog
    I am using that line. The lookAtPoint method is:

    Code:
    public void lookAtPoint(Location point) {
            if (getEntity().getBukkitEntity().getWorld() != point.getWorld()) {
                return;
            }
            Location npcLoc = ((LivingEntity) getEntity().getBukkitEntity()).getEyeLocation();
            double xDiff = point.getX() - npcLoc.getX();
            double yDiff = point.getY() - npcLoc.getY();
            double zDiff = point.getZ() - npcLoc.getZ();
            double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
            double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
            double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
            double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
            if (zDiff < 0.0) {
                newYaw = newYaw + Math.abs(180 - newYaw) * 2;
            }
            Logger.getLogger("Minecraft").info("yaw = " + (newYaw - 90) + " and pitch = " + newPitch);
            getEntity().yaw = (float) (newYaw - 90);
            getEntity().pitch = (float) newPitch;
            ((EntityPlayer)getEntity()).bS = (float)(newYaw - 90);
        }
    The methods are called meaningless names because the source code is obfuscated. This means that the names of classes, methods, and variables are all changed to random letters (a, aa, b, bB, cH, etc.) in order to prevent other coders from decompiling Minecraft and changing code. The methods are put in alphabetical order (a, b, ... y, z, aa, ab, ...). That is why whenever a new method is added, the method names change. This is why this library usually only works with the version that is specified. Every time Minecraft updates, most of the method names change in the minecraft (and Bukkit) server jar.

    Back to my question: how do I fix this? I am using that line of code and it still does not work.

    Edit: forgot to mention that the logging statement (Logger.getLogger...) outputs the correct yaw and pitch that the head should be at. It seems it is only setting the body's yaw and pitch.
     
  21. Offline

    Neodork

    They obfuscate the code to make it hard for others to read. This has many purposes as mentioned on the wiki page.

    You can search for the changed values in the commits to craftbukkit, like this one:
    [​IMG]

    Every time you update your plugin from one build to another errors might show up. These errors are the changed values that were changed in the craftbukkit source. You will have go and look for a commit like the one shown above. Look up the values and change them into the new ones.
     
  22. jeremytrains
    Thats what I wanted to say. This code line is not working correctly.
    Because if you try to set the yaw of the head you have to set it two times.
    For the first time it works (getEntity().yaw=...) but the method (bs()) doesn't work.
    You just have to find out what the name of the old method bS is right now.

    EDIT: It sets the Pitch of the Head correctly. (Look up and down)
     
  23. Offline

    jeremytrains

    Neodork caliog
    So I have done some research on the code changes in the class EntityHuman (where bS was located). It seems that it has been renamed to bP, but that still doesn't work. I tried all floats in the class EntityHuman (bO, bP, ca, and cb). None of them work. Let me know if you find anything - NPCWarehouse depends on it. I am going to setup a method that tries setting every single double or float accessible from the ((EntityPlayer)getEntity()) class, maybe I can narrow it down with that. I will let you know the results.
     
  24. Offline

    Neodork


    You can try this one:

    ((EntityPlayer)getEntity()).ay = (float)(newYaw - 90.0);
     
  25. That works !! :D nice thank you very very much :) Here is my Code :
    Code:
    getEntity().yaw = (float) (newYaw - 90);
    getEntity().pitch = (float) newPitch;
    ((EntityPlayer) getEntity()).ay = (float) (newYaw - 90);
    
    The npc turns his head !
     
  26. Offline

    jeremytrains

    caliog
    Thank you! I couldn't get the "scanner" to work, but it seems you have! Thank you very much! NPCWarehouse's bug is now fixed!
     
  27. Offline

    Maro

    Am I the only one getting lots of errors with this in 1.4.5? And I don't know how to fix them.
     
  28. Offline

    zta192

    I'm have the same issues. I can't seem to fix it either. Hopefully someone will be able to post an update.
     
  29. Offline

    Maro

    Found it out. All the classes from net.minecraft.server have been renamed, so you have to import the new ones.
     
  30. Offline

    zta192

    I still seem to be having some issues with it. I changed the imports to include the .v1_4_6 and that did fix quite a bit of the problems but some things like ItemInWorldManager in the NPCManager class are still giving errors.
     
Thread Status:
Not open for further replies.

Share This Page