Hep with getting baby cows to spawn!

Discussion in 'Plugin Development' started by tooncool64, May 8, 2014.

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

    tooncool64

    Ok, i am making a plugin. The plugin makes every cow in the world a baby, and when it hits you it catches you on fire.
    Could someone look at my code and tell me how to make every cow a baby?
    Here is my main class:
    Code:java
    1. package plugin5;
    2. import org.bukkit.entity.Cow;
    3. import org.bukkit.event.Listener;
    4. public class Main{
    5. void setBaby(boolean flag){
    6.  
    7.  
    8.  
    9. }
    10. }
    11.  
    12.  

    Here is my spawn class:
    Code:java
    1. package plugin5;
    2. import org.bukkit.event.entity.CreatureSpawnEvent;
    3. import org.bukkit.entity.CreatureType;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.LivingEntity;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.entity.Creature;
    8. @SuppressWarnings("deprecation")
    9. public class Spawn{
    10.  
    11.  
    12. @Deprecated
    13. public CreatureType getCreatureType(){
    14. return (getCreatureType());
    15.  
    16. }
    17. }
     
  2. tooncool64
    What is up with the random void method and an infinite loop?
    Answer to your question: You can use World#spawnEntity() to spawn an entity of given type at given location. It returns Entity, which's attributes you can modify.
    Code:
    Cow cow = (Cow) someWorld.spawnEntity(someLocation, EntityType.COW);
    cow.setBaby(true);
    Edit: I misread your question. Use World#getEntitiesByClass(Cow.class) and then set the cows to baby.
     
  3. Offline

    rsod

    1) you should listen for CreatureSpawnEvent, check, if it's a cow is about to be spawned and if so, then turn it to baby
    2) if you think that world already contain cows, and you want them to turn to baby, use ChunkLoadEvent and check all entites in chunk, and if it's a cow, turn it to baby
    Not going to write code, btw
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page