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); }