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

How to create block allways

Discussion in 'Development' started by Hoyee, Mar 16, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    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 '->'
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    public function onPlace(BlockPlaceEvent $event){
        
    $block $event->getBlock();
        
    $pos $block->add(01);

        if((
    $block->getId() === Block::GLASS) && ($block->getLevel()->getBlock($pos)->getId() === Block::AIR)) {
            
    $block->getLevel()->setBlock($posBlock::get(Block::SAND));
        }
    }
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    But that doesn't work allways. that works only one time
     
  4. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    Do you want to make some kind of sand generator?
     
  5. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    maybe
     
  6. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    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
     
    Last edited: Mar 16, 2020
  7. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    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.
     
  8. Invy55

    Invy55 Witch

    Messages:
    52
    GitHub:
    invy55
    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 :rolleyes:
     
  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.