Solved Locating chests in Generated Chunks

Discussion in 'Plugin Development' started by Lorinthio, May 13, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    Hey everyone! So I stumbled into a performance issue and was wondering if the bukkit community could give me priceless feedback!

    My issue...

    I've created an Rpg Plugin that is currently being tweaked for modded server use, and initially used the ChunkPopulateEvent to search for chests in the chunk. However, for some reason the plugin would never catch when there were chests in the chunk.

    So I've changed to ChunkLoadEvent.

    With the ChunkLoadEvent, I check if chunk.isNewChunk(), then search the chunk for a chest by iterating over each column in the chunk from y=0 <= 127.

    How you can help...

    I need help with optimizing the search code as this is EXTREMELY intensive on TPS and such as I'm sure you can imagine. I've already tried to split the column checks into different timed tasks offset to spread out the performance rather than spike lag. But is there an easier way to get the "specially generated" blocks either NMS or not. The version change is not an issue so I can/will use NMS if you guys know an easier way to do this.
  2. Offline


    it's a while ago i've used chunks but i think a chunk object has #getTileEnities() so it will return all hoppers and dispenser and chest so you need to check if it's a chest. this is the best way to do it i think
    NathanWolf likes this.
  3. Offline


    If this works you are a life/TPS saver!

    For some reason this code isn't working...

    c is a chunk passed in.

    for(BlockState bs : c.getTileEntities()){
        if(bs instanceof Chest){
            System.out.println("Is Chest");
            main.IG.populateChest((Chest) bs);
    using org.bukkit.block.Chest;

    Solved, and fixed. Thank you for your help.

    The issue was that the generation of chests from mods happened after the event was called. So I simply added a 1 second delay to the TileEntities check.


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page