From 2da20b9d7962ed530cfd42a80f6248b6972006d6 Mon Sep 17 00:00:00 2001 From: brausjonas <47791011+jonasbraus@users.noreply.github.com> Date: Mon, 16 May 2022 00:41:42 +0200 Subject: [PATCH 1/2] Dead Sync and Timescale Bug Fix --- Minecraft Client/Assets/Scripts/Game/Client.cs | 5 +++++ Minecraft Client/Assets/Scripts/Game/Player.cs | 5 ++++- Minecraft Client/Assets/Scripts/Game/World.cs | 11 ++++------- Minecraft Server/Assets/Game/Server.cs | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Minecraft Client/Assets/Scripts/Game/Client.cs b/Minecraft Client/Assets/Scripts/Game/Client.cs index 3b57362..be38782 100644 --- a/Minecraft Client/Assets/Scripts/Game/Client.cs +++ b/Minecraft Client/Assets/Scripts/Game/Client.cs @@ -253,6 +253,11 @@ public class Client //send Chunk with position in Chunk Send(new byte[] { 3, (byte)chunk.x, (byte)chunk.z, xInChunk, yInChunk, zInChunk, blockID }); } + + public void SendDeadMessage() + { + Send(new byte[]{10}); + } //default send method private void Send(byte[] data) diff --git a/Minecraft Client/Assets/Scripts/Game/Player.cs b/Minecraft Client/Assets/Scripts/Game/Player.cs index 6911c89..c6243ca 100644 --- a/Minecraft Client/Assets/Scripts/Game/Player.cs +++ b/Minecraft Client/Assets/Scripts/Game/Player.cs @@ -149,7 +149,10 @@ public class Player : MonoBehaviour if (transform.position.y < 0) { - world.ShowDeadScreen(); + if(Time.timeScale > 0) + { + world.ShowDeadScreen(); + } } if (Input.GetKeyDown(KeyCode.Escape)) diff --git a/Minecraft Client/Assets/Scripts/Game/World.cs b/Minecraft Client/Assets/Scripts/Game/World.cs index 662971d..cc6fdf8 100644 --- a/Minecraft Client/Assets/Scripts/Game/World.cs +++ b/Minecraft Client/Assets/Scripts/Game/World.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Threading; using UnityEngine; using UnityEngine.SceneManagement; @@ -154,7 +155,7 @@ public class World : MonoBehaviour //returns if a block is on the position public bool CheckBlock(Vector3 positionInWorld) { - if (positionInWorld.x < -1 || positionInWorld.z < -1 || + if (positionInWorld.x < 0 || positionInWorld.z < 0 || positionInWorld.x > worldSize * Data.chunkWidth || positionInWorld.z > worldSize * Data.chunkWidth) { @@ -255,12 +256,6 @@ public class World : MonoBehaviour client.Disconnect(); } - - public void BackToMenu() - { - SceneManager.LoadScene("Scenes/Login", LoadSceneMode.Single); - } - public Client GetClient() { return client; @@ -277,6 +272,7 @@ public class World : MonoBehaviour public void ShowDeadScreen() { + client.SendDeadMessage(); Cursor.visible = true; Cursor.lockState = CursorLockMode.None; deadScreen.SetActive(true); @@ -310,6 +306,7 @@ public class World : MonoBehaviour public void QuitButton() { + Time.timeScale = 1; client.Disconnect(); SceneManager.LoadScene("Login"); deadScreen.SetActive(false); diff --git a/Minecraft Server/Assets/Game/Server.cs b/Minecraft Server/Assets/Game/Server.cs index 90fbd8e..bb04d00 100644 --- a/Minecraft Server/Assets/Game/Server.cs +++ b/Minecraft Server/Assets/Game/Server.cs @@ -47,6 +47,7 @@ public class Server //[0] = 7: player position update //[0] = 8: player rotation update //[0] = 9: Save the World + //[0] = 10: Player died private void Receive() { @@ -249,6 +250,12 @@ public class Server { world.SaveWorld(); } + + //player died + if (data[0] == 10) + { + Console.WriteLine(playerNames[GetPlayerID(endPoint)] + " died!"); + } } catch (Exception e) { From ad2ad89fec972da8cbcff105dc932bdd3ec92632 Mon Sep 17 00:00:00 2001 From: brausjonas <47791011+jonasbraus@users.noreply.github.com> Date: Mon, 16 May 2022 00:45:25 +0200 Subject: [PATCH 2/2] World rendering Issue --- Minecraft Client/Assets/Scripts/Game/World.cs | 4 ++-- Minecraft Server/Assets/Game/Server.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Minecraft Client/Assets/Scripts/Game/World.cs b/Minecraft Client/Assets/Scripts/Game/World.cs index cc6fdf8..2bf0ccd 100644 --- a/Minecraft Client/Assets/Scripts/Game/World.cs +++ b/Minecraft Client/Assets/Scripts/Game/World.cs @@ -156,8 +156,8 @@ public class World : MonoBehaviour public bool CheckBlock(Vector3 positionInWorld) { if (positionInWorld.x < 0 || positionInWorld.z < 0 || - positionInWorld.x > worldSize * Data.chunkWidth || - positionInWorld.z > worldSize * Data.chunkWidth) + positionInWorld.x >= worldSize * Data.chunkWidth || + positionInWorld.z >= worldSize * Data.chunkWidth) { return false; } diff --git a/Minecraft Server/Assets/Game/Server.cs b/Minecraft Server/Assets/Game/Server.cs index bb04d00..91ff79d 100644 --- a/Minecraft Server/Assets/Game/Server.cs +++ b/Minecraft Server/Assets/Game/Server.cs @@ -254,7 +254,7 @@ public class Server //player died if (data[0] == 10) { - Console.WriteLine(playerNames[GetPlayerID(endPoint)] + " died!"); + Console.WriteLine(playerNames[GetPlayerID(endPoint)] + " died! \n"); } } catch (Exception e)