public static bool WaypointExistsWithinRadius(this ICoreClientAPI api, BlockPos pos, int horizontalRadius, int verticalRadius, Vintagestory.API.Common.Func <Waypoint, bool> comparer = null) { var waypointMapLayer = api.ModLoader.GetModSystem <WorldMapManager>().WaypointMapLayer(); var waypoints = waypointMapLayer.ownWaypoints.Where(wp => wp.Position.AsBlockPos.InRangeCubic(pos, horizontalRadius, verticalRadius)).ToList(); if (!waypoints.Any()) { return(false); } return(comparer == null || waypoints.Any(p => comparer(p))); }
public static TBlockEntity GetNearestBlockEntity <TBlockEntity>(this IWorldAccessor world, BlockPos pos, float horRange, float vertRange, Vintagestory.API.Common.Func <TBlockEntity, bool> predicate) where TBlockEntity : BlockEntity { TBlockEntity blockEntity = null; var minPos = pos.AddCopy(-horRange, -vertRange, -horRange); var maxPos = pos.AddCopy(horRange, vertRange, horRange); world.BlockAccessor.WalkBlocks(minPos, maxPos, (_, blockPos) => { var entity = world.GetBlockAccessorPrefetch(false, false).GetBlockEntity(blockPos); if (entity == null) { return; } if (entity.GetType() == typeof(TBlockEntity) && predicate((TBlockEntity)entity)) { blockEntity = (TBlockEntity)entity; } }, true); return(blockEntity); }