From f23fc16f0d964bec2f5627e90a82583dd5a25b1b Mon Sep 17 00:00:00 2001 From: brausjonas <47791011+jonasbraus@users.noreply.github.com> Date: Tue, 17 May 2022 16:51:35 +0200 Subject: [PATCH] save bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ascii 10 ist ein line feed. Einen line feed aus einer datei dann zurück umzuwandeln ist nicht möglich. Daher jeder ascii wert +32 am nur zeichen zu speichern. --- Minecraft Client/Assets/Scripts/Game/Client.cs | 2 +- Minecraft Client/Assets/Scripts/Game/World.cs | 18 ++++++++++++++++-- Minecraft Server/Assets/Game/Server.cs | 2 +- Minecraft Server/Assets/Game/World.cs | 6 +++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Minecraft Client/Assets/Scripts/Game/Client.cs b/Minecraft Client/Assets/Scripts/Game/Client.cs index be38782..67740ab 100644 --- a/Minecraft Client/Assets/Scripts/Game/Client.cs +++ b/Minecraft Client/Assets/Scripts/Game/Client.cs @@ -101,7 +101,7 @@ public class Client { for (int z = 0; z < Data.chunkWidth; z++) { - blocks[x, y, z] = data[i]; + blocks[x, y, z] = (byte)(data[i] - 32); i++; } } diff --git a/Minecraft Client/Assets/Scripts/Game/World.cs b/Minecraft Client/Assets/Scripts/Game/World.cs index 974de38..176b5b3 100644 --- a/Minecraft Client/Assets/Scripts/Game/World.cs +++ b/Minecraft Client/Assets/Scripts/Game/World.cs @@ -30,6 +30,7 @@ public class World : MonoBehaviour //chunks private Chunk[,] chunks; private Queue chunksToUpdate = new Queue(); + private Queue chunksToUpdate1 = new Queue(); private List lastActiveChunks = new List(); //blocks @@ -43,6 +44,12 @@ public class World : MonoBehaviour private void Start() { //get default information + + if (PlayerPrefs.HasKey("viewDistance")) + { + Data.viewDistance = PlayerPrefs.GetInt("viewDistance"); + } + name = PlayerPrefs.GetString("userName"); ip = PlayerPrefs.GetString("serverIP"); port = int.Parse(PlayerPrefs.GetString("port")); @@ -74,6 +81,13 @@ public class World : MonoBehaviour ChunkCoord chunk = chunksToUpdate.Dequeue(); chunks[chunk.x, chunk.z].Update(); } + + //update 1 chunk in list + if (chunksToUpdate1.Count > 0) + { + ChunkCoord chunk = chunksToUpdate1.Dequeue(); + chunks[chunk.x, chunk.z].Update(); + } //create 1 player in list if (playersToCreate.Count > 0) @@ -125,7 +139,7 @@ public class World : MonoBehaviour { List checkList = new List(); - chunksToUpdate.Clear(); + chunksToUpdate1.Clear(); for (int x = playerChunk.x - Data.viewDistance; x < playerChunk.x + Data.viewDistance; x++) { @@ -138,7 +152,7 @@ public class World : MonoBehaviour } if(!chunks[x, z].active) { - chunksToUpdate.Enqueue(new ChunkCoord(x, z)); + chunksToUpdate1.Enqueue(new ChunkCoord(x, z)); } checkList.Add(chunks[x, z]); } diff --git a/Minecraft Server/Assets/Game/Server.cs b/Minecraft Server/Assets/Game/Server.cs index 91ff79d..e21f8e1 100644 --- a/Minecraft Server/Assets/Game/Server.cs +++ b/Minecraft Server/Assets/Game/Server.cs @@ -313,7 +313,7 @@ public class Server { for (int z = 0; z < Data.chunkWidth; z++) { - send[i] = world.chunks[xChunk, zChunk].blocks[x, y, z]; + send[i] = (byte)(world.chunks[xChunk, zChunk].blocks[x, y, z] + 32); i++; } } diff --git a/Minecraft Server/Assets/Game/World.cs b/Minecraft Server/Assets/Game/World.cs index 05e500c..85bf50f 100644 --- a/Minecraft Server/Assets/Game/World.cs +++ b/Minecraft Server/Assets/Game/World.cs @@ -57,7 +57,7 @@ public class World : MonoBehaviour { for (int z = 0; z < Data.chunkWidth; z++) { - chunks[xChunk, zChunk].blocks[x, y, z] = save[i]; + chunks[xChunk, zChunk].blocks[x, y, z] = (byte)(save[i] - 32); i++; } } @@ -289,7 +289,7 @@ public class World : MonoBehaviour { for (int z = 0; z < Data.chunkWidth; z++) { - save[i] = chunks[xChunk, zChunk].blocks[x, y, z]; + save[i] = (byte)(chunks[xChunk, zChunk].blocks[x, y, z] + 32); i++; } } @@ -300,6 +300,6 @@ public class World : MonoBehaviour } } writer.Close(); - Console.WriteLine("world saved! (world.save) \n"); + Console.WriteLine("world saved! (save.world) \n"); } }