1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Is there a more efficient way of doing this?

Discussion in 'Development' started by NickteeChunky, Jan 19, 2021.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Hi, I'm trying to prevent items from burning in lava. This is what I've got however I feel as if this method is inefficient since EntityDamageEvent is constantly called and I was wondering if there was a simpler way to do this that wouldn't keep on calling EntityDamageEvent.

    The code I've got can be found below, if it is possible to completely remove ItemEntity collision with Lava so it would just not float on lava, that would be phenomenal, or just not set ItemEntity on fire in collision with Lava.


    PHP:
        public function onDamageEntity(EntityDamageEvent $e): void
        
    {
            
    $damaged $e->getEntity();
            if (
    $damaged instanceof ItemEntity) {
                
    // if ($damaged->getItem()->getId() === 52) {
                    
    $e->setCancelled(true);
                    return;
                
    // }
            
    }
        }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You can cancel EntityCombustByBlockEvent to prevent it from burning
     
    NickteeChunky and Primus like this.
  3. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    This was my first attempt however it didn't work. This is my code.


    PHP:
        public function onEntityCombust(EntityCombustEvent $e){
            
    $burned $e->getEntity();
            if(
    $burned instanceof ItemEntity){
                
    $e->setCancelled();
            }
        }
     
  4. Mcbeany

    Mcbeany Spider Jockey

    Messages:
    33
    GitHub:
    mcbeany
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Seems like cancelling EntityCombustByBlockEvent only prevent it from getting set on fire, but does not prevent the fire damage so you would have to cancel EntityDamageByBlockEvent too, pocketmine's logic..?
     
    NickteeChunky and Mcbeany like this.
  6. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    That's odd, I'll give it a go when I can and let you know.
     
  7. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    There's no other way around it. The only one that comes to my mind is to extend whether ItemEntity or Lava class and change its behavior. On the other hand it seems to be a bit overkill in this case.
     
    NickteeChunky likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.