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

setBlock

Discussion in 'Development' started by SkySeven, May 9, 2017.

  1. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Hello,
    How to use setBlock() without creating lags ?
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    First, setBlock() won't just lag the server super hard just because you use it, you just have to be careful using with large operations. For large operations, I at least recommend you set $direct and $update to false, so blocks don't get updated. So for example:
    $level->setBlock($position, new Stone(), false, false);
     
    HimbeersaftLP and SkySeven like this.
  3. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    Ok, thanks for your answer !
     
  4. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
  5. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    $direct is unused.(see below)
    Then you're doing it in the wrong way. Read the post again.
    P.S. @falk typo in your post! It should be "asynchronous" not "asyncronous".
     
    Last edited: May 11, 2017
    jasonwynn10, HimbeersaftLP and falk like this.
  7. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    SOFe and jasonwynn10 like this.
  8. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    With future API changes in mind, you should not do this, but instead prefer using:
    Code:
    Block::get(Block::STONE)
    
    This is because in the upcoming ALPHA6 update, block objects need to be initialized with certain properties, which must be passed in the constructor.

    In ALPHA6, Block types may also be overridden by plugins. For example a plugin could replace the Stone type in the global index with a custom Stone which is Fallable. Using Block::get() provides the ability to allow plugins to modify the behaviour, in the same way that Entity::createEntity() may return custom Entity types.

    The constructors should not be used directly unless you want to create a block type to register into the index. Same thing applies to item types and enchantment types.
     
    Last edited: May 11, 2017
    SkySeven, SOFe, jasonwynn10 and 3 others like this.
  9. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're right, I typed that just before seeing you changed all new Block()s to Block::get() in PMMP ;)
     
    jasonwynn10 likes 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.