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

Weird block glitch on interact

Discussion in 'Development' started by BruhLol, Nov 27, 2017.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    I get a weird block glitch when i interact with some blocks on an island i created with this code
    Code:
    public function generateChunk(int $chunkX, int $chunkZ) {
            $chunk = $this->level->getChunk($chunkX, $chunkZ);
            $chunk->setGenerated();
            if ($chunkX % 20 == 0 && $chunkZ % 20 == 0) {
                    //set block on chunk
                    }
                Tree::growTree($this->level, $chunkX * 16 + 3, 6, $chunkZ * 16 + 4, $this->random, 0);
                $chunk->setX($chunkX);
                $chunk->setZ($chunkZ);
                $this->level->setChunk($chunkX, $chunkZ, $chunk);
            }
        }
    You can see this gif of what happens ->

    Spawn protection = -1
    Even with no editing on playerinteractevent
    Does anyone know why this is happening or how to fix?
     
    Last edited: Nov 28, 2017
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Does this still happen after relog/are the blocks really gone even afer relog?
     
  3. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    no, the blocks are back after relog but why does this happen?
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    This is really weird, do you have any plugins interfering with PlayerInteractEvent or PlayerActionPacket?
     
  5. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    @Muqsit No, i only have devtools and the plugin i am working on, no event listener yet. This only happens when i generate the island and teleport to it in the same session after loading the level, not after relogging. Also i generate the island at level's spawn and spawn protection is -1, if that has anything to do with it.
     

    Attached Files:

  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    then this suggests a client issue. try teleporting the client out of reach and then in reach again after generating
     
  7. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    what do you mean by out of reach?
     
  8. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    no wait i get the same glitch after respawn only the blocks appear back, you can still interact and the blocks disappear
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    this is really weird, how are you generating exactly and when are you putting the player on top of the island?
     
  10. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
  11. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
  12. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    I did, but I’m pretty clueless. dktapps said there might be a race between chunk sending and generation, but i don‘t understand why and what the result would be.
     
  13. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Call $chunk->setPopulated() after $chunk->setGenerated()
     
  14. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    still happening, i did this -->
    Code:
    $chunk = $this->level->getChunk($chunkX, $chunkZ);
    $chunk->setGenerated();
    $chunk->setPopulated();
     
  15. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    so is their a fix? @robske_110 (Tim)
     
  16. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Did you try calling setPopulated() after you've actually populated the chunk, not before?
     
  17. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    Yes at the end of generateChunk()
     
  18. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    This bug appears to be caused by an issue with Level block object caching. I've encountered this issue myself without plugins, on both newly-generated worlds and worlds loaded from disk. Working on a fix.

    Technical TL;DR: Before chunks are loaded/generated, Level->getBlock[At]() will return, and cache, an AIR block. The bad cache does not later get cleared when chunks are set into the world. This results in the server erroneously thinking that you're clicking on an AIR block and not [whatever] block.
     
    BruhLol, SleepSpace9, Awzaw and 2 others 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.