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());