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

Disable block from placing

Discussion in 'Development' started by xXNiceAssassinlo YT, Mar 24, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    like I don’t want people to place tnt on grass how do I disable that
     
  2. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    PHP:
    public function onPlace(\pocketmine\event\block\BlockPlaceEvent $event){
           
            
    $block $event->getBlock();
            
    $player $event->getPlayer();
           
            if(
    $block->getId() == 46){
               
                
    $event->setCancelled();
                
    $player->sendMessage("§cYou can't place TNT.");
               
            }
        }
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I want to in grass not in every blocks
     
  4. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Simply verify if Y -= 1 is a block of grass
     
  5. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    to verify, you can get coords like
    PHP:
    $player->add(0,-1,0);
     
  6. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    why not just use the subtract function?
    PHP:
    $player->subtract(0,1);
    p.s. There's no need to use the third parameter if it's going to be zero, because it's set at zero by default.
     
    OnTheVerge and korado531m7 like this.
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You shouldn't even use the subtract function :p
    Block::getSide() returns a Block instance. Plus, block below the player is not the block below the block you are mining.
    PHP:
    /** @var BlockBreakEvent $event */
    if($event->getBlock()->getSide(Vector3::SIDE_DOWN)->getId() === Block::GRASS){
        
    $event->setCancelled();
    }
     
    Teamblocket likes this.
  8. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Common sense at it's best
     
    Muqsit likes this.
  9. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    This is arguably the best solution. I didn't even read the original post. I just saw someone using the add function with negative parameters and shook my fist in raging anger.
     
    Teamblocket and Muqsit like 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.