Give mobs armour

Discussion in 'Plugin Development' started by PureGero, Feb 24, 2013.

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

    PureGero

    Is there any way to give mobs armor, that works for the latest craftbukkit version? I want a simple function that takes in (ItemStack),(slot int) and (Entity) and will change the entity's equiptment
     
  2. Offline

    hatstand

    You're after entity.getEquipment() - Gives you an EntityEquipment object that allows you to set the armor, item in hand, and drop chances.
     
  3. Offline

    PureGero

    hatstand I did try this, but i can't convert Entity to EntityLiving to use this, is there any other way?
     
  4. Offline

    hatstand

    Check if the entity is an instance of EntityLiving, if it is, cast it.

    Unless you want to go digging around in CB internal stuff, which is a terrible idea, and more complex than that.
     
  5. Offline

    PureGero

    hatstand When I cast it, the console just gives errors

    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_4_R1.entity.CraftZombie cannot be cast to net.minecraft.server.v1_4_R1.EntityLiving
     
  6. Offline

    hatstand

    Just double checked that, you're after LivingEntity, not EntityLiving - The former is a Bukkit class, the latter is an NMS class. Hence the exception.

    For reference, this is a similar section of code I'm using:
    Code:
                EntityType type = event.getEntityType();
     
                if(type == EntityType.ZOMBIE || type == EntityType.SKELETON)
                {
                    SpawnReason reason = event.getSpawnReason();
     
                    if(reason == SpawnReason.NATURAL)
                    {
                        LivingEntity entity = event.getEntity();
     
                        EntityEquipment equips = entity.getEquipment();
    This is in a handler for a CreatureSpawnEvent, so I don't need to cast it.
     
  7. Offline

    PureGero

    Sorry, i was using .setEquiptment() not .getEquiptment()
     
  8. Offline

    gamerzap

    You should be warned that armor doesn't render for non-undead mobs. (At least, I think it doesn't)
     
  9. Offline

    Benlewis9000

    Would this also work for implementing player heads and overriding skeletons with bows?
    PureGero
     
  10. Offline

    jusjus112

Thread Status:
Not open for further replies.

Share This Page