Solved Cast Entity to LivingEntity

Discussion in 'Plugin Development' started by Casier, Jan 15, 2013.

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

    Casier

    Hi everybody !

    I just have a little problem. Bukkit has change the method for spawning mob from spawnCreature to spawnEntity. The disadvantage is the spawnCreature method returned a LivingEntity and the new spawnEntity method returns a Entity. In my plugin. I need to get a LivingEntity to set the equipment of the spawned mob and potion effect. So here's is my question, how can i get a LivingEntity from an Entity ?

    I've tried to cast it, but my server returns that the Entity can not be cast to a LivingEntity

    Thanks !
     
  2. Offline

    raGan.

    if(entity instanceof LivingEntity) {
    LivingEntity living = (LivingEntity) entity;
    }
    Has to work.
     
    Ne0nx3r0 likes this.
  3. Offline

    Casier

    So, if it should work, why i have this:
    Code:
    org.bukkit.craftbukkit.v1_4_6.entity.CraftWitherSkull cannot be cast to org.bukkit.entity.LivingEntity
    With this lines:
    PHP:
    LivingEntity ent = (LivingEntityp.getWorld().spawnEntity(p.getTargetBlock(null1000).getLocation(), EntityType.WITHER_SKULL);
     
  4. Offline

    Craftiii4

    Because your getting a block, not an entity.

    Sorry miss read the code - Have you tried just making it an entity?
     
  5. Offline

    devilquak

    I don't think that a wither skull is a living entity.
     
  6. Offline

    raGan.

    ^ That.
     
  7. Offline

    Casier

    Thanks !

    So i can't set an equipment and the max health of a wither skull ?
     
  8. Offline

    fireblast709

    no, as projectiles don't have health and equipment ;3
     
  9. Offline

    devilquak

    You seem to be confusing the different types of entities involved here.

    A CraftWitherSkull is the actual Wither Skull item, the one that you can hold in your inventory and place on the ground.

    A Wither_Skull is the projectile that Withers shoot from their heads. It is its own entity, separate from Wither entities. It is not a living entity, it's a flaming ball of power that wants to destroy you.

    A Wither, just "Wither" alone, is the Wither mob. It is a living entity.
     
    Casier likes this.
  10. Offline

    Casier

    dude, i thought that the wither skull was the wither skeleton (I'm French !). You just save me ! Thaaaannks !
     
    devilquak likes this.
  11. Offline

    kasszz

    Nooo, I have the same type of problem only then with a creeper.setPowered(true);

    Code:
                        if(entity instanceof Creeper){
                            getLogger().info("4");
                            LivingEntity creeper = (LivingEntity)entity;
                            creeper.setPowered(true);
                        }
    error:
    The method setPowered(boolean) is undefined for the type LivingEntity
     
  12. Offline

    raGan.

    Why don't you cast it to creeper then ?
     
  13. Offline

    kasszz

    O sorry, I forgot to mention. I want a creeper to get changed when an enderman hits the player, and I allready got that working, it really is just the creeper.setPowered(true); that doesn't work
     
  14. Offline

    SchemingWeasels

    How do i do it for a zombie?
    Code:java
    1. EntityEquipment invent = ((LivingEntity)TankZombie).getEquipment();


    Im getting TankZombie cannot be cast to org.bukkit.LivingEntity
    I tried
    Code:java
    1. EntityEquipment invent = ((LivingEntity) (Entity)TankZombie).getEquipment();


    And i got TankZombie cannot be cast to org.bukkit.Entity
     
Thread Status:
Not open for further replies.

Share This Page