Code: public function Sand(BlockPlaceEvent $event){ $block = $event->getBlock(); $pos = new Position($block->getX(), $block->getY() + 1, $block->getZ(), $block->getLevel()); if( ($block->getId()==20) && ($block->getY()+1 ->getBlock()->getId() == 0 ){ $block->getLevel()->setBlock($pos, Block::get(12)); }//if } I want to make if glass's y+1 is 0(Air), create Sand in there. it crash "syntax error, unexpected '->'
PHP: public function onPlace(BlockPlaceEvent $event){ $block = $event->getBlock(); $pos = $block->add(0, 1); if(($block->getId() === Block::GLASS) && ($block->getLevel()->getBlock($pos)->getId() === Block::AIR)) { $block->getLevel()->setBlock($pos, Block::get(Block::SAND)); }}
To not destroy your server, I think the best way is to detect the break event, check if under the broked block there is glass cancel the event and give to the player one block of sand
but if I use that way, the item goes to inventory directly, isn't it? so I want to make items come out when I dig up blocks.
Yes, I think the best way is doing like that because else you have to wait the event to be finished to replace the block that will implement a delayed task. I think you can also spawn an item