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

Solved setBlock() issue in task

Discussion in 'Development' started by KielKing, Dec 21, 2018.

  1. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    Hello forums, I am trying to set a beacon that shoots a beam of light into the sky, and change the color depending on a condition, here is my code: (note) this is a task running every 20 ticks
    PHP:

    foreach($this->plugin->config->get("key") as $name => $val){
        
    $level $this->plugin->getServer()->getLevelByName(explode(":"$val["pos1"])[3]);
        if(
    $level == null) continue;

        
    $beaconXyz $this->plugin->getBeaconVector($val["pos1"], $val["pos2"]);
        if(
    $beaconXyz == null) continue;

        if(
    $this->plugin->isActivated($name)){
            if(
    $level->getBlockDataAt($beaconXyz->getX(), $beaconXyz->getY() + 1$beaconXyz->getX()) !== 13){
                
    $level->setBlock($beaconXyz->add(01), Block::get(Block::STAINED_GLASS13), falsefalse);
            }
        }else{
            if(
    $level->getBlockDataAt($beaconXyz->getX(), $beaconXyz->getY() + 1$beaconXyz->getX()) !== 14){
                
    $level->setBlock($beaconXyz->add(01), Block::get(Block::STAINED_GLASS14), falsefalse);
            }
        }
        if(
    $level->getBlockIdAt($beaconXyz->getX(), $beaconXyz->getY(), $beaconXyz->getZ()) !== Block::BEACON){
            
    $level->setBlock($beaconXyzBlock::get(Block::BEACON), falsefalse);
            
    Tile::createTile("Beacon"$levelBeacon::createNBT($beaconXyz));
        }
        for(
    $x $beaconXyz->getX() - 1$x <= $beaconXyz->getX() + 1$x++){
            for(
    $z $beaconXyz->getZ() - 1$z <= $beaconXyz->getZ() + 1$z++){
                if(
    $level->getBlockIdAt($x$beaconXyz->getY() - 1$z) == Block::EMERALD_BLOCK) continue;
                
    $level->setBlock(new Vector3($x$beaconXyz->getY() - 1$z), Block::get(Block::EMERALD_BLOCK), falsefalse);
            }
        }
    }
    the issue:
    when I break the beacon, it does not re appear, and everything I do to the world does not edit / save unless I add $level->save(true), and even then, it does not fix that the beacon does not re appear

    let me explain some of my functions and or code:
    $val is an array which contains the key "pos1" with the value of "0:0:0:Spawn"
    getBeaconVector() returns a new Vector3 instance
    isActivated() returns a bool

    if you have any idea of why this is or have a lead, please do reply
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    note, the beacon tile is implemented by TeaSpoon, so if you want to look at the source code of it you can go to the GitHub repo
     
  3. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    (note) Level::getBlockDataAt() returns the damage of the block
     
  4. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    175
    GitHub:
    diamondgamermcpe
    Create an issue on GitHub.
     
  5. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    (FIX) DO NOT START THE TASK RIGHT AFTER THE LEVEL IS LOADED

    Make a delayed repeating task with the minimum delay of 20 * 10 ticks

    let the 3rd and 4th parameter of setBlock() be default

    check if the level is corrupted, use another level and test it
     
    Muqsit likes this.
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Well, consequences. So the tile wasn't registered when you called Tile::createTile() outside the task.
     
  7. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    outside the task? Tile::createTile() was inside the task, I don't understand what you mean lol:confused:
     
  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.