Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

spawn entity in unloaded chunk

Comments in 'Plugin Development' started by Creeperface, Aug 5, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    hi when i spawn entity in unloaded chunk it call EntityDeathEvent after few seconds but when i load that chunk entity is still there
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Delete entity:
    PHP:
    public function onEntityDeath(EntityDeathEvent $event){
    $entity $event->getEntity();
    $entity->getLevel()->removeEntity($entity);
    }
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but i dont want to kill entity i ask why it call deatEvent
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    when i load chunk than spawn entity it call death event too
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Maby it tries to despawn? Load chunk after spawning it.
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    hm i cancel event when it is not instance of entitydamagebyentity event
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    PHP:
    public function onEntityDamage(EntityDamageEvent $event){
    $entity $event->getEntity();
    if(!(
    $entity->getLevel()->isChunkLoaded($entity->getFloorX(), $entity->getFloorZ()))) $event->setCancelled(true);
    }
    If it calls EntityDamageEvent try code above
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    thx and what is different between getX() and getFloorX()
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Player is standing on X: 83
    PHP:
    $player->getX() // Returns 83.591251251
    PHP:
    $player->getFloorX() // Returns 83
    xiaoq likes this.
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so getFloor is block under player?
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Not really. getFloor() returns integer. but getX() return float.
    xiaoq likes this.
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    ant it doesnt work still calling deathEvent
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Maby it triggers death same as : "Suffocated in wall"
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use $event->getCause() to find out the reason why the entity died.
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    no because when i come to the entity it is still alive and i can kill it

Share This Page

Advertisement