Convert EntityType to entityliving?

Discussion in 'Plugin Development' started by ServerfromMinecraft, Sep 15, 2012.

Thread Status:
Not open for further replies.
  1. Hi! How i can convert from EntityType to livingentity? Because i would, after spawning, modify the stats of this entity - but its not possible to modify a EntityType - and its also not possible to spawn a LivingEntity

    (its a zombie)
     
  2. Offline

    Seadragon91

    Example for a sheep:
    Code:
    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if (event.getEntity().getType() == EntityType.SHEEP) {
          Sheep sheep = (Sheep) event.getEntity(); 
          //  your code
        }
    }
    
    With event.getEntity() you get the spawned creature, check the type of the creature and then cast it into the right class.
     
  3. Hm, no, because its my Plugin that spawn the entity - and then i would change some stats of this spawned entity, but for that i need a entityLiving :/

    Code:
    loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
    
    I would change the stat of this spawned EntityType.ZOMBie :/
     
  4. Offline

    Tzeentchful

    Have you tried using the spawn creature method? it retuns a living entity.

    Code:
    LivingEntity datZombie = loc.getWorld().spawnCreature(loc, EntityType.ZOMBIE);
     
  5. spawnCreature is deprecated :/
     
  6. Offline

    Tzeentchful

    it still works though.

    If you really want to avoid using spawnCreature you could try cast it. im not sure it will work though.
    Code:
    LivingEntity datZombie = (LivingEntity) loc.getWorld().spawnEntity(loc, EntityType.ZOMBIE);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  7. Ah ok :)

    And if i cast it?
    edit: ok, i try it :d thanks :D

    and another question: how i can "hook in" another file in a commandexecuter?

    Because if i do

    Nameofheclass settings; and use settings.themethod
    its give me no errors in eclipse but maake a nullpointerexception on use..
     
  8. Offline

    Tzeentchful

    I would just create an instance of the class you want to access.

    Code:
    YourClass yclass = new YourClass();
     
    if(yclass.noob){
    //bla bla bla
    }
    but the variable you want to access needs to be static.

    Code:
    public class YourClass extends JavaPlugin {
     
    public static boolean noob = true;
     
    }
     
  9. Hm, but the problem is that the methods that i would use is in the listener, and the listener has the constructor with the main class -
    Code:
    classic_main plugin;
    public classic(classic_main plugin) {
    this.plugin = plugin;
    }
    And in the other class, if i make

    MyClass mclass = new MyClass(plugin); its not work...
     
  10. The best way is to use "world.spawn"
    Code:
    Zombie yourZombie = world.spawn(location, Zombie.class);
    No need to cast anything, it returns what you pass in thanks to generics.
     
  11. Thanks!
    Its works :D

    But, have you a idea to the problem to hook in another class? (its descripted in the posts over your posts :) )
     
Thread Status:
Not open for further replies.

Share This Page