Cast Entity Id to Living Entity??

Discussion in 'Plugin Development' started by Nico4898, Aug 23, 2014.

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

    Nico4898

    Hi there,
    I just wanted to know if its possible to define a LivingEntity of the EntityId , I saved in a Hashmap ?
     
  2. Offline

    mine-care

    Unfortunately you have to loop thru all entities on a world and if their I'd matches the one you have then do
    If(entity instanceof LivingEntity){
    LivingEntity Len = (LivingEntity) entity;

    }
     
  3. Offline

    Zupsub

    Why did you saved it's id? Save the entity itself instead.
     
  4. Offline

    unon1100

    Zupsub Bad idea. Storing entire entities is a bad idea, especially if you forget to remove them, as Entities are pretty large objects and will cause memory leaks if you do something reckless. Storing EntityID or UUID is a better idea.
     
  5. Offline

    Zupsub

    Java only uses references, so saving an entity cost the same memory as saving an UUID.
    However, saving the entity in a HashMap would cause the gc to let the whole entity in memory, even if it isn't needed.

    So instead, just use a WeakHashMap. Problem with the gc solved and no need to loop threw all entities.
     
Thread Status:
Not open for further replies.

Share This Page