diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 5f81d53..d449e6a 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -4,6 +4,7 @@ using System.Data; using System.Linq; using System.Numerics; using AriasServerUtils; +using Microsoft.Win32.SafeHandles; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; @@ -53,9 +54,41 @@ public class RTPFactory BlockPos check = data.LastPosition.GetBlockPos(); check.Y = 1; - int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); + int Y = 255; + bool lastBlockAir = true; + bool lastLastBlockAir = true; + bool curBlockAir = true; + bool safe = false; + for (Y = 255; Y > 1; Y--) + { + // Manually scan downwards + var BA = ServerUtilities.API.World.BlockAccessor; + check.Y = Y; + var current = BA.GetBlock(check); - PPos.Y = height + 1; + if (current.BlockMaterial != EnumBlockMaterial.Air) + { + curBlockAir = false; + } + + + + lastLastBlockAir = lastBlockAir; + lastBlockAir = curBlockAir; + + + if (!curBlockAir && lastBlockAir && lastLastBlockAir) + { + // We found a safe spot to land + check.Y++; + safe = true; + break; + } + } + + if (!safe) return null; + + PPos.Y = check.Y; return PPos; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 9bd42e7..a385c42 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:54 AM MST", - "version": "1.0.6-dev.14", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:04 AM MST", + "version": "1.0.6-dev.15", "dependencies": { "game": "" }