diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index f238f2d70..f04a0a618 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -341,7 +341,7 @@ namespace MCGalaxy { if (pl.hasBlockDefs) continue; // if custom block is replacing core block, need to always reload for fallback - if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue; + if (block >= Block.CpeCount && !pl.level.MightHaveCustomBlocks()) continue; PlayerActions.ReloadMap(pl); } } diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index 05e06ac25..eefcd93b0 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -33,16 +33,15 @@ namespace MCGalaxy { public byte[][] CustomBlocks; public int ChunksX, ChunksY, ChunksZ; - public bool MayHaveCustomBlocks { - get { - byte[][] customBlocks = CustomBlocks; - if (customBlocks == null) return false; + /// Relatively quick guess at whether this map might use custom blocks. + public bool MightHaveCustomBlocks() { + byte[][] customBlocks = CustomBlocks; + if (customBlocks == null) return false; - for (int i = 0; i < customBlocks.Length; i++) { - if (customBlocks[i] != null) return true; - } - return false; + for (int i = 0; i < customBlocks.Length; i++) { + if (customBlocks[i] != null) return true; } + return false; } @@ -390,7 +389,7 @@ namespace MCGalaxy { AddCheck(b, false, data); } - // Save bandwidth sending identical looking blocks, like air/op_air changes. + // Save bandwidth not sending identical looking blocks, like air/op_air changes. return !Block.VisuallyEquals(old, block); } catch { return false; diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index 70af3b9ec..a09d64b43 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -251,10 +251,10 @@ namespace MCGalaxy { using (LevelChunkStream dst = new LevelChunkStream(this)) using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst)) { - if (!level.MayHaveCustomBlocks) { - LevelChunkStream.CompressMapSimple(this, stream, dst); - } else { + if (level.MightHaveCustomBlocks()) { LevelChunkStream.CompressMap(this, stream, dst); + } else { + LevelChunkStream.CompressMapSimple(this, stream, dst); } } diff --git a/MCGalaxy/Network/Utils/LevelChunkStream.cs b/MCGalaxy/Network/Utils/LevelChunkStream.cs index 8ac94eec5..f4198ca26 100644 --- a/MCGalaxy/Network/Utils/LevelChunkStream.cs +++ b/MCGalaxy/Network/Utils/LevelChunkStream.cs @@ -84,14 +84,16 @@ namespace MCGalaxy.Network { } - internal static Stream CompressMapHeader(Player player, int volume, LevelChunkStream dst) { + public static Stream CompressMapHeader(Player p, int volume, LevelChunkStream dst) { Stream stream = null; - if (player.Supports(CpeExt.FastMap)) { + if (p.Supports(CpeExt.FastMap)) { stream = new DeflateStream(dst, CompressionMode.Compress, true); } else { stream = new GZipStream(dst, CompressionMode.Compress, true); - byte[] buffer = new byte[4]; NetUtils.WriteI32(volume, buffer, 0); - stream.Write(buffer, 0, sizeof(int)); + byte[] buffer = new byte[4]; + + NetUtils.WriteI32(volume, buffer, 0); + stream.Write(buffer, 0, 4); } return stream; } @@ -117,7 +119,7 @@ namespace MCGalaxy.Network { bIndex++; if (bIndex == bufferSize) { - // '0' to indicate classic blocks + // '0' to indicate this chunk has lower 8 bits of block ids dst.chunkValue = p.hasExtBlocks ? (byte)0 : (byte)(i * progScale); stream.Write(buffer, 0, bufferSize); bIndex = 0; } @@ -132,7 +134,7 @@ namespace MCGalaxy.Network { // Store on stack instead of performing function call for every block in map byte* conv = stackalloc byte[Block.ExtendedCount]; - byte* convExt = conv + Block.Count; + byte* convExt = conv + Block.Count; #if TEN_BIT_BLOCKS byte* convExt2 = conv + Block.Count * 2; byte* convExt3 = conv + Block.Count * 3;