public void UnloadAndRequestChunks() { if (Game.StructureRoot == null) { //World is not setup yet //Prevents NullReferenceException return; } foreach (Collections.KeyValuePair <System.Tuple <int, int>, Collections.List <Structure> > Chunk in Building.Chunks) { Vector3 ChunkPos = new Vector3(Chunk.Key.Item1, 0, Chunk.Key.Item2); if (ChunkPos.DistanceTo(new Vector3(Translation.x, 0, Translation.z)) <= Game.ChunkRenderDistance * (Building.PlatformSize * 9)) { if (GetTree().IsNetworkServer()) { foreach (Structure CurrentStructure in Chunk.Value) { CurrentStructure.Show(); } } } else { foreach (Structure CurrentStructure in Chunk.Value) { if (GetTree().IsNetworkServer()) { CurrentStructure.Hide(); } else { CurrentStructure.QueueFree(); } } } } if (!GetTree().IsNetworkServer()) { Building.Self.RequestChunks(GetTree().GetNetworkUniqueId(), Translation, Game.ChunkRenderDistance); } }
public static void UnloadAndRequestChunks() { if (!World.IsOpen) { //World is not setup yet //Prevents NullReferenceException return; } foreach (KeyValuePair <System.Tuple <int, int>, ChunkClass> Chunk in World.Chunks.ToArray()) { Vector3 ChunkPos = new Vector3(Chunk.Key.Item1, 0, Chunk.Key.Item2); if (ChunkPos.DistanceTo(new Vector3(Game.PossessedPlayer.Translation.x, 0, Game.PossessedPlayer.Translation.z)) <= Game.ChunkRenderDistance * (World.PlatformSize * 9)) { if (Self.GetTree().IsNetworkServer()) { foreach (Structure CurrentStructure in Chunk.Value.Structures) { CurrentStructure.Show(); } foreach (DroppedItem Item in Chunk.Value.Items) { Item.Show(); } } } else { List <Structure> StructuresBeingRemoved = new List <Structure>(); foreach (Structure CurrentStructure in Chunk.Value.Structures) { if (Self.GetTree().IsNetworkServer()) { CurrentStructure.Hide(); } else { StructuresBeingRemoved.Add(CurrentStructure); } } foreach (Structure CurrentStructure in StructuresBeingRemoved) { CurrentStructure.Remove(Force: true); } List <DroppedItem> ItemsBeingRemoved = new List <DroppedItem>(); foreach (DroppedItem Item in Chunk.Value.Items) { if (Self.GetTree().IsNetworkServer()) { Item.Hide(); } else { ItemsBeingRemoved.Add(Item); } } foreach (DroppedItem Item in ItemsBeingRemoved) { Item.Remove(); } } } if (!Self.GetTree().IsNetworkServer()) { World.Self.RequestChunks(Self.GetTree().GetNetworkUniqueId(), Game.PossessedPlayer.Translation, Game.ChunkRenderDistance); } }