Fix manual place and map send for blocks > 255

This commit is contained in:
UnknownShadow200 2018-03-09 20:53:20 +11:00
parent 9f7913081e
commit eb9c19ca93
6 changed files with 70 additions and 34 deletions

View File

@ -242,20 +242,18 @@ namespace MCGalaxy {
internal static void SendLevelCustomBlocks(Player pl) {
BlockDefinition[] defs = pl.level.CustomBlockDefs;
BlockID_ maxRaw = pl.MaxRawBlock;
for (int i = 0; i < defs.Length; i++) {
BlockDefinition def = defs[i];
if (def == null || def.BlockID > maxRaw) continue;
if (def == null || def.BlockID > pl.MaxRawBlock) continue;
pl.Send(def.MakeDefinePacket(pl));
}
}
internal static void SendLevelInventoryOrder(Player pl) {
BlockDefinition[] defs = pl.level.CustomBlockDefs;
BlockID_ maxRaw = pl.MaxRawBlock;
for (int b = 0; b < defs.Length; b++) {
BlockDefinition def = defs[b];
if (def == null || def.BlockID > maxRaw) continue;
if (def == null || def.BlockID > pl.MaxRawBlock) continue;
if (def.InventoryOrder >= 0) {
pl.Send(Packet.SetInventoryOrder(def, pl.hasExtBlocks));
}

View File

@ -264,22 +264,23 @@ namespace MCGalaxy {
NetUtils.WriteU16(y, buffer, 3);
NetUtils.WriteU16(z, buffer, 5);
BlockID raw;
if (block >= Block.Extended) {
block = hasBlockDefs ? Block.ToRaw(block) : level.RawFallback(block);
raw = Block.ToRaw(block);
} else {
block = Block.Convert(block);
// Invalid block physics won't have converted form
if (block >= Block.CpeCount) block = Block.Orange;
}
raw = Block.Convert(block);
if (raw >= Block.CpeCount) raw = Block.Orange;
}
if (raw > MaxRawBlock) raw = level.RawFallback(block);
// Custom block replaced a core block
if (!hasBlockDefs && block < Block.CpeCount) {
BlockDefinition def = level.CustomBlockDefs[block];
if (def != null) block = def.FallBack;
}
if (!hasBlockDefs && raw < Block.CpeCount) {
BlockDefinition def = level.CustomBlockDefs[raw];
if (def != null) raw = def.FallBack;
}
if (!hasCustomBlocks) raw = Block.ConvertCPE((BlockRaw)raw);
if (!hasCustomBlocks) block = Block.ConvertCPE((BlockRaw)block); // doesn't support CPE blocks
NetUtils.WriteBlock(block, buffer, 7, hasExtBlocks);
NetUtils.WriteBlock(raw, buffer, 7, hasExtBlocks);
Socket.SendLowPriority(buffer);
}

View File

@ -38,8 +38,8 @@ namespace MCGalaxy.Network {
internal int index, position, length;
Player p;
byte[] data = new byte[chunkSize + 4];
const int chunkSize = 1024;
byte[] data = new byte[chunkSize + 4];
const int chunkSize = 1024;
public LevelChunkStream(Player p) { this.p = p; }
public override void Close() {
@ -96,14 +96,11 @@ namespace MCGalaxy.Network {
conv[b] = (byte)Block.Convert((byte)b);
if (conv[b] > Block.CpeCount) conv[b] = Block.Orange;
}
// Convert custom blocks (that overwrote core blocks) to their fallbacks
#if !TEN_BIT_BLOCKS
if (!p.hasBlockDefs) {
// Convert custom blocks (that overwrote core blocks) to their fallbacks
for (int b = 0; b < Block.CpeCount; b++) {
BlockDefinition def = p.level.CustomBlockDefs[b];
if (def != null) conv[b] = def.FallBack;
}
#endif
for (int b = 0; b < Block.Count; b++) {
BlockID block = Block.FromRaw((byte)b);
BlockDefinition def = p.level.CustomBlockDefs[block];
@ -114,6 +111,16 @@ namespace MCGalaxy.Network {
convExt[b] = def.FallBack;
}
}
#if !TEN_BIT_BLOCKS
}
#endif
// Convert custom blocks (that overwrote core blocks) to their fallbacks
if (!p.hasBlockDefs) {
for (int b = 0; b < Block.CpeCount; b++) {
BlockDefinition def = p.level.CustomBlockDefs[b];
if (def != null) conv[b] = def.FallBack;
}
}
// Convert CPE blocks to their fallbacks
@ -157,9 +164,39 @@ namespace MCGalaxy.Network {
gs.Write(buffer, 0, bufferSize); bIndex = 0;
}
}
} else
#endif
} else if (p.hasBlockDefs) {
for (int i = 0; i < blocks.Length; ++i) {
byte block = blocks[i];
if (block == Block.custom_block) {
buffer[bIndex] = lvl.GetExtTile(i);
} else if (block == Block.custom_block_2 || block == Block.custom_block_3) {
buffer[bIndex] = convExt[lvl.GetExtTile(i)];
} else {
buffer[bIndex] = conv[block];
}
bIndex++;
if (bIndex == bufferSize) {
dst.position = i;
gs.Write(buffer, 0, bufferSize); bIndex = 0;
}
}
} else {
for (int i = 0; i < blocks.Length; ++i) {
byte block = blocks[i];
if (block == Block.custom_block || block == Block.custom_block_2 || block == Block.custom_block_3) {
block = convExt[lvl.GetExtTile(i)];
}
buffer[bIndex] = conv[block];
bIndex++;
if (bIndex == bufferSize) {
dst.position = i;
gs.Write(buffer, 0, bufferSize); bIndex = 0;
}
}
}
#else
if (p.hasBlockDefs) {
for (int i = 0; i < blocks.Length; ++i) {
byte block = blocks[i];
@ -190,6 +227,9 @@ namespace MCGalaxy.Network {
}
}
}
#endif
if (bIndex > 0) gs.Write(buffer, 0, bIndex);
}
}

View File

@ -73,6 +73,7 @@ namespace MCGalaxy {
if (ext.ExtName == CpeExt.CustomBlocks) {
if (version == 1) Send(Packet.CustomBlockSupportLevel(1));
hasCustomBlocks = true;
if (MaxRawBlock < Block.CpeMaxBlock) MaxRawBlock = Block.CpeMaxBlock;
} else if (ext.ExtName == CpeExt.ChangeModel) {
hasChangeModel = true;
} else if (ext.ExtName == CpeExt.FullCP437) {
@ -81,6 +82,7 @@ namespace MCGalaxy {
hasExtList = true;
} else if (ext.ExtName == CpeExt.BlockDefinitions) {
hasBlockDefs = true;
if (MaxRawBlock < 255) MaxRawBlock = 255;
} else if (ext.ExtName == CpeExt.TextColors) {
hasTextColors = true;
for (int i = 0; i < Colors.List.Length; i++) {
@ -97,6 +99,7 @@ namespace MCGalaxy {
#if TEN_BIT_BLOCKS
else if (ext.ExtName == CpeExt.ExtBlocks) {
hasExtBlocks = true;
if (MaxRawBlock < 767) MaxRawBlock = 767;
}
#endif
}

View File

@ -55,6 +55,7 @@ namespace MCGalaxy {
internal bool nonPlayerClient = false;
public INetworkSocket Socket;
public PingList Ping = new PingList();
public BlockID MaxRawBlock = Block.OriginalMaxBlock;
public DateTime LastAction, AFKCooldown;
public bool IsAfk, AutoAfk;

View File

@ -58,13 +58,6 @@ namespace MCGalaxy {
}
}
public BlockID MaxRawBlock { get {
if (hasExtBlocks) return 767;
if (hasBlockDefs) return 255;
return hasCustomBlocks ? Block.CpeMaxBlock : Block.OriginalMaxBlock;
}
}
internal void Connect(Socket s) {
try {
Socket = new TcpSocket(this, s);