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

how to prevent tnt explodes from killing players

Discussion in 'Development' started by brokiem, Jul 14, 2020.

  1. brokiem

    brokiem Silverfish

    Messages:
    18
    GitHub:
    brokiem
    how?, and make tnt instant explodes
     
    Last edited: Jul 14, 2020
  2. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    PHP:
    public function onDamage(EntityDamageEvent $event)
        {
            
    $cause $event->getCause();
            if(
    $cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION){
                
    $event->setCancelled(true);
            }
        }
    I'm not sure if it's explosion by entity or by block.

    For instant explode Summon PrimedTNT and remove the tnt when a player place a tnt.
    And execute explode from PrimedTNT
     
    brokiem likes this.
  3. brokiem

    brokiem Silverfish

    Messages:
    18
    GitHub:
    brokiem
    thanks! :D
     
  4. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    It should be by block if I'm not wrong


    Also if you want the players to still be knocked around it's better to set the damage to 0 rather than cancel the event outright
     
  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.