Auto load chunk when spawning entities

This commit is contained in:
themode 2021-03-21 14:26:34 +01:00
parent 9893bb72c8
commit 95eddf47de

View File

@ -880,9 +880,11 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
}
});
final Chunk chunk = getChunkAt(entityPosition);
Check.notNull(chunk, "You tried to spawn an entity in an unloaded chunk, " + entityPosition);
addEntityToChunk(entity, chunk);
// Load the chunk if not already (or throw an error if auto chunk load is disabled)
loadOptionalChunk(entityPosition, chunk -> {
Check.notNull(chunk, "You tried to spawn an entity in an unloaded chunk, " + entityPosition);
addEntityToChunk(entity, chunk);
});
});
}