Check if the destination chunk exists after leaving the source chunk

This fixes a crash if a player does a /refresh in the zeroeth chunk.
This commit is contained in:
dongresource 2021-05-02 19:51:59 +02:00
parent 1c3e1d83de
commit 2658ed5900
1 changed files with 3 additions and 2 deletions

View File

@ -161,12 +161,13 @@ static void emptyChunk(ChunkPos chunkPos) {
void Chunking::updateEntityChunk(const EntityRef& ref, ChunkPos from, ChunkPos to) {
Entity* ent = ref.getEntity();
// move to other chunk's player set
untrackEntity(from, ref); // this will delete the chunk if it's empty
// if the new chunk doesn't exist, make it first
if (!chunkExists(to))
newChunk(to);
// move to other chunk's player set
untrackEntity(from, ref); // this will delete the chunk if it's empty
trackEntity(to, ref);
// calculate viewable chunks from both points