diff --git a/Drawing/DrawOps/UndoDrawOp.cs b/Drawing/DrawOps/UndoDrawOp.cs index d315ab464..2669c9de2 100644 --- a/Drawing/DrawOps/UndoDrawOp.cs +++ b/Drawing/DrawOps/UndoDrawOp.cs @@ -47,57 +47,42 @@ namespace MCGalaxy.Drawing.Ops { UndoCache cache = who.UndoBuffer; UndoCacheNode node = cache.Tail; if (node == null) return; + Vec3U16 min = Min, max = Max; bool undoArea = min.X != ushort.MaxValue; + Player.UndoPos Pos = default(Player.UndoPos); + int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; while (node != null) { Level lvl = LevelInfo.FindExact(node.MapName); if (lvl == null || (p.level != null && !p.level.name.CaselessEq(lvl.name))) { node = node.Prev; continue; } + Pos.mapName = lvl.name; saveLvl = lvl; List items = node.Items; BufferedBlockSender buffer = new BufferedBlockSender(lvl); if (!undoArea) { - min = new Vec3U16(0, 0, 0); - max = new Vec3U16((ushort)(lvl.Width - 1), (ushort)(lvl.Height - 1), (ushort)(lvl.Length - 1)); + min = new Vec3U16(0, 0, 0); + max = new Vec3U16((ushort)(lvl.Width - 1), (ushort)(lvl.Height - 1), (ushort)(lvl.Length - 1)); } for (int i = items.Count - 1; i >= 0; i--) { UndoCacheItem item = items[i]; - ushort x, y, z; - node.Unpack(item.Index, out x, out y, out z); - if (x < min.X || y < min.Y || z < min.Z || - x > max.X || y > max.Y || z > max.Z) continue; + node.Unpack(item.Index, out Pos.x, out Pos.y, out Pos.z); + if (Pos.x < min.X || Pos.y < min.Y || Pos.z < min.Z || + Pos.x > max.X || Pos.y > max.Y || Pos.z > max.Z) continue; DateTime time = node.BaseTime.AddTicks(item.TimeDelta * TimeSpan.TicksPerSecond); if (time > End) continue; if (time < Start) { buffer.CheckIfSend(true); return; } - byte b = lvl.GetTile(x, y, z); byte newTile = 0, newExtTile = 0; item.GetNewExtBlock(out newTile, out newExtTile); - if (b == newTile || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava) { - Player.UndoPos uP = default(Player.UndoPos); - byte extType = 0; - if (b == Block.custom_block) extType = lvl.GetExtTile(x, y, z); - byte tile = 0, extTile = 0; - item.GetExtBlock(out tile, out extTile); - - if (lvl.DoBlockchange(p, x, y, z, tile, extTile)) { - buffer.Add(lvl.PosToInt(x, y, z), tile, extTile); - buffer.CheckIfSend(false); - } - - uP.newtype = tile; uP.newExtType = extTile; - uP.type = b; uP.extType = extType; - uP.x = x; uP.y = y; uP.z = z; - uP.mapName = node.MapName; - time = node.BaseTime.AddTicks(item.TimeDelta * TimeSpan.TicksPerSecond); - uP.timeDelta = (int)time.Subtract(Server.StartTime).TotalSeconds; - if (p != null) p.RedoBuffer.Add(lvl, uP); - } + byte tile = 0, extTile = 0; + item.GetExtBlock(out tile, out extTile); + UndoFile.UndoBlock(p, lvl, Pos, timeDelta, buffer, tile, extTile, newTile, newExtTile); } buffer.CheckIfSend(true); node = node.Prev; diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index be2cd4c34..e12330643 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -728,7 +728,7 @@ namespace MCGalaxy { } byte MakePitch() { - if (Server.flipHead || (flipHead && infected)) + if (Server.flipHead || flipHead) if (rot[1] > 64 && rot[1] < 192) return rot[1]; else diff --git a/Player/Player.cs b/Player/Player.cs index 51a114e71..e6799266d 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -194,7 +194,7 @@ namespace MCGalaxy { public int lastYblock = 0, lastXblock = 0, lastZblock = 0; public bool infected = false; public bool aka = false; - public bool flipHead = true; + public bool flipHead = false; public int playersInfected = 0; internal string lastSpawnColor = ""; internal bool ratedMap = false; @@ -501,6 +501,8 @@ namespace MCGalaxy { other.SendSpawn(p.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty); else other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty); + if (other.HasCpeExt(CpeExt.ChangeModel)) + other.SendChangeModel(p.id, "zombie"); } else if (!p.referee) { other.SendSpawn(p.id, p.color + p.name + possession, x, y, z, rotx, roty); } diff --git a/Player/Undo/UndoFile.cs b/Player/Undo/UndoFile.cs index 11a771fc2..3057da2eb 100644 --- a/Player/Undo/UndoFile.cs +++ b/Player/Undo/UndoFile.cs @@ -114,6 +114,23 @@ namespace MCGalaxy.Util { return aNum.CompareTo(bNum); } + protected internal static void UndoBlock(Player p, Level lvl, Player.UndoPos Pos, + int timeDelta, BufferedBlockSender buffer, + byte oldType, byte oldExtType, byte newType, byte newExtType) { + Pos.type = lvl.GetTile(Pos.x, Pos.y, Pos.z); + if (Pos.type == newType || Block.Convert(Pos.type) == Block.water + || Block.Convert(Pos.type) == Block.lava || Pos.type == Block.grass) { + + Pos.newtype = oldType; Pos.newExtType = oldExtType; + Pos.extType = newExtType; Pos.timeDelta = timeDelta; + if (lvl.DoBlockchange(p, Pos.x, Pos.y, Pos.z, Pos.newtype, Pos.newExtType)) { + buffer.Add(lvl.PosToInt(Pos.x, Pos.y, Pos.z), Pos.newtype, Pos.newExtType); + buffer.CheckIfSend(false); + } + if (p != null) p.RedoBuffer.Add(lvl, Pos); + } + } + public static void CreateDefaultDirectories() { if (!Directory.Exists(undoDir)) Directory.CreateDirectory(undoDir); diff --git a/Player/Undo/UndoFileBin.cs b/Player/Undo/UndoFileBin.cs index 6f13e39a9..c95c60462 100644 --- a/Player/Undo/UndoFileBin.cs +++ b/Player/Undo/UndoFileBin.cs @@ -121,7 +121,7 @@ namespace MCGalaxy.Util { ref byte[] temp, DateTime start) { List list = new List(); int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; - Player.UndoPos Pos; + Player.UndoPos Pos = default(Player.UndoPos); Vec3U16 min = marks[0], max = marks[1]; bool undoArea = min.X != ushort.MaxValue; @@ -155,21 +155,9 @@ namespace MCGalaxy.Util { if (Pos.x < min.X || Pos.y < min.Y || Pos.z < min.Z || Pos.x > max.X || Pos.y > max.Y || Pos.z > max.Z) continue; - Pos.type = lvl.GetTile(Pos.x, Pos.y, Pos.z); byte oldType = temp[offset + 8], oldExtType = temp[offset + 9]; byte newType = temp[offset + 10], newExtType = temp[offset + 11]; - - if (Pos.type == newType || Block.Convert(Pos.type) == Block.water - || Block.Convert(Pos.type) == Block.lava || Pos.type == Block.grass) { - - Pos.newtype = oldType; Pos.newExtType = oldExtType; - Pos.extType = newExtType; Pos.timeDelta = timeDelta; - if (lvl.DoBlockchange(p, Pos.x, Pos.y, Pos.z, Pos.newtype, Pos.newExtType)) { - buffer.Add(lvl.PosToInt(Pos.x, Pos.y, Pos.z), Pos.newtype, Pos.newExtType); - buffer.CheckIfSend(false); - } - if (p != null) p.RedoBuffer.Add(lvl, Pos); - } + UndoBlock(p, lvl, Pos, timeDelta, buffer, oldType, oldExtType, newType, newExtType); } buffer.CheckIfSend(true); } diff --git a/Player/Undo/UndoFileText.cs b/Player/Undo/UndoFileText.cs index ad7fcad9c..790165477 100644 --- a/Player/Undo/UndoFileText.cs +++ b/Player/Undo/UndoFileText.cs @@ -70,12 +70,13 @@ namespace MCGalaxy.Util { protected override bool UndoEntry(Player p, string path, Vec3U16[] marks, ref byte[] temp, DateTime start) { - Player.UndoPos Pos; + Player.UndoPos Pos = default(Player.UndoPos); int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; - Pos.extType = 0; Pos.newExtType = 0; string[] lines = File.ReadAllText(path).Split(' '); Vec3U16 min = marks[0], max = marks[1]; bool undoArea = min.X != ushort.MaxValue; + BufferedBlockSender buffer = new BufferedBlockSender(null); + string last = null; // because we have space to end of each entry, need to subtract one otherwise we'll start at a "". for (int i = (lines.Length - 1) / 7; i >= 0; i--) { @@ -89,27 +90,26 @@ namespace MCGalaxy.Util { min = new Vec3U16(0, 0, 0); max = new Vec3U16((ushort)(lvl.Width - 1), (ushort)(lvl.Height - 1), (ushort)(lvl.Length - 1)); } - + if (last == null || last != lvl.name) { + buffer.CheckIfSend(true); + last = lvl.name; + } + buffer.level = lvl; Pos.mapName = lvl.name; + Pos.x = Convert.ToUInt16(lines[(i * 7) - 6]); Pos.y = Convert.ToUInt16(lines[(i * 7) - 5]); Pos.z = Convert.ToUInt16(lines[(i * 7) - 4]); if (Pos.x < min.X || Pos.y < min.Y || Pos.z < min.Z || Pos.x > max.X || Pos.y > max.Y || Pos.z > max.Z) continue; - Pos.type = lvl.GetTile(Pos.x, Pos.y, Pos.z); - - if (Pos.type == Convert.ToByte(lines[(i * 7) - 1]) || Block.Convert(Pos.type) == Block.water || - Block.Convert(Pos.type) == Block.lava || Pos.type == Block.grass) { - - Pos.newtype = Convert.ToByte(lines[(i * 7) - 2]); - Pos.timeDelta = timeDelta; - - lvl.Blockchange(p, Pos.x, Pos.y, Pos.z, Pos.newtype, 0); - if (p != null) p.RedoBuffer.Add(lvl, Pos); - } + + byte newType = Convert.ToByte(lines[(i * 7) - 1]); + byte oldType = Convert.ToByte(lines[(i * 7) - 2]); + UndoBlock(p, lvl, Pos, timeDelta, buffer, oldType, 0, newType, 0); } catch { } } + buffer.CheckIfSend(true); return true; }