mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
MayHaveCustomBlocks property -> MightHaveCustomBlocks function
since really only trivial code should be in a getter, and MightHaveCustomBlocks can potentially be quite expensive
This commit is contained in:
parent
485be4a3af
commit
67d2ecba74
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
/// <summary> Relatively quick guess at whether this map might use custom blocks. </summary>
|
||||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user