diff --git a/Obsidian.API/_Interfaces/IServerConfiguration.cs b/Obsidian.API/_Interfaces/IServerConfiguration.cs index f2f6b5078..1595c041e 100644 --- a/Obsidian.API/_Interfaces/IServerConfiguration.cs +++ b/Obsidian.API/_Interfaces/IServerConfiguration.cs @@ -109,6 +109,14 @@ public interface IServerConfiguration /// public RconConfig? Rcon { get; set; } + /// + /// The view distance of the server. + /// + /// + /// Players with higher view distance will use the server's view distance. + /// + public byte ViewDistance { get; set; } + public List WhitelistedIPs { get; set; } public List Whitelisted { get; set; } } diff --git a/Obsidian/Net/Packets/ClientInformationPacket.cs b/Obsidian/Net/Packets/ClientInformationPacket.cs index 99df5b3a3..319dc1217 100644 --- a/Obsidian/Net/Packets/ClientInformationPacket.cs +++ b/Obsidian/Net/Packets/ClientInformationPacket.cs @@ -36,7 +36,7 @@ public async ValueTask HandleAsync(Server server, Player player) player.ClientInformation = new() { Locale = this.Locale, - ViewDistance = this.ViewDistance, + ViewDistance = sbyte.Min(ViewDistance, (sbyte) server.Configuration.ViewDistance), ChatMode = this.ChatMode, ChatColors = this.ChatColors, DisplayedSkinParts = this.DisplayedSkinParts, diff --git a/Obsidian/Utilities/ServerConfiguration.cs b/Obsidian/Utilities/ServerConfiguration.cs index 965dd5837..5c0e5dfc2 100644 --- a/Obsidian/Utilities/ServerConfiguration.cs +++ b/Obsidian/Utilities/ServerConfiguration.cs @@ -48,6 +48,12 @@ public sealed class ServerConfiguration : IServerConfiguration public bool AllowLan { get; set; } = true; // Enabled because it's super useful for debugging tbh + public byte ViewDistance + { + get => viewDistance; + set => viewDistance = value >= MinimumViewDistance ? value : MinimumViewDistance; + } + public int PregenerateChunkRange { get; set; } = 15; // by default, pregenerate range from -15 to 15 [JsonConverter(typeof(JsonStringEnumConverter))] @@ -64,6 +70,11 @@ public sealed class ServerConfiguration : IServerConfiguration public ServerListQuery ServerListQuery { get; set; } = ServerListQuery.Full; public int TimeTickSpeedMultiplier { get; set; } = 1; + + private byte viewDistance = 10; + + // Anything lower than 3 will cause weird artifacts on the client. + private const byte MinimumViewDistance = 3; } public sealed class ServerWorld