diff --git a/CakeBuild/CakeBuild.csproj b/CakeBuild/CakeBuild.csproj index 8e2c970..67807c1 100644 --- a/CakeBuild/CakeBuild.csproj +++ b/CakeBuild/CakeBuild.csproj @@ -1,7 +1,7 @@ Exe - net7.0 + net8.0 $(MSBuildProjectDirectory) diff --git a/global.json b/global.json new file mode 100644 index 0000000..b5b37b6 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "8.0.0", + "rollForward": "latestMajor", + "allowPrerelease": false + } +} \ No newline at end of file diff --git a/resources/modinfo.json b/resources/modinfo.json index 1ee6ae4..3365f7c 100644 --- a/resources/modinfo.json +++ b/resources/modinfo.json @@ -7,7 +7,7 @@ "authors": [ "Grifthegnome" ], "contributors": [ "Professor Cupcake" ], "description": "Adds dynamic evolving trail and roads. Backup your world before using!", - "version": "1.2.1", + "version": "1.3.0", "dependencies": { "game": "*" } diff --git a/trailmodcupdate/src/Patches.cs b/trailmodcupdate/src/Patches.cs index b5c4bb8..a7ae5f2 100644 --- a/trailmodcupdate/src/Patches.cs +++ b/trailmodcupdate/src/Patches.cs @@ -1,12 +1,13 @@ using HarmonyLib; using System.Reflection; -using System.Diagnostics; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.GameContent; using Vintagestory.API.MathTools; using System; -using Vintagestory.API.Client; +using System.Linq; +using Vintagestory.API.Server; +using static Vintagestory.API.Server.EnumClientState; namespace TrailMod @@ -46,8 +47,16 @@ static void OnEntityCollideOverride(Block __instance, IWorldAccessor world, Enti if (entity is not EntityAgent) return; - //Only run trail logic within 100 blocks of a player. - if (entity.minHorRangeToClient > 100) + const int playerRangeCap = 100; + var validStates = new[] { Playing, Connected }; + + var onlinePlayersInRange = world.AllOnlinePlayers.Where(player => + player is IServerPlayer serverPlayer + && validStates.Contains(serverPlayer.ConnectionState) + && entity.Pos.InRangeOf(player.Entity.Pos, playerRangeCap * playerRangeCap)); + + //Only run trail logic within 100 blocks of any online player. + if (!onlinePlayersInRange.Any()) return; if ( entity is EntityPlayer ) diff --git a/trailmodcupdate/trailmodcupdate.csproj b/trailmodcupdate/trailmodcupdate.csproj index c9f352c..343566b 100644 --- a/trailmodcupdate/trailmodcupdate.csproj +++ b/trailmodcupdate/trailmodcupdate.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 false bin\$(Configuration)\Mods\mod