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

Automatic tnt igniting when placed

Discussion in 'Development' started by Saxavlax001, Aug 31, 2020.

  1. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I want to make a custom tnt item,which when you try to place it in ground,it will be ignited automatically and then it will explode like a normal tnt,but I have problems though.

    Firstly,if I try to place a normal tnt or the automatic tnt I made in the air,an ignited tnt is being spawned.

    Secondly, if I place again those tnts in ground,it seems that a non ignited tnt is placed and then after some blocks away,an ignited tnt is being spawned and it blows up the with the other tnt.

    The result I ought to expect,would be after placing the tnt with custom name,(automatic tnt),I should have seen the tnt I just placed being ignited etc. but it didn't happen exactly.

    PHP:
        /**
         * @param BlockPlaceEvent $event
         */
        
    public function onPlace(BlockPlaceEvent $event) {
            
    $player $event->getPlayer();

            
    $block $event->getBlock();
            
    $item $event->getItem();
            
    $hand $player->getInventory()->getItemInHand();
            if(
    $hand->getName() === "§l§6Automatic §eTNT" and $hand->getId() === Block::TNT) {
                
    $block->ignite();
                
    $hand->pop();
                
    $player->getInventory()->setItemInHand($hand);
                
    $block->getLevel()->setBlock($blockBlock::get(Block::AIR));
            }
         }
    I may did some mistakes when checking the custom tnt placing,but I couldn't find anything helpful enough on google.I just want someone to help me if it's possible.
     
  2. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I tried to make also some different checks and add different codes to make those tnts work but I got same results.
     
  3. Ayzrix

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    You need to make a « new tnt » and extend the real tnt
     
  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.