diff --git a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs index 4ce4480b1..6f4fee035 100644 --- a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Blocks { p.ChangeBlock(x, y, z, Block.staircasestep, 0); return; } - p.SendBlockchange(x, y, z, Block.air); // send the air block back only to the user + p.SendBlockchange(x, y, z, Block.air, 0); // send the air block back only to the user p.ChangeBlock(x, (ushort)(y - 1), z, Block.staircasefull, 0); } @@ -62,7 +62,7 @@ namespace MCGalaxy.Blocks { p.ChangeBlock(x, y, z, Block.cobblestoneslab, 0); return; } - p.SendBlockchange(x, y, z, Block.air); // send the air block back only to the user + p.SendBlockchange(x, y, z, Block.air, 0); // send the air block back only to the user p.ChangeBlock(x, (ushort)(y - 1), z, Block.stone, 0); } diff --git a/MCGalaxy/Commands/Fun/WeaponCmd.cs b/MCGalaxy/Commands/Fun/WeaponCmd.cs index 2194a6dd9..6267e26ab 100644 --- a/MCGalaxy/Commands/Fun/WeaponCmd.cs +++ b/MCGalaxy/Commands/Fun/WeaponCmd.cs @@ -105,7 +105,7 @@ namespace MCGalaxy.Commands { foreach (Vec3U16 cP in toSend) { if (lastSent.Contains(cP)) continue; lastSent.Add(cP); - p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.glass); + p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.glass, 0); } toSend.Clear(); } diff --git a/MCGalaxy/Commands/building/CmdMessageBlock.cs b/MCGalaxy/Commands/building/CmdMessageBlock.cs index 31b4f53ca..6ab99d12a 100644 --- a/MCGalaxy/Commands/building/CmdMessageBlock.cs +++ b/MCGalaxy/Commands/building/CmdMessageBlock.cs @@ -173,7 +173,7 @@ namespace MCGalaxy.Commands.Building { static void ShowMessageBlocks(Player p, DataTable table) { foreach (DataRow row in table.Rows) { - p.SendBlockchange(U16(row["X"]), U16(row["Y"]), U16(row["Z"]), Block.green); + p.SendBlockchange(U16(row["X"]), U16(row["Y"]), U16(row["Z"]), Block.green, 0); } Player.Message(p, "Now showing &a" + table.Rows.Count + " %SMBs."); } diff --git a/MCGalaxy/Commands/building/CmdPortal.cs b/MCGalaxy/Commands/building/CmdPortal.cs index b407b73ac..a1e0ff95d 100644 --- a/MCGalaxy/Commands/building/CmdPortal.cs +++ b/MCGalaxy/Commands/building/CmdPortal.cs @@ -88,7 +88,7 @@ namespace MCGalaxy.Commands.Building { if (data.Multi && type == Block.red && data.Entries.Count > 0) { ExitChange(p, x, y, z, type, extType); return; } p.level.Blockchange(p, x, y, z, data.Block, data.ExtBlock); - p.SendBlockchange(x, y, z, Block.green); + p.SendBlockchange(x, y, z, Block.green, 0); PortalPos Port; Port.Map = p.level.name; @@ -162,8 +162,8 @@ namespace MCGalaxy.Commands.Building { static void ShowPortals(Player p, DataTable table) { foreach (DataRow row in table.Rows) { if (row["ExitMap"].ToString() == p.level.name) - p.SendBlockchange(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"]), Block.red); - p.SendBlockchange(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"]), Block.green); + p.SendBlockchange(U16(row["ExitX"]), U16(row["ExitY"]), U16(row["ExitZ"]), Block.red, 0); + p.SendBlockchange(U16(row["EntryX"]), U16(row["EntryY"]), U16(row["EntryZ"]), Block.green, 0); } Player.Message(p, "Now showing &a" + table.Rows.Count + " %Sportals."); diff --git a/MCGalaxy/Commands/other/CmdFly.cs b/MCGalaxy/Commands/other/CmdFly.cs index 0cfe4dd1d..ac3d84020 100644 --- a/MCGalaxy/Commands/other/CmdFly.cs +++ b/MCGalaxy/Commands/other/CmdFly.cs @@ -46,7 +46,7 @@ namespace MCGalaxy.Commands { DoFly(p, oldpos, last, next); foreach (Vec3U16 cP in last) - p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.air); + p.SendBlockchange(cP.X, cP.Y, cP.Z, Block.air, 0); Player.Message(p, "Stopped flying"); })); flyThread.Name = "MCG_Fly"; @@ -77,14 +77,14 @@ namespace MCGalaxy.Commands { foreach (Vec3U16 P in next) { if (last.Contains(P)) continue; last.Add(P); - p.SendBlockchange(P.X, P.Y, P.Z, Block.glass); + p.SendBlockchange(P.X, P.Y, P.Z, Block.glass, 0); } for (int i = 0; i < last.Count; i++) { Vec3U16 P = last[i]; if (next.Contains(P)) continue; - p.SendBlockchange(P.X, P.Y, P.Z, Block.air); + p.SendBlockchange(P.X, P.Y, P.Z, Block.air, 0); last.RemoveAt(i); i--; } next.Clear(); diff --git a/MCGalaxy/Levels/Level.Blocks.cs b/MCGalaxy/Levels/Level.Blocks.cs index a2d533a86..3455ddfbe 100644 --- a/MCGalaxy/Levels/Level.Blocks.cs +++ b/MCGalaxy/Levels/Level.Blocks.cs @@ -90,9 +90,10 @@ namespace MCGalaxy { return def == null ? Block.air : def.FallBack; } - public byte GetFallback(byte extType) { - BlockDefinition def = CustomBlockDefs[extType]; - return def == null ? Block.air : def.FallBack; + public byte RawFallback(byte raw) { + BlockDefinition def = CustomBlockDefs[raw]; + if (def != null) return def.FallBack; + return raw < Block.CpeCount ? raw : Block.air; } public void SetTile(int index, byte block) { diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index 6e824b217..50ca3b65e 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -366,29 +366,13 @@ namespace MCGalaxy { SendRaw(Opcode.RemoveEntity, id); } + [Obsolete("Prefer SendBlockChange(x, y, z, block, extBlock)")] public void SendBlockchange(ushort x, ushort y, ushort z, byte block) { - //if (x < 0 || y < 0 || z < 0) return; - if (x >= level.Width || y >= level.Height || z >= level.Length) return; - - byte[] buffer = new byte[8]; - buffer[0] = Opcode.SetBlock; - NetUtils.WriteU16(x, buffer, 1); - NetUtils.WriteU16(y, buffer, 3); - NetUtils.WriteU16(z, buffer, 5); - - if (block == Block.custom_block) { - block = hasBlockDefs ? level.GetExtTile(x, y, z) : level.GetFallbackExtTile(x, y, z); - } else { - block = Block.Convert(block); - } - - // TODO: custom blocks replacing core blocks - if (!hasCustomBlocks) block = Block.ConvertCPE(block); - buffer[7] = block; - Send(buffer); + byte extBlock = 0; + if (block == Block.custom_block) extBlock = level.GetExtTile(x, y, z); + SendBlockchange(x, y, z, block, extBlock); } - // Duplicated as this packet needs to have maximum optimisation. public void SendBlockchange(ushort x, ushort y, ushort z, byte block, byte extBlock) { //if (x < 0 || y < 0 || z < 0) return; if (x >= level.Width || y >= level.Height || z >= level.Length) return; @@ -400,12 +384,18 @@ namespace MCGalaxy { NetUtils.WriteU16(z, buffer, 5); if (block == Block.custom_block) { - block = hasBlockDefs ? extBlock : level.GetFallback(extBlock); + block = hasBlockDefs ? extBlock : level.RawFallback(extBlock); } else { block = Block.Convert(block); } - - if (!hasCustomBlocks) block = Block.ConvertCPE(block); + if (!hasCustomBlocks) block = Block.ConvertCPE(block); // client doesn't support CPE + + // Custom block replaced a core block + if (!hasBlockDefs && block < Block.CpeCount) { + BlockDefinition def = level.CustomBlockDefs[block]; + if (def != null) block = def.FallBack; + } + buffer[7] = block; Send(buffer); } @@ -433,10 +423,9 @@ namespace MCGalaxy { public void SendChangeModel(byte id, string model) { // Fallback block models for clients that don't support block definitions byte block; - bool fallback = byte.TryParse(model, out block) && block >= Block.CpeCount; - block = level == null ? block : level.GetFallback(block); - if (fallback && !hasBlockDefs && block != Block.air) - model = block.ToString(); + if (byte.TryParse(model, out block) && !hasBlockDefs) { + model = level.RawFallback(block).ToString(); + } Send(Packet.ChangeModel(id, model, hasCP437)); } diff --git a/MCGalaxy/Player/Player.CPE.cs b/MCGalaxy/Player/Player.CPE.cs index d217c6935..1ba578d44 100644 --- a/MCGalaxy/Player/Player.CPE.cs +++ b/MCGalaxy/Player/Player.CPE.cs @@ -149,10 +149,8 @@ namespace MCGalaxy { string lastUrl = ""; public void SendCurrentMapAppearance() { byte side = (byte)level.EdgeBlock, edge = (byte)level.HorizonBlock; - if (side >= Block.CpeCount && !hasBlockDefs) - side = level.GetFallback(side); - if (edge >= Block.CpeCount && !hasBlockDefs) - edge = level.GetFallback(edge); + if (!hasBlockDefs) side = level.RawFallback(side); + if (!hasBlockDefs) edge = level.RawFallback(edge); if (HasCpeExt(CpeExt.EnvMapAspect)) { string url = GetTextureUrl(); diff --git a/MCGalaxy/util/IO/BufferedBlockSender.cs b/MCGalaxy/util/IO/BufferedBlockSender.cs index db83eeef6..fdf658de8 100644 --- a/MCGalaxy/util/IO/BufferedBlockSender.cs +++ b/MCGalaxy/util/IO/BufferedBlockSender.cs @@ -144,7 +144,7 @@ namespace MCGalaxy { data[j++] = (byte)(x >> 8); data[j++] = (byte)x; data[j++] = (byte)(y >> 8); data[j++] = (byte)y; data[j++] = (byte)(z >> 8); data[j++] = (byte)z; - data[j++] = types[i] < Block.CpeCount ? types[i] : level.GetFallback(types[i]); + data[j++] = level.RawFallback(types[i]); } return data; } @@ -161,8 +161,7 @@ namespace MCGalaxy { data[j++] = (byte)(x >> 8); data[j++] = (byte)x; data[j++] = (byte)(y >> 8); data[j++] = (byte)y; data[j++] = (byte)(z >> 8); data[j++] = (byte)z; - data[j++] = types[i] < Block.CpeCount ? Block.ConvertCPE(types[i]) - : Block.ConvertCPE(level.GetFallback(types[i])); + data[j++] = types[i] = Block.ConvertCPE(level.RawFallback(types[i])); } return data; }