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


    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:
            Skeleton s = (Skeleton) loc.getWorld().spawnEntity(loc, EntityType.SKELETON);
            skeletonTypeStore.put(s, type);
            ZombieListenerDamage.livesStore.put(s, lives);
            ZombieArenaPrice.entityMoneyStore.put(s, price);
    Does somebody know how to equip them?
  2. Offline


    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


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


    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)

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

    So this will work out into (including an extra function for armor, just to clarify a little bit more):
    1. public void setItemInHand(ItemStack i, LivingEntity le)
    2. {
    3. ((CraftLivingEntity)le).getHandle().setEquipment(0, ((CraftItemStack)i).getHandle());
    4. }
    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


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


    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