How to keep Chunk load?

What I want:

Keep all Tile Entities in a specific chunk processing/working even there is no player around them.

What did I try:

@Listener
public void onChunkUnload(UnloadChunkEvent event){
    Chunk chunk = ...;
    if (event.getTargetChunk() == chunk){
        Sponge.getScheduler()
                .createTaskBuilder()
                .execute(()->{
                    if (!chunk.isLoaded()){
                        chunk.loadChunk(true);
                    }
                })
                .delayTicks(10)
                .submit(Main.getINSTANCE());
    }
}

and

    Sponge.getScheduler().createTaskBuilder()
            .execute(()->{
                chunk.getTileEntities().forEach(tileEntity -> {
                    if (!tileEntity.isValid()){
                        tileEntity.setValid(true);
                    }
                });
            })
           .intervalTicks(1)
           .submit(Main.getINSTANCE());

I dont believe chunks use the same instance, meaning that == will always be false. Try using .equals().

Also from what i remember, you cannot load just one chunk to keep tile entities, etc from remaining active. You need to get the 8 chunks around that one chunk loaded to keep tile entities active in that one chunk

Edit:
Just found this. Turns out its 24chunks around that single chunk

https://www.spigotmc.org/threads/keepchunks.147987/page-4#post-3184282

Thanks! It work!

1 Like