Skip to content

Commit

Permalink
fix: Use correct chunk load radius when changing render distances
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Jun 27, 2020
1 parent f3916a1 commit 43f77f9
Showing 1 changed file with 5 additions and 35 deletions.
@@ -1,9 +1,7 @@
package me.jellysquid.mods.sodium.client.world;

import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.longs.LongList;
import net.minecraft.client.world.ClientChunkManager;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -96,11 +94,6 @@ public WorldChunk getChunk(int x, int z, ChunkStatus status, boolean create) {

@Override
public WorldChunk loadChunkFromPacket(int x, int z, BiomeArray biomes, PacketByteBuf buf, CompoundTag tag, int flag) {
// Do not try to load chunks outside the load distance
if (!this.isWithinLoadDistance(x, z)) {
return null;
}

long key = toChunkKey(x, z);

WorldChunk chunk = this.chunks.get(key);
Expand Down Expand Up @@ -130,20 +123,8 @@ public void setChunkMapCenter(int x, int z) {
}

@Override
public void updateLoadDistance(int dist) {
int radius = getChunkMapRadius(dist);

if (this.radius == radius) {
return;
}

this.radius = dist;

this.checkChunks();
}

private void checkChunks() {
LongList queue = new LongArrayList();
public void updateLoadDistance(int loadDistance) {
this.radius = getChunkMapRadius(loadDistance);

LongIterator it = this.chunks.keySet().iterator();

Expand All @@ -153,22 +134,11 @@ private void checkChunks() {
int x = ChunkPos.getPackedX(pos);
int z = ChunkPos.getPackedZ(pos);

if (!this.isWithinLoadDistance(x, z)) {
queue.add(pos);
// Remove any chunks which are outside the load radius
if (Math.abs(x - this.centerX) > this.radius || Math.abs(z - this.centerZ) > this.radius) {
it.remove();
}
}

if (!queue.isEmpty()) {
it = queue.iterator();

while (it.hasNext()) {
this.unload(it.nextLong());
}
}
}

private boolean isWithinLoadDistance(int x, int z) {
return Math.abs(x - this.centerX) <= this.radius && Math.abs(z - this.centerZ) <= this.radius;
}

@Override
Expand Down

0 comments on commit 43f77f9

Please sign in to comment.