Getting blocks asynchronously

Discussion in 'Spigot Plugin Development' started by Islandscout, Jun 21, 2018.

  1. I know, it sounds like a stupid question. I'm trying to iterate through blocks in a line and I need to do this on a separate thread, not the main thread. I tried doing this using Bukkit's BlockIterator, but it throws the async entity world add exception. How would I accomplish this?
    • Useful Useful x 1
    • Optimistic Optimistic x 1
  2. Interesting, but it would be a shame to add FAWE as a dependency. Might have to look into if if I can't find any other alternates. Thanks for your suggestion.
  3. ScarabCoder

    ScarabCoder Retired Resource Staff

    You can get a ChunkSnapshot and get the material at a coordinate in that chunk.

    EDIT: ChunkSnapshot was made to asynchronously get blocks in a chunk, I believe it's main purpose was to get block colors for maps without blocking the main thread.
  4. Can it get the data and state of a block? For example, can I use it to tell if a fence is facing one way or another?
  5. md_5

    Administrator Developer

    ChunkSnapshot (created sync) is the only option.
    It's only intended for when you care about a large part of the chunk (as stated above for map renderers), otherwise you should just do it sync.
  6. ScarabCoder

    ScarabCoder Retired Resource Staff

    You can just get the Material and data ID of a block.
  7. Oops. I found out that BlockIterator was iterating to oblivion, loading in chunks and entities async along the way. The distance for the BlockIterator happened to be 0.

    I won't mark this thread as solved, even after I fixed my BlockIterator, since other people with the same question might stumble across this thread.
    #8 Islandscout, Jun 21, 2018
    Last edited: Jun 21, 2018