How to equip a skeleton with a bow?

Discussion in 'Plugin Development' started by black_ixx, Nov 17, 2012.

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

    black_ixx

    I want to add skeletons to my plugin but when I spawn them they dont have a bow. Ive asked someone a while ago and he said that 1.4.4 is going to allow me to equip skeletons. Well now 1.4.4 was released, but I could not find out how to equip them. My code at the moment:
    Code:
            Skeleton s = (Skeleton) loc.getWorld().spawnEntity(loc, EntityType.SKELETON);
            skeletonTypeStore.put(s, type);
            //s.setHealth(lives);
            ZombieListenerDamage.livesStore.put(s, lives);
            ZombieArenaPrice.entityMoneyStore.put(s, price);
    Does somebody know how to equip them?
     
  2. Offline

    SnowGears

    You will most likely have to use net.minecraft.server , not bukkit to do this.

    Because the Bukkit API is not complete yet, (there is no recommended build for 1.4), the only way to do this is using the actual minecraft server. The rest I do not know, I try to avoid working with NMS when possible. Hope this helped point you in the right direction at least
     
    black_ixx likes this.
  3. Offline

    black_ixx

    Kk thanks. Then I'll continue with waiting for a new bukkit build which contains the feature.
     
  4. Offline

    fireblast709

    Hehe someone is forgetting that he is actually playing the game. Yes ofcourse it is not as safe as Bukkit to use NMS classes, but most of the time it is needed (and it can actually be faster) to use NMS classes (as you also said btw)


    black_ixx
    there is a method in EntityLiving in the NMS code for you
    Code:java
    1. /**
    2. * 0: Tool in Hand; 1-4: Armor
    3.  */
    4. public void setEquipment(int i, ItemStack itemstack)
    5. {
    6. this.equipment[i] = itemstack;
    7. }[/i]

    So this will work out into (including an extra function for armor, just to clarify a little bit more):
    Code:java
    1. public void setItemInHand(ItemStack i, LivingEntity le)
    2. {
    3. ((CraftLivingEntity)le).getHandle().setEquipment(0, ((CraftItemStack)i).getHandle());
    4. }
    5.  
    6. public void setHelmet(ItemStack i, LivingEntity le)
    7. {
    8. // Assuming from bottom to top, it could be that he gets a helmet as chestplate ;D
    9. ((CraftLivingEntity)le).getHandle().setEquipment(4, ((CraftItemStack)i).getHandle());
    10. }

    Obviously, Craftbukkit is needed as a library
     
    Feindbild, Tooner101 and black_ixx like this.
  5. Offline

    black_ixx

    Awesome! It works perfect! :D Diamond for you [diamond]
     
  6. Offline

    SnowGears

    Cool. I will probably use this at some point. Not sure where but I bet it will come up. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page