mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-10-03 08:58:16 +02:00
Don't cancel chunks with missing light data (#2711)
This commit is contained in:
parent
0b541befbc
commit
b2e0fdeaf8
@ -41,6 +41,7 @@ import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18T
|
|||||||
import com.viaversion.viaversion.util.MathUtil;
|
import com.viaversion.viaversion.util.MathUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class WorldPackets {
|
public final class WorldPackets {
|
||||||
@ -162,18 +163,26 @@ public final class WorldPackets {
|
|||||||
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()),
|
MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()),
|
||||||
MathUtil.ceilLog2(tracker.biomesSent())), chunk);
|
MathUtil.ceilLog2(tracker.biomesSent())), chunk);
|
||||||
|
|
||||||
// Get and remove light stored, there's only full chunk packets //TODO Only get, not remove if we find out people re-send full chunk packets without re-sending light
|
|
||||||
final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
|
final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
|
||||||
|
// Mark chunk as loaded
|
||||||
|
boolean alreadyLoaded = !lightStorage.addLoadedChunk(chunk.getX(), chunk.getZ());
|
||||||
|
|
||||||
|
// Get and remove light stored, there's only full chunk packets //TODO Only get, not remove if we find out people re-send full chunk packets without re-sending light
|
||||||
|
// Append light data to chunk packet
|
||||||
final ChunkLightStorage.ChunkLight light = lightStorage.removeLight(chunk.getX(), chunk.getZ());
|
final ChunkLightStorage.ChunkLight light = lightStorage.removeLight(chunk.getX(), chunk.getZ());
|
||||||
if (light == null) {
|
if (light == null) {
|
||||||
Via.getPlatform().getLogger().warning("No light data found for chunk at " + chunk.getX() + ", " + chunk.getZ());
|
Via.getPlatform().getLogger().warning("No light data found for chunk at " + chunk.getX() + ", " + chunk.getZ() + ". Chunk was already loaded: " + alreadyLoaded);
|
||||||
wrapper.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lightStorage.addLoadedChunk(chunk.getX(), chunk.getZ());
|
BitSet emptyLightMask = new BitSet();
|
||||||
|
emptyLightMask.set(0, tracker.currentWorldSectionHeight() + 2);
|
||||||
// Append light data to chunk packet
|
wrapper.write(Type.BOOLEAN, false);
|
||||||
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
|
||||||
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
|
||||||
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
|
||||||
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
|
||||||
|
wrapper.write(Type.VAR_INT, 0);
|
||||||
|
wrapper.write(Type.VAR_INT, 0);
|
||||||
|
} else {
|
||||||
wrapper.write(Type.BOOLEAN, light.trustEdges());
|
wrapper.write(Type.BOOLEAN, light.trustEdges());
|
||||||
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.skyLightMask());
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.skyLightMask());
|
||||||
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.blockLightMask());
|
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.blockLightMask());
|
||||||
@ -187,6 +196,7 @@ public final class WorldPackets {
|
|||||||
for (final byte[] blockLight : light.blockLight()) {
|
for (final byte[] blockLight : light.blockLight()) {
|
||||||
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, blockLight);
|
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, blockLight);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,8 +38,8 @@ public final class ChunkLightStorage implements StorableObject {
|
|||||||
return lightPackets.remove(getChunkSectionIndex(x, z));
|
return lightPackets.remove(getChunkSectionIndex(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLoadedChunk(final int x, final int z) {
|
public boolean addLoadedChunk(final int x, final int z) {
|
||||||
loadedChunks.add(getChunkSectionIndex(x, z));
|
return loadedChunks.add(getChunkSectionIndex(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoaded(final int x, final int z) {
|
public boolean isLoaded(final int x, final int z) {
|
||||||
|
Loading…
Reference in New Issue
Block a user